From 3e62f6aabebaa66dda7487e8fe74c0c328d86078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Wed, 12 Dec 2018 18:25:51 +0100 Subject: [PATCH] Remove no longer needed cast to Client in Workspace::sendClientToDesktop Summary: This change removes a small difference between X11 and Wayland clients. It ensures that all transients are sent to the same desktop as the main window. A similar check is already in AbstractClient::setDesktop, so in general it already worked. This is just a special case for sendClientToDesktop which supports sending to the same desktop so that all transients are sent to that desktop. Test Plan: New test case which fails without this change Reviewers: #kwin Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D17546 --- autotests/integration/shell_client_test.cpp | 58 +++++++++++++++++++++ workspace.cpp | 13 ++--- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/autotests/integration/shell_client_test.cpp b/autotests/integration/shell_client_test.cpp index d8a8a75002..d3ffa887e5 100644 --- a/autotests/integration/shell_client_test.cpp +++ b/autotests/integration/shell_client_test.cpp @@ -92,6 +92,8 @@ private Q_SLOTS: void testAppMenu(); void testNoDecorationModeRequested_data(); void testNoDecorationModeRequested(); + void testSendClientWithTransientToDesktop_data(); + void testSendClientWithTransientToDesktop(); }; void TestShellClient::initTestCase() @@ -1087,5 +1089,61 @@ void TestShellClient::testNoDecorationModeRequested() QCOMPARE(c->isDecorated(), true); } +void TestShellClient::testSendClientWithTransientToDesktop_data() +{ + QTest::addColumn("type"); + + QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; + QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6; + QTest::newRow("xdgWmBase") << Test::ShellSurfaceType::XdgShellStable; +} + +void TestShellClient::testSendClientWithTransientToDesktop() +{ + // this test verifies that when sending a client to a desktop all transients are also send to that desktop + + VirtualDesktopManager::self()->setCount(2); + QScopedPointer surface{Test::createSurface()}; + QFETCH(Test::ShellSurfaceType, type); + QScopedPointer shellSurface{qobject_cast(Test::createShellSurface(type, surface.data()))}; + + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); + QVERIFY(c); + + // let's create a transient window + QScopedPointer transientSurface{Test::createSurface()}; + QScopedPointer transientShellSurface{qobject_cast(Test::createShellSurface(type, transientSurface.data()))}; + transientShellSurface->setTransientFor(shellSurface.data()); + + auto transient = Test::renderAndWaitForShown(transientSurface.data(), QSize(100, 50), Qt::blue); + QVERIFY(transient); + QCOMPARE(workspace()->activeClient(), transient); + QCOMPARE(transient->transientFor(), c); + QVERIFY(c->transients().contains(transient)); + + QCOMPARE(c->desktop(), 1); + QVERIFY(!c->isOnAllDesktops()); + QCOMPARE(transient->desktop(), 1); + QVERIFY(!transient->isOnAllDesktops()); + workspace()->slotWindowToDesktop(2); + + QCOMPARE(c->desktop(), 1); + QCOMPARE(transient->desktop(), 2); + + // activate c + workspace()->activateClient(c); + QCOMPARE(workspace()->activeClient(), c); + QVERIFY(c->isActive()); + + // and send it to the desktop it's already on + QCOMPARE(c->desktop(), 1); + QCOMPARE(transient->desktop(), 2); + workspace()->slotWindowToDesktop(1); + + // which should move the transient back to the desktop + QCOMPARE(c->desktop(), 1); + QCOMPARE(transient->desktop(), 1); +} + WAYLANDTEST_MAIN(TestShellClient) #include "shell_client_test.moc" diff --git a/workspace.cpp b/workspace.cpp index 25eeda8be5..734e3fdc07 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -1169,14 +1169,11 @@ void Workspace::sendClientToDesktop(AbstractClient* c, int desk, bool dont_activ c->checkWorkspacePosition( QRect(), old_desktop ); - if (Client *client = dynamic_cast(c)) { - // TODO: adjust transients for non-X11 - auto transients_stacking_order = ensureStackingOrder(client->transients()); - for (auto it = transients_stacking_order.constBegin(); - it != transients_stacking_order.constEnd(); - ++it) - sendClientToDesktop(*it, desk, dont_activate); - } + auto transients_stacking_order = ensureStackingOrder(c->transients()); + for (auto it = transients_stacking_order.constBegin(); + it != transients_stacking_order.constEnd(); + ++it) + sendClientToDesktop(*it, desk, dont_activate); updateClientArea(); }