From 8e20932d3f13a4c085c80cf316df3aa910cdff0e Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 16 Sep 2024 21:47:17 +0000 Subject: [PATCH] workspace: Update focus when a window is moved away from the current desktop If a focussed window is to a new virtual desktop we need to update focus. It does not make sense for focus to remain on a now-invisible window. This patch re-uses the same path as when virtual desktop is changed. BUG: 481574 (cherry picked from commit b96e6cf0b3eb4250b7a9ed6f5c1c7fa080566dd0) Co-authored-by: David Edmundson --- autotests/integration/kwinbindings_test.cpp | 7 +++++++ src/workspace.cpp | 11 +++++++++-- src/workspace.h | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/autotests/integration/kwinbindings_test.cpp b/autotests/integration/kwinbindings_test.cpp index e674e96f1b..9e59739084 100644 --- a/autotests/integration/kwinbindings_test.cpp +++ b/autotests/integration/kwinbindings_test.cpp @@ -238,10 +238,17 @@ void KWinBindingsTest::testWindowToDesktop() invokeShortcut(desktop); QVERIFY(desktopsChangedSpy.wait()); QCOMPARE(window->desktops(), QList{desktops.at(desktop - 1)}); + + // window to Desktop does not change the current desktop, change it manually + VirtualDesktopManager::self()->setCurrent(desktops.at(desktop - 1)); + // back to desktop 1 invokeShortcut(1); QVERIFY(desktopsChangedSpy.wait()); QCOMPARE(window->desktops(), QList{desktops.at(0)}); + + VirtualDesktopManager::self()->setCurrent(desktops.at(0)); + // invoke with one desktop too many invokeShortcut(desktop + 1); // that should fail diff --git a/src/workspace.cpp b/src/workspace.cpp index 24cecc7dfe..ceb71a4466 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -932,7 +932,7 @@ void Workspace::slotCurrentDesktopChanged(VirtualDesktop *oldDesktop, VirtualDes // Restore the focus on this desktop --block_focus; - activateWindowOnNewDesktop(newDesktop); + activateWindowOnDesktop(newDesktop); Q_EMIT currentDesktopChanged(oldDesktop, m_moveResizeWindow); } @@ -985,7 +985,7 @@ void Workspace::updateWindowVisibilityOnDesktopChange(VirtualDesktop *newDesktop } } -void Workspace::activateWindowOnNewDesktop(VirtualDesktop *desktop) +void Workspace::activateWindowOnDesktop(VirtualDesktop *desktop) { Window *window = nullptr; if (options->focusPolicyIsReasonable()) { @@ -1476,6 +1476,7 @@ void Workspace::sendWindowToDesktops(Window *window, const QList oldDesktops = window->desktops(); const bool wasOnCurrent = window->isOnCurrentDesktop(); + const bool wasActive = window->isActive(); window->setDesktops(desktops); if (window->desktops() != desktops) { // No change or desktop forced return; @@ -1489,7 +1490,13 @@ void Workspace::sendWindowToDesktops(Window *window, const QListcurrentDesktop()); + } } window->checkWorkspacePosition(QRect(), oldDesktops.isEmpty() ? nullptr : oldDesktops.last()); diff --git a/src/workspace.h b/src/workspace.h index 11edb183fc..51f03514d5 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -637,7 +637,7 @@ private: void closeActivePopup(); void updateWindowVisibilityOnDesktopChange(VirtualDesktop *newDesktop); - void activateWindowOnNewDesktop(VirtualDesktop *desktop); + void activateWindowOnDesktop(VirtualDesktop *desktop); Window *findWindowToActivateOnDesktop(VirtualDesktop *desktop); void removeWindow(Window *window); QString getPlacementTrackerHash();