From e0c941109c683857c1852c80e417a29fabd64b57 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sat, 28 Aug 2021 17:51:57 +0300 Subject: [PATCH] Allow setting current AbstractOutput --- src/abstract_client.cpp | 6 +++--- src/activation.cpp | 5 +++-- src/layershellv1integration.cpp | 2 +- src/screens.cpp | 18 ++++++++++++++++++ src/screens.h | 2 ++ src/tabbox/tabbox.cpp | 6 +++--- src/toplevel.cpp | 4 ++-- src/toplevel.h | 2 +- src/workspace.cpp | 6 +++--- src/xdgshellclient.cpp | 4 ++-- 10 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/abstract_client.cpp b/src/abstract_client.cpp index 8e9d5f5d41..7e404d6f11 100644 --- a/src/abstract_client.cpp +++ b/src/abstract_client.cpp @@ -85,7 +85,7 @@ AbstractClient::AbstractClient() Q_UNUSED(c) if (isOnScreenDisplay() && !frameGeometry().isEmpty() && old.size() != frameGeometry().size() && isPlaceable()) { GeometryUpdatesBlocker blocker(this); - placeIn(workspace()->clientArea(PlacementArea, this, Screens::self()->current())); + placeIn(workspace()->clientArea(PlacementArea, this, Screens::self()->currentOutput())); } } ); @@ -1222,7 +1222,7 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y // Make sure the titlebar isn't behind a restricted area. We don't need to restrict // the other directions. If not visible enough, move the window to the closest valid // point. We bruteforce this by slowly moving the window back to its previous position - QRegion availableArea(workspace()->clientArea(FullArea, this, screens()->current())); + QRegion availableArea(workspace()->clientArea(FullArea, this, screens()->currentOutput())); availableArea -= workspace()->restrictedMoveArea(VirtualDesktopManager::self()->currentDesktop()); bool transposed = false; int requiredPixels; @@ -1350,7 +1350,7 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y if (!isUnrestrictedInteractiveMoveResize()) { const QRegion strut = workspace()->restrictedMoveArea(VirtualDesktopManager::self()->currentDesktop()); - QRegion availableArea(workspace()->clientArea(FullArea, this, screens()->current())); + QRegion availableArea(workspace()->clientArea(FullArea, this, screens()->currentOutput())); availableArea -= strut; // Strut areas bool transposed = false; int requiredPixels; diff --git a/src/activation.cpp b/src/activation.cpp index cc4bc2ef79..f1d694defd 100644 --- a/src/activation.cpp +++ b/src/activation.cpp @@ -391,8 +391,9 @@ bool Workspace::takeActivity(AbstractClient* c, ActivityFlags flags) if (flags & ActivityRaise) workspace()->raiseClient(c); - if (!c->isOnActiveScreen()) - screens()->setCurrent(c->screen()); + if (!c->isOnActiveOutput()) { + screens()->setCurrent(c->output()); + } return ret; } diff --git a/src/layershellv1integration.cpp b/src/layershellv1integration.cpp index d3461f0aec..0d03c257df 100644 --- a/src/layershellv1integration.cpp +++ b/src/layershellv1integration.cpp @@ -41,7 +41,7 @@ void LayerShellV1Integration::createClient(LayerSurfaceV1Interface *shellSurface { AbstractOutput *output = waylandServer()->findOutput(shellSurface->output()); if (!output) { - output = kwinApp()->platform()->findOutput(screens()->current()); + output = screens()->currentOutput(); } if (!output) { qCWarning(KWIN_CORE) << "Could not find any suitable output for a layer surface"; diff --git a/src/screens.cpp b/src/screens.cpp index a7b9dbc075..8c89e03f49 100644 --- a/src/screens.cpp +++ b/src/screens.cpp @@ -185,6 +185,15 @@ void Screens::setCurrent(int current) Q_EMIT currentChanged(); } +void Screens::setCurrent(AbstractOutput *output) +{ +#ifdef KWIN_UNIT_TEST + Q_UNUSED(output) +#else + setCurrent(kwinApp()->platform()->enabledOutputs().indexOf(output)); +#endif +} + void Screens::setCurrent(const QPoint &pos) { setCurrent(number(pos)); @@ -220,6 +229,15 @@ int Screens::current() const return m_current; } +AbstractOutput *Screens::currentOutput() const +{ +#ifdef KWIN_UNIT_TEST + return nullptr; +#else + return kwinApp()->platform()->findOutput(current()); +#endif +} + int Screens::intersecting(const QRect &r) const { int cnt = 0; diff --git a/src/screens.h b/src/screens.h index df03288bf5..1c59487723 100644 --- a/src/screens.h +++ b/src/screens.h @@ -42,12 +42,14 @@ public: void setConfig(KSharedConfig::Ptr config); int count() const; int current() const; + AbstractOutput *currentOutput() const; void setCurrent(int current); /** * Called e.g. when a user clicks on a window, set current screen to be the screen * where the click occurred */ void setCurrent(const QPoint &pos); + void setCurrent(AbstractOutput *output); /** * Check whether a client moved completely out of what's considered the current screen, * if yes, set a new active screen. diff --git a/src/tabbox/tabbox.cpp b/src/tabbox/tabbox.cpp index fc506069a9..b54df171dd 100644 --- a/src/tabbox/tabbox.cpp +++ b/src/tabbox/tabbox.cpp @@ -235,9 +235,9 @@ bool TabBoxHandlerImpl::checkMultiScreen(TabBoxClient* client) const case TabBoxConfig::IgnoreMultiScreen: return true; case TabBoxConfig::ExcludeCurrentScreenClients: - return current->screen() != screens()->current(); + return current->output() != screens()->currentOutput(); default: // TabBoxConfig::OnlyCurrentScreenClients - return current->screen() == screens()->current(); + return current->output() == screens()->currentOutput(); } } @@ -322,7 +322,7 @@ QWeakPointer TabBoxHandlerImpl::desktopClient() const { Q_FOREACH (Toplevel *toplevel, Workspace::self()->stackingOrder()) { auto client = qobject_cast(toplevel); - if (client && client->isDesktop() && client->isOnCurrentDesktop() && client->screen() == screens()->current()) { + if (client && client->isDesktop() && client->isOnCurrentDesktop() && client->output() == screens()->currentOutput()) { return client->tabBoxClient(); } } diff --git a/src/toplevel.cpp b/src/toplevel.cpp index 16a88aeca8..c81c1afadc 100644 --- a/src/toplevel.cpp +++ b/src/toplevel.cpp @@ -424,9 +424,9 @@ bool Toplevel::isOnScreen(int screen) const return screens()->geometry(screen).intersects(frameGeometry()); } -bool Toplevel::isOnActiveScreen() const +bool Toplevel::isOnActiveOutput() const { - return isOnScreen(screens()->current()); + return isOnOutput(screens()->currentOutput()); } bool Toplevel::isOnOutput(AbstractOutput *output) const diff --git a/src/toplevel.h b/src/toplevel.h index bf01e7bc56..60ee92abf9 100644 --- a/src/toplevel.h +++ b/src/toplevel.h @@ -343,7 +343,7 @@ public: int height() const; bool isOnScreen(int screen) const; // true if it's at least partially there bool isOnOutput(AbstractOutput *output) const; - bool isOnActiveScreen() const; + bool isOnActiveOutput() const; int screen() const; // the screen where the center is AbstractOutput *output() const; /** diff --git a/src/workspace.cpp b/src/workspace.cpp index a703456f29..5b79621ee4 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -786,7 +786,7 @@ void Workspace::addShellClient(AbstractClient *client) client->updateLayer(); if (client->isPlaceable()) { - const QRect area = clientArea(PlacementArea, client, Screens::self()->current()); + const QRect area = clientArea(PlacementArea, client, Screens::self()->currentOutput()); bool placementDone = false; if (client->isRequestedFullScreen()) { placementDone = true; @@ -1099,7 +1099,7 @@ AbstractClient *Workspace::findClientToActivateOnDesktop(VirtualDesktop *desktop } if (!(client->isShown(false) && client->isOnDesktop(desktop) && - client->isOnCurrentActivity() && client->isOnActiveScreen())) + client->isOnCurrentActivity() && client->isOnActiveOutput())) continue; if (client->frameGeometry().contains(Cursors::self()->mouse()->pos())) { @@ -1926,7 +1926,7 @@ void Workspace::addInternalClient(InternalClient *client) client->updateLayer(); if (client->isPlaceable()) { - const QRect area = clientArea(PlacementArea, client, screens()->current()); + const QRect area = clientArea(PlacementArea, client, screens()->currentOutput()); client->placeIn(area); } diff --git a/src/xdgshellclient.cpp b/src/xdgshellclient.cpp index a1ae060bc8..ab9cf4ecc5 100644 --- a/src/xdgshellclient.cpp +++ b/src/xdgshellclient.cpp @@ -1235,7 +1235,7 @@ void XdgToplevelClient::initialize() needsPlacement = false; } if (needsPlacement) { - const QRect area = workspace()->clientArea(PlacementArea, this, Screens::self()->current()); + const QRect area = workspace()->clientArea(PlacementArea, this, Screens::self()->currentOutput()); placeIn(area); } @@ -2058,7 +2058,7 @@ void XdgPopupClient::initialize() updateReactive(); - const QRect area = workspace()->clientArea(PlacementArea, this, Screens::self()->current()); + const QRect area = workspace()->clientArea(PlacementArea, this, Screens::self()->currentOutput()); placeIn(area); scheduleConfigure(); }