diff --git a/autotests/integration/xdgshellclient_test.cpp b/autotests/integration/xdgshellclient_test.cpp index 480f7f23bd..322491ce3c 100644 --- a/autotests/integration/xdgshellclient_test.cpp +++ b/autotests/integration/xdgshellclient_test.cpp @@ -908,7 +908,10 @@ void TestXdgShellClient::testSendClientWithTransientToDesktop() { // this test verifies that when sending a client to a desktop all transients are also send to that desktop - VirtualDesktopManager::self()->setCount(2); + VirtualDesktopManager *vds = VirtualDesktopManager::self(); + vds->setCount(2); + const QVector desktops = vds->desktops(); + QScopedPointer surface{Test::createSurface()}; QScopedPointer shellSurface(Test::createXdgToplevelSurface(surface.data())); @@ -926,14 +929,16 @@ void TestXdgShellClient::testSendClientWithTransientToDesktop() QCOMPARE(transient->transientFor(), c); QVERIFY(c->transients().contains(transient)); - QCOMPARE(c->desktop(), 1); + // initially, the parent and the transient are on the first virtual desktop + QCOMPARE(c->desktops(), QVector{desktops[0]}); QVERIFY(!c->isOnAllDesktops()); - QCOMPARE(transient->desktop(), 1); + QCOMPARE(transient->desktops(), QVector{desktops[0]}); QVERIFY(!transient->isOnAllDesktops()); - workspace()->slotWindowToDesktop(2); - QCOMPARE(c->desktop(), 1); - QCOMPARE(transient->desktop(), 2); + // send the transient to the second virtual desktop + workspace()->slotWindowToDesktop(desktops[1]); + QCOMPARE(c->desktops(), QVector{desktops[0]}); + QCOMPARE(transient->desktops(), QVector{desktops[1]}); // activate c workspace()->activateClient(c); @@ -941,13 +946,13 @@ void TestXdgShellClient::testSendClientWithTransientToDesktop() QVERIFY(c->isActive()); // and send it to the desktop it's already on - QCOMPARE(c->desktop(), 1); - QCOMPARE(transient->desktop(), 2); - workspace()->slotWindowToDesktop(1); + QCOMPARE(c->desktops(), QVector{desktops[0]}); + QCOMPARE(transient->desktops(), QVector{desktops[1]}); + workspace()->slotWindowToDesktop(desktops[0]); // which should move the transient back to the desktop - QCOMPARE(c->desktop(), 1); - QCOMPARE(transient->desktop(), 1); + QCOMPARE(c->desktops(), QVector{desktops[0]}); + QCOMPARE(transient->desktops(), QVector{desktops[0]}); } void TestXdgShellClient::testMinimizeWindowWithTransients() diff --git a/src/useractions.cpp b/src/useractions.cpp index 6fe20c9ac8..f042a7c085 100644 --- a/src/useractions.cpp +++ b/src/useractions.cpp @@ -1068,8 +1068,15 @@ void Workspace::initShortcuts() DEF2("Window On All Desktops", I18N_NOOP("Keep Window on All Desktops"), 0, slotWindowOnAllDesktops); - for (int i = 1; i < 21; ++i) { - DEF5(I18N_NOOP("Window to Desktop %1"), 0, std::bind(&Workspace::slotWindowToDesktop, this, i), i); + VirtualDesktopManager *vds = VirtualDesktopManager::self(); + for (uint i = 0; i < vds->maximum(); ++i) { + auto handler = [this, i]() { + const QVector desktops = VirtualDesktopManager::self()->desktops(); + if (i < uint(desktops.count())) { + slotWindowToDesktop(desktops[i]); + } + }; + DEF5(I18N_NOOP("Window to Desktop %1"), 0, handler, i + 1); } DEF(I18N_NOOP("Window to Next Desktop"), 0, slotWindowToNextDesktop); DEF(I18N_NOOP("Window to Previous Desktop"), 0, slotWindowToPreviousDesktop); @@ -1105,7 +1112,7 @@ void Workspace::initShortcuts() #ifdef KWIN_BUILD_TABBOX TabBox::TabBox::self()->initShortcuts(); #endif - VirtualDesktopManager::self()->initShortcuts(); + vds->initShortcuts(); m_userActionsMenu->discard(); // so that it's recreated next time } @@ -1283,14 +1290,10 @@ static uint senderValue(QObject *sender) #define USABLE_ACTIVE_CLIENT (active_client && !(active_client->isDesktop() || active_client->isDock())) -void Workspace::slotWindowToDesktop(uint i) +void Workspace::slotWindowToDesktop(VirtualDesktop *desktop) { if (USABLE_ACTIVE_CLIENT) { - if (i < 1) - return; - - if (i >= 1 && i <= VirtualDesktopManager::self()->count()) - sendClientToDesktop(active_client, i, true); + sendClientToDesktop(active_client, desktop->x11DesktopNumber(), true); } } @@ -1528,14 +1531,14 @@ void activeClientToDesktop() { VirtualDesktopManager *vds = VirtualDesktopManager::self(); Workspace *ws = Workspace::self(); - const int current = vds->current(); + VirtualDesktop *current = vds->currentDesktop(); Direction functor; - const int d = functor(current, options->isRollOverDesktops()); - if (d == current) { + VirtualDesktop *newCurrent = functor(current, options->isRollOverDesktops()); + if (newCurrent == current) { return; } ws->setMoveResizeClient(ws->activeClient()); - vds->setCurrent(d); + vds->setCurrent(newCurrent); ws->setMoveResizeClient(nullptr); } diff --git a/src/workspace.h b/src/workspace.h index b3caa10479..b5b287c668 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -413,7 +413,7 @@ public Q_SLOTS: void performWindowOperation(KWin::AbstractClient* c, Options::WindowOperation op); // Keybindings //void slotSwitchToWindow( int ); - void slotWindowToDesktop(uint i); + void slotWindowToDesktop(VirtualDesktop *desktop); //void slotWindowToListPosition( int ); void slotSwitchToScreen();