From 0d96e60b79a760e3fc17ee781a4d2b97dce915e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Sun, 1 Oct 2017 11:01:55 +0200 Subject: [PATCH] Also send Wayland clients to a new desktop if their desktop was removed Summary: So far the method only operated on X11 clients. So when the last desktop got removed Wayland clients were still on it. As the auto test showed: this results in a crash. Credits go to code coverage as it showed that area as red, which made me look on it and realize this must be broken. Test Plan: New test case added Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D8082 --- autotests/integration/CMakeLists.txt | 1 + .../integration/virtual_desktop_test.cpp | 117 ++++++++++++++++++ workspace.cpp | 2 +- 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 autotests/integration/virtual_desktop_test.cpp diff --git a/autotests/integration/CMakeLists.txt b/autotests/integration/CMakeLists.txt index 294043bd0e..58c16aa9ba 100644 --- a/autotests/integration/CMakeLists.txt +++ b/autotests/integration/CMakeLists.txt @@ -46,6 +46,7 @@ integrationTest(NAME testKeymapCreationFailure SRCS keymap_creation_failure_test integrationTest(NAME testShowingDesktop SRCS showing_desktop_test.cpp) integrationTest(NAME testDontCrashUseractionsMenu SRCS dont_crash_useractions_menu.cpp) integrationTest(NAME testKWinBindings SRCS kwinbindings_test.cpp) +integrationTest(NAME testVirtualDesktop SRCS virtual_desktop_test.cpp) if (XCB_ICCCM_FOUND) integrationTest(NAME testMoveResize SRCS move_resize_window_test.cpp LIBS XCB::ICCCM) diff --git a/autotests/integration/virtual_desktop_test.cpp b/autotests/integration/virtual_desktop_test.cpp new file mode 100644 index 0000000000..82a7c405de --- /dev/null +++ b/autotests/integration/virtual_desktop_test.cpp @@ -0,0 +1,117 @@ +/******************************************************************** +KWin - the KDE window manager +This file is part of the KDE project. + +Copyright (C) 2017 Martin Flöser + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +#include "kwin_wayland_test.h" +#include "main.h" +#include "platform.h" +#include "screens.h" +#include "shell_client.h" +#include "wayland_server.h" +#include "virtualdesktops.h" + +#include + +using namespace KWin; +using namespace KWayland::Client; + +static const QString s_socketName = QStringLiteral("wayland_test_kwin_virtualdesktop-0"); + +class VirtualDesktopTest : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void initTestCase(); + void init(); + void cleanup(); + + void testLastDesktopRemoved_data(); + void testLastDesktopRemoved(); +}; + +void VirtualDesktopTest::initTestCase() +{ + qRegisterMetaType(); + qRegisterMetaType(); + QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); + QVERIFY(workspaceCreatedSpy.isValid()); + kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); + QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); + + kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); + qputenv("KWIN_XKB_DEFAULT_KEYMAP", "1"); + qputenv("XKB_DEFAULT_RULES", "evdev"); + + kwinApp()->start(); + QVERIFY(workspaceCreatedSpy.wait()); + waylandServer()->initWorkspace(); +} + +void VirtualDesktopTest::init() +{ + QVERIFY(Test::setupWaylandConnection()); + screens()->setCurrent(0); + VirtualDesktopManager::self()->setCount(1); +} + +void VirtualDesktopTest::cleanup() +{ + Test::destroyWaylandConnection(); +} + +void VirtualDesktopTest::testLastDesktopRemoved_data() +{ + QTest::addColumn("type"); + + QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; + QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; + QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6; +} + +void VirtualDesktopTest::testLastDesktopRemoved() +{ + // first create a new desktop + QCOMPARE(VirtualDesktopManager::self()->count(), 1u); + VirtualDesktopManager::self()->setCount(2); + QCOMPARE(VirtualDesktopManager::self()->count(), 2u); + + // switch to last desktop + VirtualDesktopManager::self()->setCurrent(VirtualDesktopManager::self()->desktops().last()); + QCOMPARE(VirtualDesktopManager::self()->current(), 2u); + + // now create a window on this desktop + QScopedPointer surface(Test::createSurface()); + QFETCH(Test::ShellSurfaceType, type); + QScopedPointer shellSurface(Test::createShellSurface(type, surface.data())); + auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); + + QVERIFY(client); + QCOMPARE(client->desktop(), 2); + QSignalSpy desktopPresenceChangedSpy(client, &ShellClient::desktopPresenceChanged); + QVERIFY(desktopPresenceChangedSpy.isValid()); + + // and remove last desktop + VirtualDesktopManager::self()->setCount(1); + QCOMPARE(VirtualDesktopManager::self()->count(), 1u); + // now the client should be moved as well + QTRY_COMPARE(desktopPresenceChangedSpy.count(), 1); + QCOMPARE(client->desktop(), 1); +} + +WAYLANDTEST_MAIN(VirtualDesktopTest) +#include "virtual_desktop_test.moc" diff --git a/workspace.cpp b/workspace.cpp index d62c2a71c9..bac6e30acd 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -1134,7 +1134,7 @@ void Workspace::updateCurrentActivity(const QString &new_activity) void Workspace::moveClientsFromRemovedDesktops() { - for (ClientList::ConstIterator it = clients.constBegin(); it != clients.constEnd(); ++it) { + for (auto it = m_allClients.constBegin(); it != m_allClients.constEnd(); ++it) { if (!(*it)->isOnAllDesktops() && (*it)->desktop() > static_cast(VirtualDesktopManager::self()->count())) sendClientToDesktop(*it, VirtualDesktopManager::self()->count(), true); }