diff --git a/abstract_client.h b/abstract_client.h --- a/abstract_client.h +++ b/abstract_client.h @@ -428,7 +428,8 @@ virtual bool performMouseCommand(Options::MouseCommand, const QPoint &globalPos); void setOnAllDesktops(bool set); void setDesktop(int); - Q_INVOKABLE virtual void unSetDesktop(int desktop); + Q_INVOKABLE virtual void enterDesktop(VirtualDesktop *desktop); + Q_INVOKABLE virtual void leaveDesktop(VirtualDesktop *desktop); int desktop() const override { return m_desktops.isEmpty() ? (int)NET::OnAllDesktops : m_desktops.last()->x11DesktopNumber(); } diff --git a/abstract_client.cpp b/abstract_client.cpp --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -501,7 +501,7 @@ { //on x11 we can have only one desktop at a time if (kwinApp()->operationMode() == Application::OperationModeX11 && desktops.size() > 1) { - desktops = QList({desktops.first()}); + desktops = QList({desktops.last()}); } if (desktops == m_desktops) { @@ -571,23 +571,24 @@ Q_UNUSED(was_desk) } -void AbstractClient::unSetDesktop(int desktop) +void AbstractClient::enterDesktop(VirtualDesktop *virtualDesktop) { - // Case in which we are on all desktops and gets asked to unset - if (desktop == NET::OnAllDesktops) { - if (m_desktops.isEmpty()) { - setOnAllDesktops(false); - } + if (m_desktops.contains(virtualDesktop)) { return; } + auto desktops = m_desktops; + desktops.append(virtualDesktop); + if (desktops.count() == VirtualDesktopManager::self()->count()) { + desktops.clear(); + } + setDesktops(desktops); +} - // Out of range - if (desktop < 1 || desktop > VirtualDesktopManager::self()->count()) { +void AbstractClient::leaveDesktop(VirtualDesktop *virtualDesktop) +{ + if (!m_desktops.contains(virtualDesktop)) { return; } - - VirtualDesktop *virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desktop); - Q_ASSERT(virtualDesktop); auto desktops = m_desktops; desktops.removeOne(virtualDesktop); setDesktops(desktops); @@ -999,21 +1000,21 @@ [this] (const QString &desktopId) { VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId.toUtf8()); if (vd) { - workspace()->sendClientToDesktop(this, vd->x11DesktopNumber(), false); + enterDesktop(vd); } } ); connect(w, &PlasmaWindowInterface::enterNewPlasmaVirtualDesktopRequested, this, [this] () { VirtualDesktopManager::self()->setCount(VirtualDesktopManager::self()->count() + 1); - workspace()->sendClientToDesktop(this, VirtualDesktopManager::self()->count(), false); + enterDesktop(VirtualDesktopManager::self()->desktops().last()); } ); connect(w, &PlasmaWindowInterface::leavePlasmaVirtualDesktopRequested, this, [this] (const QString &desktopId) { VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId.toUtf8()); if (vd) { - unSetDesktop(vd->x11DesktopNumber()); + leaveDesktop(vd); } } ); diff --git a/autotests/integration/virtual_desktop_test.cpp b/autotests/integration/virtual_desktop_test.cpp --- a/autotests/integration/virtual_desktop_test.cpp +++ b/autotests/integration/virtual_desktop_test.cpp @@ -210,35 +210,35 @@ QCOMPARE(VirtualDesktopManager::self()->currentDesktop(), client->desktops().first()); //Set the window on desktop 2 as well - client->setDesktop(2u); + client->enterDesktop(VirtualDesktopManager::self()->desktops()[2]); QCOMPARE(client->desktops().count(), 2u); QCOMPARE(VirtualDesktopManager::self()->desktops()[2], client->desktops()[0]); QCOMPARE(VirtualDesktopManager::self()->desktops()[1], client->desktops()[1]); QVERIFY(client->isOnDesktop(2)); QVERIFY(client->isOnDesktop(3)); //leave desktop 3 - client->unSetDesktop(3); + client->leaveDesktop(VirtualDesktopManager::self()->desktops()[2]); QCOMPARE(client->desktops().count(), 1u); //leave desktop 2 - client->unSetDesktop(2); + client->leaveDesktop(VirtualDesktopManager::self()->desktops()[1]); QCOMPARE(client->desktops().count(), 0u); //we should be on all desktops now QVERIFY(client->isOnAllDesktops()); //put on desktop 1 - client->setDesktop(1); + client->enterDesktop(VirtualDesktopManager::self()->desktops()[0]); QVERIFY(client->isOnDesktop(1)); QVERIFY(!client->isOnDesktop(2)); QVERIFY(!client->isOnDesktop(3)); QCOMPARE(client->desktops().count(), 1u); //put on desktop 2 - client->setDesktop(2); + client->enterDesktop(VirtualDesktopManager::self()->desktops()[1]); QVERIFY(client->isOnDesktop(1)); QVERIFY(client->isOnDesktop(2)); QVERIFY(!client->isOnDesktop(3)); QCOMPARE(client->desktops().count(), 2u); //put on desktop 3 - client->setDesktop(3); + client->enterDesktop(VirtualDesktopManager::self()->desktops()[2]); QVERIFY(client->isOnDesktop(1)); QVERIFY(client->isOnDesktop(2)); QVERIFY(client->isOnDesktop(3)); @@ -282,7 +282,7 @@ QCOMPARE(VirtualDesktopManager::self()->currentDesktop(), client->desktops().first()); //Set the window on desktop 2 as well - client->setDesktop(2u); + client->enterDesktop(VirtualDesktopManager::self()->desktops()[1]); QCOMPARE(client->desktops().count(), 2u); QCOMPARE(VirtualDesktopManager::self()->desktops()[2], client->desktops()[0]); QCOMPARE(VirtualDesktopManager::self()->desktops()[1], client->desktops()[1]); @@ -298,8 +298,8 @@ //Again 3 desktops VirtualDesktopManager::self()->setCount(3); //move window to be only on desktop 3 - client->setDesktop(3); - client->unSetDesktop(2); + client->enterDesktop(VirtualDesktopManager::self()->desktops()[2]); + client->leaveDesktop(VirtualDesktopManager::self()->desktops()[1]); QCOMPARE(client->desktops().count(), 1u); //window is only on desktop 3 QCOMPARE(VirtualDesktopManager::self()->desktops()[2], client->desktops()[0]); diff --git a/autotests/mock_effectshandler.h b/autotests/mock_effectshandler.h --- a/autotests/mock_effectshandler.h +++ b/autotests/mock_effectshandler.h @@ -263,6 +263,15 @@ } void hideOnScreenMessage(OnScreenMessageHideFlags flags = OnScreenMessageHideFlags()) override { Q_UNUSED(flags)} + void addWindowToDesktop(KWin::EffectWindow *w, int desktop) { + Q_UNUSED(w) + Q_UNUSED(desktop) + } + void removeWindowFromDesktop(KWin::EffectWindow *w, int desktop) { + Q_UNUSED(w) + Q_UNUSED(desktop) + } + KSharedConfigPtr config() const override; KSharedConfigPtr inputConfig() const override; diff --git a/effects.h b/effects.h --- a/effects.h +++ b/effects.h @@ -260,6 +260,9 @@ return registered_atoms.contains(atom); } + void addWindowToDesktop(EffectWindow *w, int desktop) override; + void removeWindowFromDesktop(EffectWindow *w, int desktop) override; + public Q_SLOTS: void slotCurrentTabAboutToChange(EffectWindow* from, EffectWindow* to); void slotTabAdded(EffectWindow* from, EffectWindow* to); diff --git a/effects.cpp b/effects.cpp --- a/effects.cpp +++ b/effects.cpp @@ -916,6 +916,20 @@ } } +void EffectsHandlerImpl::addWindowToDesktop(EffectWindow *w, int desktop) +{ + AbstractClient* cl = dynamic_cast< AbstractClient* >(static_cast(w)->window()); + VirtualDesktop *d = VirtualDesktopManager::self()->desktopForX11Id(desktop); + cl->enterDesktop(d); +} + +void EffectsHandlerImpl::removeWindowFromDesktop(EffectWindow *w, int desktop) +{ + AbstractClient* cl = dynamic_cast< AbstractClient* >(static_cast(w)->window()); + VirtualDesktop *d = VirtualDesktopManager::self()->desktopForX11Id(desktop); + cl->leaveDesktop(d); +} + void EffectsHandlerImpl::windowToScreen(EffectWindow* w, int screen) { AbstractClient* cl = dynamic_cast< AbstractClient* >(static_cast(w)->window()); diff --git a/effects/desktopgrid/desktopgrid.cpp b/effects/desktopgrid/desktopgrid.cpp --- a/effects/desktopgrid/desktopgrid.cpp +++ b/effects/desktopgrid/desktopgrid.cpp @@ -525,7 +525,7 @@ effects->defineCursor(Qt::ClosedHandCursor); } if (d != highlightedDesktop) { - effects->windowToDesktop(windowMove, d); // Not true all desktop move + effects->addWindowToDesktop(windowMove, d); // Not true all desktop move if (highlightedDesktop != sourceDesktop || !wasWindowCopy) { effects->removeWindowFromDesktop(windowMove, highlightedDesktop); } @@ -561,7 +561,7 @@ if (desks[i] == desks[i+1]) continue; foreach (EffectWindow *w, stack[i]) { - effects->windowToDesktop(w, desks[i+1]); + effects->addWindowToDesktop(w, desks[i+1]); effects->removeWindowFromDesktop(w, desks[i]); if (isUsingPresentWindows()) { diff --git a/libkwineffects/kwineffects.h b/libkwineffects/kwineffects.h --- a/libkwineffects/kwineffects.h +++ b/libkwineffects/kwineffects.h @@ -944,10 +944,17 @@ virtual KWin::EffectWindow* activeWindow() const = 0 ; Q_SCRIPTABLE virtual void moveWindow(KWin::EffectWindow* w, const QPoint& pos, bool snap = false, double snapAdjust = 1.0) = 0; Q_SCRIPTABLE virtual void windowToDesktop(KWin::EffectWindow* w, int desktop) = 0; + /** * Removes a window from a desktop on wayland, no-op on X11 */ - Q_SCRIPTABLE void removeWindowFromDesktop(KWin::EffectWindow* w, int desktop); + Q_SCRIPTABLE virtual void removeWindowFromDesktop(KWin::EffectWindow* w, int desktop) = 0; + /** + * Adds a window to a desktop on wayland, moves the window on X11 + */ + Q_SCRIPTABLE virtual void addWindowToDesktop(KWin::EffectWindow* w, int desktop) = 0; + + Q_SCRIPTABLE virtual void windowToScreen(KWin::EffectWindow* w, int screen) = 0; virtual void setShowingDesktop(bool showing) = 0; diff --git a/libkwineffects/kwineffects.cpp b/libkwineffects/kwineffects.cpp --- a/libkwineffects/kwineffects.cpp +++ b/libkwineffects/kwineffects.cpp @@ -762,13 +762,6 @@ return compositing_type & OpenGLCompositing; } -void EffectsHandler::removeWindowFromDesktop(KWin::EffectWindow* w, int desktop) -{ - if (w->parent() && !w->isDesktop() && !w->isDock()) { - QMetaObject::invokeMethod(w->parent(), "unSetDesktop", Q_ARG(int, desktop)); - } -} - EffectsHandler* effects = nullptr; diff --git a/useractions.cpp b/useractions.cpp --- a/useractions.cpp +++ b/useractions.cpp @@ -912,9 +912,9 @@ VirtualDesktop *virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desk); if (m_client.data()->desktops().contains(virtualDesktop)) { - m_client.data()->unSetDesktop(desk); + m_client.data()->leaveDesktop(virtualDesktop); } else { - ws->sendClientToDesktop(m_client.data(), desk, false); + m_client.data()->enterDesktop(virtualDesktop); } }