diff --git a/autotests/client/test_plasma_virtual_desktop.cpp b/autotests/client/test_plasma_virtual_desktop.cpp --- a/autotests/client/test_plasma_virtual_desktop.cpp +++ b/autotests/client/test_plasma_virtual_desktop.cpp @@ -466,6 +466,8 @@ virtualDesktopLeftSpy.wait(); QCOMPARE(virtualDesktopLeftSpy.count(), 2); + QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0); + QVERIFY(m_window->isOnAllDesktops()); QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0); QVERIFY(m_window->isOnAllDesktops()); @@ -476,22 +478,6 @@ QCOMPARE(m_window->plasmaVirtualDesktops().length(), 1); QCOMPARE(m_windowInterface->plasmaVirtualDesktops().first(), QStringLiteral("0-1")); QVERIFY(!m_window->isOnAllDesktops()); - - //try setting on virtual desktops again but by setting every desktop by hand - m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("0-3")); - virtualDesktopEnteredSpy.wait(); - - virtualDesktopEnteredSpy.clear(); - virtualDesktopLeftSpy.clear(); - - m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("0-2")); - virtualDesktopLeftSpy.wait(); - QCOMPARE(virtualDesktopLeftSpy.count(), 2); - //note that virtualDesktopEntered should *not* have been emitted for 0-2 - QCOMPARE(virtualDesktopEnteredSpy.count(), 0); - - QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0); - QVERIFY(m_window->isOnAllDesktops()); } void TestVirtualDesktop::testCreateRequested() diff --git a/autotests/client/test_plasma_window_model.cpp b/autotests/client/test_plasma_window_model.cpp --- a/autotests/client/test_plasma_window_model.cpp +++ b/autotests/client/test_plasma_window_model.cpp @@ -28,6 +28,7 @@ // server #include "../../src/server/display.h" #include "../../src/server/plasmawindowmanagement_interface.h" +#include "../../src/server/plasmavirtualdesktop_interface.h" #include @@ -67,7 +68,6 @@ void testIsMinimized(); void testIsKeepAbove(); void testIsKeepBelow(); - void testIsOnAllDesktops(); void testIsDemandingAttention(); void testSkipTaskbar(); void testSkipSwitcher(); @@ -81,7 +81,7 @@ void testTitle(); void testAppId(); void testPid(); - void testVirtualDesktop(); + void testVirtualDesktops(); // TODO icon: can we ensure a theme is installed on CI? void testRequests(); // TODO: minimized geometry @@ -96,6 +96,7 @@ Display *m_display = nullptr; PlasmaWindowManagementInterface *m_pwInterface = nullptr; PlasmaWindowManagement *m_pw = nullptr; + KWayland::Server::PlasmaVirtualDesktopManagementInterface *m_plasmaVirtualDesktopManagementInterface = nullptr; ConnectionThread *m_connection = nullptr; QThread *m_thread = nullptr; EventQueue *m_queue = nullptr; @@ -113,6 +114,12 @@ m_display->createShm(); m_pwInterface = m_display->createPlasmaWindowManagement(); m_pwInterface->create(); + m_plasmaVirtualDesktopManagementInterface = m_display->createPlasmaVirtualDesktopManagement(m_display); + m_plasmaVirtualDesktopManagementInterface->create(); + QVERIFY(m_plasmaVirtualDesktopManagementInterface->isValid()); + m_plasmaVirtualDesktopManagementInterface->createDesktop("desktop1"); + m_plasmaVirtualDesktopManagementInterface->createDesktop("desktop2"); + m_pwInterface->setPlasmaVirtualDesktopManagementInterface(m_plasmaVirtualDesktopManagementInterface); // setup connection m_connection = new KWayland::Client::ConnectionThread; @@ -153,6 +160,7 @@ variable = nullptr; \ } CLEANUP(m_pw) + CLEANUP(m_plasmaVirtualDesktopManagementInterface) CLEANUP(m_queue) if (m_connection) { m_connection->deleteLater(); @@ -401,11 +409,6 @@ QVERIFY(testBooleanData(PlasmaWindowModel::IsKeepBelow, &PlasmaWindowInterface::setKeepBelow)); } -void PlasmaWindowModelTest::testIsOnAllDesktops() -{ - QVERIFY(testBooleanData(PlasmaWindowModel::IsOnAllDesktops, &PlasmaWindowInterface::setOnAllDesktops)); -} - void PlasmaWindowModelTest::testIsDemandingAttention() { QVERIFY(testBooleanData(PlasmaWindowModel::IsDemandingAttention, &PlasmaWindowInterface::setDemandsAttention)); @@ -549,7 +552,7 @@ QCOMPARE(model->data(index, PlasmaWindowModel::Pid).toInt(), 1337); } -void PlasmaWindowModelTest::testVirtualDesktop() +void PlasmaWindowModelTest::testVirtualDesktops() { auto model = m_pw->createWindowModel(); QVERIFY(model); @@ -564,17 +567,36 @@ QVERIFY(dataChangedSpy.isValid()); const QModelIndex index = model->index(0); - QCOMPARE(model->data(index, PlasmaWindowModel::VirtualDesktop).toInt(), 0); + QCOMPARE(model->data(index, PlasmaWindowModel::VirtualDesktops).toStringList(), QStringList()); + + w->addPlasmaVirtualDesktop("desktop1"); + QVERIFY(dataChangedSpy.wait()); + QCOMPARE(dataChangedSpy.count(), 2); + QCOMPARE(dataChangedSpy.first().first().toModelIndex(), index); + QCOMPARE(dataChangedSpy.last().first().toModelIndex(), index); + + QCOMPARE(dataChangedSpy.first().last().value>(), QVector{int(PlasmaWindowModel::VirtualDesktops)}); + QCOMPARE(dataChangedSpy.last().last().value>(), QVector{int(PlasmaWindowModel::IsOnAllDesktops)}); + + QCOMPARE(model->data(index, PlasmaWindowModel::VirtualDesktops).toStringList(), QStringList({"desktop1"})); + QCOMPARE(model->data(index, PlasmaWindowModel::IsOnAllDesktops).toBool(), false); - w->setVirtualDesktop(1); + dataChangedSpy.clear(); + w->addPlasmaVirtualDesktop("desktop2"); QVERIFY(dataChangedSpy.wait()); QCOMPARE(dataChangedSpy.count(), 1); QCOMPARE(dataChangedSpy.last().first().toModelIndex(), index); - QCOMPARE(dataChangedSpy.last().last().value>(), QVector{int(PlasmaWindowModel::VirtualDesktop)}); - QCOMPARE(model->data(index, PlasmaWindowModel::VirtualDesktop).toInt(), 1); + QCOMPARE(dataChangedSpy.last().last().value>(), QVector{int(PlasmaWindowModel::VirtualDesktops)}); + QCOMPARE(model->data(index, PlasmaWindowModel::VirtualDesktops).toStringList(), QStringList({"desktop1", "desktop2"})); + QCOMPARE(model->data(index, PlasmaWindowModel::IsOnAllDesktops).toBool(), false); + + w->removePlasmaVirtualDesktop("desktop2"); + w->removePlasmaVirtualDesktop("desktop1"); + QVERIFY(dataChangedSpy.wait()); + QCOMPARE(dataChangedSpy.last().last().value>(), QVector{int(PlasmaWindowModel::IsOnAllDesktops)}); + QCOMPARE(model->data(index, PlasmaWindowModel::VirtualDesktops).toStringList(), QStringList({})); + QCOMPARE(model->data(index, PlasmaWindowModel::IsOnAllDesktops).toBool(), true); - // setting to same should not trigger - w->setVirtualDesktop(1); QVERIFY(!dataChangedSpy.wait(100)); } diff --git a/src/client/plasmawindowmanagement.cpp b/src/client/plasmawindowmanagement.cpp --- a/src/client/plasmawindowmanagement.cpp +++ b/src/client/plasmawindowmanagement.cpp @@ -471,6 +471,9 @@ const QString stringId(QString::fromUtf8(id)); p->plasmaVirtualDesktops << stringId; emit p->q->plasmaVirtualDesktopEntered(stringId); + if (p->plasmaVirtualDesktops.count() == 1) { + emit p->q->onAllDesktopsChanged(); + } } void PlasmaWindow::Private::virtualDesktopLeftCallback(void *data, org_kde_plasma_window *window, const char *id) @@ -480,6 +483,9 @@ const QString stringId(QString::fromUtf8(id)); p->plasmaVirtualDesktops.removeAll(stringId); emit p->q->plasmaVirtualDesktopLeft(stringId); + if (p->plasmaVirtualDesktops.isEmpty()) { + emit p->q->onAllDesktopsChanged(); + } } void PlasmaWindow::Private::stateChangedCallback(void *data, org_kde_plasma_window *window, uint32_t state) diff --git a/src/client/plasmawindowmodel.h b/src/client/plasmawindowmodel.h --- a/src/client/plasmawindowmodel.h +++ b/src/client/plasmawindowmodel.h @@ -70,6 +70,9 @@ IsMinimized, IsKeepAbove, IsKeepBelow, + /** + @deprecated @see VirtualDesktops + */ VirtualDesktop, IsOnAllDesktops, IsDemandingAttention, @@ -110,6 +113,10 @@ * @since 5.47 */ SkipSwitcher, + /** + * @since 5.55 + */ + VirtualDesktops }; Q_ENUM(AdditionalRoles) diff --git a/src/client/plasmawindowmodel.cpp b/src/client/plasmawindowmodel.cpp --- a/src/client/plasmawindowmodel.cpp +++ b/src/client/plasmawindowmodel.cpp @@ -164,6 +164,14 @@ QObject::connect(window, &PlasmaWindow::geometryChanged, q, [window, this] { this->dataChanged(window, Geometry); } ); + + QObject::connect(window, &PlasmaWindow::plasmaVirtualDesktopEntered, q, + [window, this] { this->dataChanged(window, VirtualDesktops); } + ); + + QObject::connect(window, &PlasmaWindow::plasmaVirtualDesktopLeft, q, + [window, this] { this->dataChanged(window, VirtualDesktops); } + ); } void PlasmaWindowModel::Private::dataChanged(PlasmaWindow *window, int role) @@ -273,6 +281,8 @@ return window->isCloseable(); } else if (role == Geometry) { return window->geometry(); + } else if (role == VirtualDesktops) { + return window->plasmaVirtualDesktops(); } return QVariant(); diff --git a/src/server/plasmawindowmanagement_interface.cpp b/src/server/plasmawindowmanagement_interface.cpp --- a/src/server/plasmawindowmanagement_interface.cpp +++ b/src/server/plasmawindowmanagement_interface.cpp @@ -882,12 +882,6 @@ return; } - //full? lets set it on all desktops, the plasmaVirtualDesktops list will get empty, which means it's on all desktops - if (d->wm->plasmaVirtualDesktopManagementInterface()->desktops().count() == d->plasmaVirtualDesktops.count() + 1) { - setOnAllDesktops(true); - return; - } - d->plasmaVirtualDesktops << id; //if the desktop dies, remove it from or list