Warning, file /plasma/kwin/autotests/integration/showing_desktop_test.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "kwin_wayland_test.h" 0010 0011 #include "core/outputbackend.h" 0012 #include "wayland_server.h" 0013 #include "window.h" 0014 #include "workspace.h" 0015 0016 #include <KWayland/Client/plasmashell.h> 0017 #include <KWayland/Client/surface.h> 0018 0019 using namespace KWin; 0020 0021 static const QString s_socketName = QStringLiteral("wayland_test_kwin_showing_desktop-0"); 0022 0023 class ShowingDesktopTest : public QObject 0024 { 0025 Q_OBJECT 0026 private Q_SLOTS: 0027 void initTestCase(); 0028 void init(); 0029 void cleanup(); 0030 0031 void testRestoreFocus(); 0032 void testRestoreFocusWithDesktopWindow(); 0033 }; 0034 0035 void ShowingDesktopTest::initTestCase() 0036 { 0037 qRegisterMetaType<KWin::Window *>(); 0038 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started); 0039 QVERIFY(waylandServer()->init(s_socketName)); 0040 QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024))); 0041 0042 kwinApp()->start(); 0043 QVERIFY(applicationStartedSpy.wait()); 0044 } 0045 0046 void ShowingDesktopTest::init() 0047 { 0048 QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::PlasmaShell)); 0049 } 0050 0051 void ShowingDesktopTest::cleanup() 0052 { 0053 Test::destroyWaylandConnection(); 0054 } 0055 0056 void ShowingDesktopTest::testRestoreFocus() 0057 { 0058 std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface()); 0059 std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get())); 0060 auto window1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue); 0061 std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface()); 0062 std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get())); 0063 auto window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue); 0064 QVERIFY(window1 != window2); 0065 0066 QCOMPARE(workspace()->activeWindow(), window2); 0067 workspace()->slotToggleShowDesktop(); 0068 QVERIFY(workspace()->showingDesktop()); 0069 workspace()->slotToggleShowDesktop(); 0070 QVERIFY(!workspace()->showingDesktop()); 0071 0072 QVERIFY(workspace()->activeWindow()); 0073 QCOMPARE(workspace()->activeWindow(), window2); 0074 } 0075 0076 void ShowingDesktopTest::testRestoreFocusWithDesktopWindow() 0077 { 0078 // first create a desktop window 0079 0080 std::unique_ptr<KWayland::Client::Surface> desktopSurface(Test::createSurface()); 0081 QVERIFY(desktopSurface != nullptr); 0082 std::unique_ptr<Test::XdgToplevel> desktopShellSurface(Test::createXdgToplevelSurface(desktopSurface.get())); 0083 QVERIFY(desktopSurface != nullptr); 0084 std::unique_ptr<KWayland::Client::PlasmaShellSurface> plasmaSurface(Test::waylandPlasmaShell()->createSurface(desktopSurface.get())); 0085 QVERIFY(plasmaSurface != nullptr); 0086 plasmaSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::Desktop); 0087 0088 auto desktop = Test::renderAndWaitForShown(desktopSurface.get(), QSize(100, 50), Qt::blue); 0089 QVERIFY(desktop); 0090 QVERIFY(desktop->isDesktop()); 0091 0092 // now create some windows 0093 std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface()); 0094 std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get())); 0095 auto window1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue); 0096 std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface()); 0097 std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get())); 0098 auto window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue); 0099 QVERIFY(window1 != window2); 0100 0101 QCOMPARE(workspace()->activeWindow(), window2); 0102 workspace()->slotToggleShowDesktop(); 0103 QVERIFY(workspace()->showingDesktop()); 0104 QCOMPARE(workspace()->activeWindow(), desktop); 0105 workspace()->slotToggleShowDesktop(); 0106 QVERIFY(!workspace()->showingDesktop()); 0107 0108 QVERIFY(workspace()->activeWindow()); 0109 QCOMPARE(workspace()->activeWindow(), window2); 0110 } 0111 0112 WAYLANDTEST_MAIN(ShowingDesktopTest) 0113 #include "showing_desktop_test.moc"