KWin
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
showing_desktop_test.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "kwin_wayland_test.h"
10
11#include "wayland_server.h"
12#include "window.h"
13#include "workspace.h"
14
15#include <KWayland/Client/surface.h>
16
17using namespace KWin;
18
19static const QString s_socketName = QStringLiteral("wayland_test_kwin_showing_desktop-0");
20
21class ShowingDesktopTest : public QObject
22{
23 Q_OBJECT
24private Q_SLOTS:
25 void initTestCase();
26 void init();
27 void cleanup();
28
29 void testRestoreFocus();
30 void testRestoreFocusWithDesktopWindow();
31 void testQuitAfterActivatingHiddenWindow();
32 void testDontQuitAfterActivatingDock();
33 void testQuitAfterAddingWindow();
34 void testDontQuitAfterAddingDock();
35};
36
37void ShowingDesktopTest::initTestCase()
38{
39 qRegisterMetaType<KWin::Window *>();
40 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
41 QVERIFY(waylandServer()->init(s_socketName));
43 QRect(0, 0, 1280, 1024),
44 QRect(1280, 0, 1280, 1024),
45 });
46
47 kwinApp()->start();
48 QVERIFY(applicationStartedSpy.wait());
49}
50
51void ShowingDesktopTest::init()
52{
53 QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::LayerShellV1));
54}
55
56void ShowingDesktopTest::cleanup()
57{
59}
60
61void ShowingDesktopTest::testRestoreFocus()
62{
63 std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
64 std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
65 auto window1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
66 std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
67 std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
68 auto window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue);
69 QVERIFY(window1 != window2);
70
71 QCOMPARE(workspace()->activeWindow(), window2);
73 QVERIFY(workspace()->showingDesktop());
75 QVERIFY(!workspace()->showingDesktop());
76
77 QVERIFY(workspace()->activeWindow());
78 QCOMPARE(workspace()->activeWindow(), window2);
79}
80
81void ShowingDesktopTest::testRestoreFocusWithDesktopWindow()
82{
83 // first create a desktop window
84
85 std::unique_ptr<KWayland::Client::Surface> desktopSurface(Test::createSurface());
86 std::unique_ptr<Test::LayerSurfaceV1> desktopShellSurface(Test::createLayerSurfaceV1(desktopSurface.get(), QStringLiteral("desktop")));
87 desktopShellSurface->set_keyboard_interactivity(1);
88 desktopShellSurface->set_layer(Test::LayerShellV1::layer_background);
89 desktopShellSurface->set_size(0, 0);
90 desktopShellSurface->set_exclusive_zone(-1);
91 desktopShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom
92 | Test::LayerSurfaceV1::anchor_top
93 | Test::LayerSurfaceV1::anchor_left
94 | Test::LayerSurfaceV1::anchor_right);
95 desktopSurface->commit(KWayland::Client::Surface::CommitFlag::None);
96 QSignalSpy desktopConfigureRequestedSpy(desktopShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
97 QVERIFY(desktopConfigureRequestedSpy.wait());
98 auto desktop = Test::renderAndWaitForShown(desktopSurface.get(), desktopConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
99 QVERIFY(desktop);
100 QVERIFY(desktop->isDesktop());
101
102 // now create some windows
103 std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
104 std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
105 auto window1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
106 std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
107 std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
108 auto window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue);
109 QVERIFY(window1 != window2);
110
111 QCOMPARE(workspace()->activeWindow(), window2);
113 QVERIFY(workspace()->showingDesktop());
114 QCOMPARE(workspace()->activeWindow(), desktop);
116 QVERIFY(!workspace()->showingDesktop());
117
118 QVERIFY(workspace()->activeWindow());
119 QCOMPARE(workspace()->activeWindow(), window2);
120}
121
122void ShowingDesktopTest::testQuitAfterActivatingHiddenWindow()
123{
124 // This test verifies that the show desktop mode is deactivated after activating a hidden window.
125
126 std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
127 std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
128 auto window1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
129 std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
130 std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
131 auto window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue);
132 QCOMPARE(workspace()->activeWindow(), window2);
133
135 QVERIFY(workspace()->showingDesktop());
136
137 workspace()->activateWindow(window1);
138 QVERIFY(!workspace()->showingDesktop());
139}
140
141void ShowingDesktopTest::testDontQuitAfterActivatingDock()
142{
143 // This test verifies that activating windows belonging to desktop doesn't break showing desktop mode.
144
145 std::unique_ptr<KWayland::Client::Surface> desktopSurface(Test::createSurface());
146 std::unique_ptr<Test::LayerSurfaceV1> desktopShellSurface(Test::createLayerSurfaceV1(desktopSurface.get(), QStringLiteral("desktop")));
147 desktopShellSurface->set_keyboard_interactivity(1);
148 desktopShellSurface->set_layer(Test::LayerShellV1::layer_background);
149 desktopShellSurface->set_size(0, 0);
150 desktopShellSurface->set_exclusive_zone(-1);
151 desktopShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom
152 | Test::LayerSurfaceV1::anchor_top
153 | Test::LayerSurfaceV1::anchor_left
154 | Test::LayerSurfaceV1::anchor_right);
155 desktopSurface->commit(KWayland::Client::Surface::CommitFlag::None);
156 QSignalSpy desktopConfigureRequestedSpy(desktopShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
157 QVERIFY(desktopConfigureRequestedSpy.wait());
158 auto desktop = Test::renderAndWaitForShown(desktopSurface.get(), desktopConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
159
160 std::unique_ptr<KWayland::Client::Surface> dockSurface{Test::createSurface()};
161 std::unique_ptr<Test::LayerSurfaceV1> dockShellSurface{Test::createLayerSurfaceV1(dockSurface.get(), QStringLiteral("dock"))};
162 dockShellSurface->set_size(1280, 50);
163 dockShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom);
164 dockShellSurface->set_exclusive_zone(50);
165 dockShellSurface->set_keyboard_interactivity(1);
166 dockSurface->commit(KWayland::Client::Surface::CommitFlag::None);
167 QSignalSpy dockConfigureRequestedSpy(dockShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
168 QVERIFY(dockConfigureRequestedSpy.wait());
169 auto dock = Test::renderAndWaitForShown(dockSurface.get(), dockConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
170
171 std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
172 std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
173 auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
174 QVERIFY(window->isActive());
175
177 QVERIFY(workspace()->showingDesktop());
178 QVERIFY(desktop->isActive());
179
180 workspace()->activateWindow(dock);
181 QVERIFY(workspace()->showingDesktop());
182 QVERIFY(dock->isActive());
183
184 workspace()->activateWindow(desktop);
185 QVERIFY(workspace()->showingDesktop());
186 QVERIFY(desktop->isActive());
187
189 QVERIFY(!workspace()->showingDesktop());
190}
191
192void ShowingDesktopTest::testQuitAfterAddingWindow()
193{
194 // This test verifies that the show desktop mode is deactivated after mapping a new window.
195
196 std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
197 std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
198 Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
199
201 QVERIFY(workspace()->showingDesktop());
202
203 std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
204 std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
205 Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue);
206
207 QVERIFY(!workspace()->showingDesktop());
208}
209
210void ShowingDesktopTest::testDontQuitAfterAddingDock()
211{
212 // This test verifies that the show desktop mode is not broken after adding a dock.
213
214 std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
215 std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
216 auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
217 QVERIFY(window->isActive());
218
220 QVERIFY(workspace()->showingDesktop());
221
222 std::unique_ptr<KWayland::Client::Surface> dockSurface{Test::createSurface()};
223 std::unique_ptr<Test::LayerSurfaceV1> dockShellSurface{Test::createLayerSurfaceV1(dockSurface.get(), QStringLiteral("dock"))};
224 dockShellSurface->set_size(1280, 50);
225 dockShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom);
226 dockShellSurface->set_exclusive_zone(50);
227 dockShellSurface->set_keyboard_interactivity(1);
228 dockSurface->commit(KWayland::Client::Surface::CommitFlag::None);
229 QSignalSpy dockConfigureRequestedSpy(dockShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
230 QVERIFY(dockConfigureRequestedSpy.wait());
231 auto dock = Test::renderAndWaitForShown(dockSurface.get(), dockConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
232 QVERIFY(dock->isActive());
233
234 QVERIFY(workspace()->showingDesktop());
236}
237
239#include "showing_desktop_test.moc"
void configureRequested(quint32 serial, const QSize &size)
void slotToggleShowDesktop()
void activateWindow(Window *window, bool force=false)
#define WAYLANDTEST_MAIN(TestObject)
Window * renderAndWaitForShown(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format=QImage::Format_ARGB32, int timeout=5000)
void destroyWaylandConnection()
void setOutputConfig(const QList< QRect > &geometries)
bool setupWaylandConnection(AdditionalWaylandInterfaces flags=AdditionalWaylandInterfaces())
LayerSurfaceV1 * createLayerSurfaceV1(KWayland::Client::Surface *surface, const QString &scope, KWayland::Client::Output *output=nullptr, LayerShellV1::layer layer=LayerShellV1::layer_top)
std::unique_ptr< KWayland::Client::Surface > createSurface()
XdgToplevel * createXdgToplevelSurface(KWayland::Client::Surface *surface, QObject *parent=nullptr)
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830