From b85edc08d20144e92480300d91397cc261b79912 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 17 Aug 2021 09:44:30 +0300 Subject: [PATCH] Port Workspace::switchWindow() to VirtualDesktop If a window is on several virtual desktops, Workspace::switchWindow() will not work as expected because AbstractClient::desktop() returns the id of the last virtual desktop. Since the active window is most likely on the current virtual desktop, we can use that for filtering out irrelevant windows. --- src/useractions.cpp | 10 +++++----- src/workspace.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/useractions.cpp b/src/useractions.cpp index e084a1134e..6fe20c9ac8 100644 --- a/src/useractions.cpp +++ b/src/useractions.cpp @@ -1586,12 +1586,12 @@ void Workspace::switchWindow(Direction direction) if (!active_client) return; AbstractClient *c = active_client; - int desktopNumber = c->isOnAllDesktops() ? VirtualDesktopManager::self()->current() : c->desktop(); + VirtualDesktop *desktop = VirtualDesktopManager::self()->currentDesktop(); // Centre of the active window QPoint curPos(c->x() + c->width() / 2, c->y() + c->height() / 2); - if (!switchWindow(c, direction, curPos, desktopNumber)) { + if (!switchWindow(c, direction, curPos, desktop)) { auto opposite = [&] { switch(direction) { case DirectionNorth: @@ -1607,11 +1607,11 @@ void Workspace::switchWindow(Direction direction) } }; - switchWindow(c, direction, opposite(), desktopNumber); + switchWindow(c, direction, opposite(), desktop); } } -bool Workspace::switchWindow(AbstractClient *c, Direction direction, QPoint curPos, int d) +bool Workspace::switchWindow(AbstractClient *c, Direction direction, QPoint curPos, VirtualDesktop *desktop) { AbstractClient *switchTo = nullptr; int bestScore = 0; @@ -1623,7 +1623,7 @@ bool Workspace::switchWindow(AbstractClient *c, Direction direction, QPoint curP continue; } if (client->wantsTabFocus() && *i != c && - client->isOnDesktop(d) && !client->isMinimized() && (*i)->isOnCurrentActivity()) { + client->isOnDesktop(desktop) && !client->isMinimized() && (*i)->isOnCurrentActivity()) { // Centre of the other window const QPoint other(client->x() + client->width() / 2, client->y() + client->height() / 2); diff --git a/src/workspace.h b/src/workspace.h index adb6eaf6f0..b3caa10479 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -531,7 +531,7 @@ private: template void initShortcut(const QString &actionName, const QString &description, const QKeySequence &shortcut, T *receiver, Slot slot, const QVariant &data = QVariant()); void setupWindowShortcut(AbstractClient* c); - bool switchWindow(AbstractClient *c, Direction direction, QPoint curPos, int desktop); + bool switchWindow(AbstractClient *c, Direction direction, QPoint curPos, VirtualDesktop *desktop); void propagateClients(bool propagate_new_clients); // Called only from updateStackingOrder QList constrainedStackingOrder();