KWin
Loading...
Searching...
No Matches
test_wayland_windowmanagement.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6// Qt
7#include <QSignalSpy>
8#include <QTest>
9// KWin
10#include "wayland/compositor.h"
11#include "wayland/display.h"
13#include "wayland/surface.h"
14#include <wayland-plasma-window-management-client-protocol.h>
15
16#include "KWayland/Client/compositor.h"
17#include "KWayland/Client/connection_thread.h"
18#include "KWayland/Client/event_queue.h"
19#include "KWayland/Client/plasmawindowmanagement.h"
20#include "KWayland/Client/region.h"
21#include "KWayland/Client/registry.h"
22#include "KWayland/Client/surface.h"
23
26typedef void (KWin::PlasmaWindowInterface::*ServerWindowBooleanSignal)(bool);
28typedef void (KWayland::Client::PlasmaWindow::*ClientWindowVoidSetter)();
30
31class TestWindowManagement : public QObject
32{
33 Q_OBJECT
34public:
35 explicit TestWindowManagement(QObject *parent = nullptr);
36private Q_SLOTS:
37 void init();
38
39 void testWindowTitle();
40 void testReallyLongTitle();
41 void testMinimizedGeometry();
42 void testUseAfterUnmap();
43 void testServerDelete();
44 void testActiveWindowOnUnmapped();
45 void testDeleteActiveWindow();
46 void testCreateAfterUnmap();
47 void testRequests_data();
48 void testRequests();
49 void testRequestsBoolean_data();
50 void testRequestsBoolean();
51 void testKeepAbove();
52 void testKeepBelow();
53 void testShowingDesktop();
54 void testRequestShowingDesktop_data();
55 void testRequestShowingDesktop();
56 void testParentWindow();
57 void testGeometry();
58 void testIcon();
59 void testPid();
60 void testApplicationMenu();
61
62 void cleanup();
63
64private:
65 KWin::Display *m_display;
66 KWin::CompositorInterface *m_compositorInterface;
67 KWin::PlasmaWindowManagementInterface *m_windowManagementInterface;
68 KWin::PlasmaWindowInterface *m_windowInterface;
69 QPointer<KWin::SurfaceInterface> m_surfaceInterface;
70
71 KWayland::Client::Surface *m_surface = nullptr;
72 KWayland::Client::ConnectionThread *m_connection;
73 KWayland::Client::Compositor *m_compositor;
74 KWayland::Client::EventQueue *m_queue;
75 KWayland::Client::PlasmaWindowManagement *m_windowManagement;
76 KWayland::Client::PlasmaWindow *m_window;
77 QThread *m_thread;
78 KWayland::Client::Registry *m_registry;
79};
80
81static const QString s_socketName = QStringLiteral("kwayland-test-wayland-windowmanagement-0");
82
84 : QObject(parent)
85 , m_display(nullptr)
86 , m_compositorInterface(nullptr)
87 , m_connection(nullptr)
88 , m_compositor(nullptr)
89 , m_queue(nullptr)
90 , m_thread(nullptr)
91{
92}
93
94void TestWindowManagement::init()
95{
96 using namespace KWin;
97 qRegisterMetaType<KWin::PlasmaWindowManagementInterface::ShowingDesktopState>("ShowingDesktopState");
98 delete m_display;
99 m_display = new KWin::Display(this);
100 m_display->addSocketName(s_socketName);
101 m_display->start();
102 QVERIFY(m_display->isRunning());
103
104 // setup connection
105 m_connection = new KWayland::Client::ConnectionThread;
106 QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
107 m_connection->setSocketName(s_socketName);
108
109 m_thread = new QThread(this);
110 m_connection->moveToThread(m_thread);
111 m_thread->start();
112
113 m_connection->initConnection();
114 QVERIFY(connectedSpy.wait());
115
116 m_queue = new KWayland::Client::EventQueue(this);
117 QVERIFY(!m_queue->isValid());
118 m_queue->setup(m_connection);
119 QVERIFY(m_queue->isValid());
120
121 m_registry = new KWayland::Client::Registry(this);
122 QSignalSpy compositorSpy(m_registry, &KWayland::Client::Registry::compositorAnnounced);
123
124 QSignalSpy windowManagementSpy(m_registry, &KWayland::Client::Registry::plasmaWindowManagementAnnounced);
125
126 QVERIFY(!m_registry->eventQueue());
127 m_registry->setEventQueue(m_queue);
128 QCOMPARE(m_registry->eventQueue(), m_queue);
129 m_registry->create(m_connection->display());
130 QVERIFY(m_registry->isValid());
131 m_registry->setup();
132
133 m_compositorInterface = new CompositorInterface(m_display, m_display);
134 QVERIFY(compositorSpy.wait());
135 m_compositor = m_registry->createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
136
137 m_windowManagementInterface = new PlasmaWindowManagementInterface(m_display, m_display);
138
139 QVERIFY(windowManagementSpy.wait());
140 m_windowManagement = m_registry->createPlasmaWindowManagement(windowManagementSpy.first().first().value<quint32>(),
141 windowManagementSpy.first().last().value<quint32>(),
142 this);
143
144 QSignalSpy windowSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
145 m_windowInterface = m_windowManagementInterface->createWindow(this, QUuid::createUuid());
146 m_windowInterface->setPid(1337);
147
148 QVERIFY(windowSpy.wait());
149 m_window = windowSpy.first().first().value<KWayland::Client::PlasmaWindow *>();
150
151 QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
152 m_surface = m_compositor->createSurface(this);
153 QVERIFY(m_surface);
154
155 QVERIFY(serverSurfaceCreated.wait());
156 m_surfaceInterface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
157 QVERIFY(m_surfaceInterface);
158}
159
160void TestWindowManagement::testWindowTitle()
161{
162 m_windowInterface->setTitle(QStringLiteral("Test Title"));
163
164 QSignalSpy titleSpy(m_window, &KWayland::Client::PlasmaWindow::titleChanged);
165
166 QVERIFY(titleSpy.wait());
167
168 QCOMPARE(m_window->title(), QString::fromUtf8("Test Title"));
169}
170
171void TestWindowManagement::testReallyLongTitle()
172{
173 QString title;
174 title.fill(QLatin1Char('t'), 500000);
175 m_windowInterface->setTitle(title);
176
177 QSignalSpy titleSpy(m_window, &KWayland::Client::PlasmaWindow::titleChanged);
178
179 QVERIFY(titleSpy.wait());
180 QVERIFY(m_window->title().startsWith("t"));
181}
182
183void TestWindowManagement::testMinimizedGeometry()
184{
185 m_window->setMinimizedGeometry(m_surface, QRect(5, 10, 100, 200));
186
187 QSignalSpy geometrySpy(m_windowInterface, &KWin::PlasmaWindowInterface::minimizedGeometriesChanged);
188
189 QVERIFY(geometrySpy.wait());
190 QCOMPARE(m_windowInterface->minimizedGeometries().values().first(), QRect(5, 10, 100, 200));
191
192 m_window->unsetMinimizedGeometry(m_surface);
193 QVERIFY(geometrySpy.wait());
194 QVERIFY(m_windowInterface->minimizedGeometries().isEmpty());
195}
196
197void TestWindowManagement::cleanup()
198{
199 if (m_surface) {
200 delete m_surface;
201 m_surface = nullptr;
202 }
203 if (m_compositor) {
204 delete m_compositor;
205 m_compositor = nullptr;
206 }
207 if (m_queue) {
208 delete m_queue;
209 m_queue = nullptr;
210 }
211 if (m_windowManagement) {
212 delete m_windowManagement;
213 m_windowManagement = nullptr;
214 }
215 if (m_registry) {
216 delete m_registry;
217 m_registry = nullptr;
218 }
219 if (m_thread) {
220 if (m_connection) {
221 m_connection->flush();
222 m_connection->deleteLater();
223 }
224 m_thread->quit();
225 m_thread->wait();
226 delete m_thread;
227 m_thread = nullptr;
228 }
229 m_connection = nullptr;
230
231 m_display->dispatchEvents();
232
233 QVERIFY(m_surfaceInterface.isNull());
234
235 delete m_display;
236 m_display = nullptr;
237
238 // these are the children of the display
239 m_windowManagementInterface = nullptr;
240 m_windowInterface = nullptr;
241}
242
243void TestWindowManagement::testUseAfterUnmap()
244{
245 // this test verifies that when the client uses a window after it's unmapped, things don't break
246 QSignalSpy unmappedSpy(m_window, &KWayland::Client::PlasmaWindow::unmapped);
247 QSignalSpy destroyedSpy(m_window, &QObject::destroyed);
248 m_windowInterface->deleteLater();
249 m_windowInterface = nullptr;
250 m_window->requestClose();
251 QVERIFY(unmappedSpy.wait());
252 QVERIFY(destroyedSpy.wait());
253 m_window = nullptr;
254}
255
256void TestWindowManagement::testServerDelete()
257{
258 QSignalSpy unmappedSpy(m_window, &KWayland::Client::PlasmaWindow::unmapped);
259 QSignalSpy destroyedSpy(m_window, &QObject::destroyed);
260 delete m_windowInterface;
261 m_windowInterface = nullptr;
262 QVERIFY(unmappedSpy.wait());
263 QVERIFY(destroyedSpy.wait());
264 m_window = nullptr;
265}
266
267void TestWindowManagement::testActiveWindowOnUnmapped()
268{
269 // This test verifies that unmapping the active window changes the active window.
270 // first make the window active
271 QVERIFY(!m_windowManagement->activeWindow());
272 QVERIFY(!m_window->isActive());
273 QSignalSpy activeWindowChangedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::activeWindowChanged);
274 m_windowInterface->setActive(true);
275 QVERIFY(activeWindowChangedSpy.wait());
276 QCOMPARE(m_windowManagement->activeWindow(), m_window);
277 QVERIFY(m_window->isActive());
278
279 // now unmap should change the active window
280 QSignalSpy destroyedSpy(m_window, &QObject::destroyed);
281 QSignalSpy serverDestroyedSpy(m_windowInterface, &QObject::destroyed);
282 delete m_windowInterface;
283 m_windowInterface = nullptr;
284 QVERIFY(activeWindowChangedSpy.wait());
285 QVERIFY(!m_windowManagement->activeWindow());
286}
287
288void TestWindowManagement::testDeleteActiveWindow()
289{
290 // This test verifies that deleting the active window on client side changes the active window
291 // first make the window active
292 QVERIFY(!m_windowManagement->activeWindow());
293 QVERIFY(!m_window->isActive());
294 QSignalSpy activeWindowChangedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::activeWindowChanged);
295 m_windowInterface->setActive(true);
296 QVERIFY(activeWindowChangedSpy.wait());
297 QCOMPARE(activeWindowChangedSpy.count(), 1);
298 QCOMPARE(m_windowManagement->activeWindow(), m_window);
299 QVERIFY(m_window->isActive());
300
301 // delete the client side window - that's semantically kind of wrong, but shouldn't make our code crash
302 delete m_window;
303 m_window = nullptr;
304 QCOMPARE(activeWindowChangedSpy.count(), 2);
305 QVERIFY(!m_windowManagement->activeWindow());
306}
307
308void TestWindowManagement::testCreateAfterUnmap()
309{
310 // this test verifies that we don't get a protocol error on client side when creating an already unmapped window.
311 QCOMPARE(m_windowManagement->children().count(), 1);
312
313 QSignalSpy windowAddedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
314
315 // create and unmap in one go
316 // client will first handle the create, the unmap will be sent once the server side is bound
317 auto serverWindow = m_windowManagementInterface->createWindow(m_windowManagementInterface, QUuid::createUuid());
318 delete serverWindow;
319 QCOMPARE(m_windowManagementInterface->children().count(), 0);
320
321 windowAddedSpy.wait();
322 auto window = dynamic_cast<KWayland::Client::PlasmaWindow *>(m_windowManagement->children().last());
323 QVERIFY(window);
324 // now this is not yet on the server, on the server it will be after next roundtrip
325 // which we can trigger by waiting for destroy of the newly created window.
326 // why destroy? Because we will get the unmap which triggers a destroy
327 QSignalSpy clientDestroyedSpy(window, &QObject::destroyed);
328 QVERIFY(clientDestroyedSpy.wait());
329 // Verify that any wrappers created for our temporary window are now gone
330 QCOMPARE(m_windowManagement->children().count(), 1);
331}
332
333void TestWindowManagement::testRequests_data()
334{
335 using namespace KWin;
336 QTest::addColumn<ServerWindowSignal>("changedSignal");
337 QTest::addColumn<ClientWindowVoidSetter>("requester");
338
339 QTest::newRow("close") << &PlasmaWindowInterface::closeRequested << &KWayland::Client::PlasmaWindow::requestClose;
340 QTest::newRow("move") << &PlasmaWindowInterface::moveRequested << &KWayland::Client::PlasmaWindow::requestMove;
341 QTest::newRow("resize") << &PlasmaWindowInterface::resizeRequested << &KWayland::Client::PlasmaWindow::requestResize;
342}
343
344void TestWindowManagement::testRequests()
345{
346 // this test case verifies all the different requests on a PlasmaWindow
347 QFETCH(ServerWindowSignal, changedSignal);
348 QSignalSpy requestSpy(m_windowInterface, changedSignal);
349 QFETCH(ClientWindowVoidSetter, requester);
350 (m_window->*(requester))();
351 QVERIFY(requestSpy.wait());
352}
353
354void TestWindowManagement::testRequestsBoolean_data()
355{
356 using namespace KWin;
357 QTest::addColumn<ServerWindowBooleanSignal>("changedSignal");
358 QTest::addColumn<int>("flag");
359
360 QTest::newRow("activate") << &PlasmaWindowInterface::activeRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ACTIVE);
361 QTest::newRow("minimized") << &PlasmaWindowInterface::minimizedRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZED);
362 QTest::newRow("maximized") << &PlasmaWindowInterface::maximizedRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZED);
363 QTest::newRow("fullscreen") << &PlasmaWindowInterface::fullscreenRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREEN);
364 QTest::newRow("keepAbove") << &PlasmaWindowInterface::keepAboveRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_ABOVE);
365 QTest::newRow("keepBelow") << &PlasmaWindowInterface::keepBelowRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_BELOW);
366 QTest::newRow("demandsAttention") << &PlasmaWindowInterface::demandsAttentionRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_DEMANDS_ATTENTION);
367 QTest::newRow("closeable") << &PlasmaWindowInterface::closeableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_CLOSEABLE);
368 QTest::newRow("minimizable") << &PlasmaWindowInterface::minimizeableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZABLE);
369 QTest::newRow("maximizable") << &PlasmaWindowInterface::maximizeableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZABLE);
370 QTest::newRow("fullscreenable") << &PlasmaWindowInterface::fullscreenableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREENABLE);
371 QTest::newRow("skiptaskbar") << &PlasmaWindowInterface::skipTaskbarRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPTASKBAR);
372 QTest::newRow("skipSwitcher") << &PlasmaWindowInterface::skipSwitcherRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPSWITCHER);
373 QTest::newRow("shadeable") << &PlasmaWindowInterface::shadeableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADEABLE);
374 QTest::newRow("shaded") << &PlasmaWindowInterface::shadedRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADED);
375 QTest::newRow("movable") << &PlasmaWindowInterface::movableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MOVABLE);
376 QTest::newRow("resizable") << &PlasmaWindowInterface::resizableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_RESIZABLE);
377 QTest::newRow("virtualDesktopChangeable") << &PlasmaWindowInterface::virtualDesktopChangeableRequested
378 << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_VIRTUAL_DESKTOP_CHANGEABLE);
379}
380
381void TestWindowManagement::testRequestsBoolean()
382{
383 // this test case verifies all the different requests on a PlasmaWindow
384 QFETCH(ServerWindowBooleanSignal, changedSignal);
385 QSignalSpy requestSpy(m_windowInterface, changedSignal);
386 QFETCH(int, flag);
387 org_kde_plasma_window_set_state(*m_window, flag, flag);
388 QVERIFY(requestSpy.wait());
389 QCOMPARE(requestSpy.count(), 1);
390 QCOMPARE(requestSpy.first().first().toBool(), true);
391 org_kde_plasma_window_set_state(*m_window, flag, 0);
392 QVERIFY(requestSpy.wait());
393 QCOMPARE(requestSpy.count(), 2);
394 QCOMPARE(requestSpy.last().first().toBool(), false);
395}
396
397void TestWindowManagement::testShowingDesktop()
398{
399 using namespace KWin;
400 // this test verifies setting the showing desktop state
401 QVERIFY(!m_windowManagement->isShowingDesktop());
402 QSignalSpy showingDesktopChangedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::showingDesktopChanged);
403 m_windowManagementInterface->setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState::Enabled);
404 QVERIFY(showingDesktopChangedSpy.wait());
405 QCOMPARE(showingDesktopChangedSpy.count(), 1);
406 QCOMPARE(showingDesktopChangedSpy.first().first().toBool(), true);
407 QVERIFY(m_windowManagement->isShowingDesktop());
408 // setting to same should not change
409 m_windowManagementInterface->setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState::Enabled);
410 QVERIFY(!showingDesktopChangedSpy.wait(100));
411 QCOMPARE(showingDesktopChangedSpy.count(), 1);
412 // setting to other state should change
413 m_windowManagementInterface->setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState::Disabled);
414 QVERIFY(showingDesktopChangedSpy.wait());
415 QCOMPARE(showingDesktopChangedSpy.count(), 2);
416 QCOMPARE(showingDesktopChangedSpy.first().first().toBool(), true);
417 QCOMPARE(showingDesktopChangedSpy.last().first().toBool(), false);
418 QVERIFY(!m_windowManagement->isShowingDesktop());
419}
420
421void TestWindowManagement::testRequestShowingDesktop_data()
422{
423 using namespace KWin;
424 QTest::addColumn<bool>("value");
425 QTest::addColumn<PlasmaWindowManagementInterface::ShowingDesktopState>("expectedValue");
426
427 QTest::newRow("enable") << true << PlasmaWindowManagementInterface::ShowingDesktopState::Enabled;
428 QTest::newRow("disable") << false << PlasmaWindowManagementInterface::ShowingDesktopState::Disabled;
429}
430
431void TestWindowManagement::testRequestShowingDesktop()
432{
433 // this test verifies requesting show desktop state
434 using namespace KWin;
435 QSignalSpy requestSpy(m_windowManagementInterface, &PlasmaWindowManagementInterface::requestChangeShowingDesktop);
436 QFETCH(bool, value);
437 m_windowManagement->setShowingDesktop(value);
438 QVERIFY(requestSpy.wait());
439 QCOMPARE(requestSpy.count(), 1);
440 QTEST(requestSpy.first().first().value<PlasmaWindowManagementInterface::ShowingDesktopState>(), "expectedValue");
441}
442
443void TestWindowManagement::testKeepAbove()
444{
445 using namespace KWin;
446 // this test verifies setting the keep above state
447 QVERIFY(!m_window->isKeepAbove());
448 QSignalSpy keepAboveChangedSpy(m_window, &KWayland::Client::PlasmaWindow::keepAboveChanged);
449 m_windowInterface->setKeepAbove(true);
450 QVERIFY(keepAboveChangedSpy.wait());
451 QCOMPARE(keepAboveChangedSpy.count(), 1);
452 QVERIFY(m_window->isKeepAbove());
453 // setting to same should not change
454 m_windowInterface->setKeepAbove(true);
455 QVERIFY(!keepAboveChangedSpy.wait(100));
456 QCOMPARE(keepAboveChangedSpy.count(), 1);
457 // setting to other state should change
458 m_windowInterface->setKeepAbove(false);
459 QVERIFY(keepAboveChangedSpy.wait());
460 QCOMPARE(keepAboveChangedSpy.count(), 2);
461 QVERIFY(!m_window->isKeepAbove());
462}
463
464void TestWindowManagement::testKeepBelow()
465{
466 using namespace KWin;
467 // this test verifies setting the keep below state
468 QVERIFY(!m_window->isKeepBelow());
469 QSignalSpy keepBelowChangedSpy(m_window, &KWayland::Client::PlasmaWindow::keepBelowChanged);
470 m_windowInterface->setKeepBelow(true);
471 QVERIFY(keepBelowChangedSpy.wait());
472 QCOMPARE(keepBelowChangedSpy.count(), 1);
473 QVERIFY(m_window->isKeepBelow());
474 // setting to same should not change
475 m_windowInterface->setKeepBelow(true);
476 QVERIFY(!keepBelowChangedSpy.wait(100));
477 QCOMPARE(keepBelowChangedSpy.count(), 1);
478 // setting to other state should change
479 m_windowInterface->setKeepBelow(false);
480 QVERIFY(keepBelowChangedSpy.wait());
481 QCOMPARE(keepBelowChangedSpy.count(), 2);
482 QVERIFY(!m_window->isKeepBelow());
483}
484
485void TestWindowManagement::testParentWindow()
486{
487 // this test verifies the functionality of ParentWindows
488 QCOMPARE(m_windowManagement->windows().count(), 1);
489 auto parentWindow = m_windowManagement->windows().first();
490 QVERIFY(parentWindow);
491 QVERIFY(parentWindow->parentWindow().isNull());
492
493 // now let's create a second window
494 QSignalSpy windowAddedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
495 std::unique_ptr<KWin::PlasmaWindowInterface> serverTransient(m_windowManagementInterface->createWindow(this, QUuid::createUuid()));
496 serverTransient->setParentWindow(m_windowInterface);
497 QVERIFY(windowAddedSpy.wait());
498 auto transient = windowAddedSpy.first().first().value<KWayland::Client::PlasmaWindow *>();
499 QCOMPARE(transient->parentWindow().data(), parentWindow);
500
501 // let's unset the parent
502 QSignalSpy parentWindowChangedSpy(transient, &KWayland::Client::PlasmaWindow::parentWindowChanged);
503 serverTransient->setParentWindow(nullptr);
504 QVERIFY(parentWindowChangedSpy.wait());
505 QVERIFY(transient->parentWindow().isNull());
506
507 // and set it again
508 serverTransient->setParentWindow(m_windowInterface);
509 QVERIFY(parentWindowChangedSpy.wait());
510 QCOMPARE(transient->parentWindow().data(), parentWindow);
511
512 // now let's try to unmap the parent
513 m_windowInterface->deleteLater();
514 m_window = nullptr;
515 m_windowInterface = nullptr;
516 QVERIFY(parentWindowChangedSpy.wait());
517 QVERIFY(transient->parentWindow().isNull());
518}
519
520void TestWindowManagement::testGeometry()
521{
522 QVERIFY(m_window);
523 QCOMPARE(m_window->geometry(), QRect());
524 QSignalSpy windowGeometryChangedSpy(m_window, &KWayland::Client::PlasmaWindow::geometryChanged);
525 m_windowInterface->setGeometry(QRect(20, -10, 30, 40));
526 QVERIFY(windowGeometryChangedSpy.wait());
527 QCOMPARE(m_window->geometry(), QRect(20, -10, 30, 40));
528 // setting an empty geometry should not be sent to the client
529 m_windowInterface->setGeometry(QRect());
530 QVERIFY(!windowGeometryChangedSpy.wait(10));
531 // setting to the geometry which the client still has should not trigger signal
532 m_windowInterface->setGeometry(QRect(20, -10, 30, 40));
533 QVERIFY(!windowGeometryChangedSpy.wait(10));
534 // setting another geometry should work, though
535 m_windowInterface->setGeometry(QRect(0, 0, 35, 45));
536 QVERIFY(windowGeometryChangedSpy.wait());
537 QCOMPARE(windowGeometryChangedSpy.count(), 2);
538 QCOMPARE(m_window->geometry(), QRect(0, 0, 35, 45));
539
540 // let's bind a second PlasmaWindowManagement to verify the initial setting
541 std::unique_ptr<KWayland::Client::PlasmaWindowManagement> pm(
542 m_registry->createPlasmaWindowManagement(m_registry->interface(KWayland::Client::Registry::Interface::PlasmaWindowManagement).name,
543 m_registry->interface(KWayland::Client::Registry::Interface::PlasmaWindowManagement).version));
544 QVERIFY(pm != nullptr);
545 QSignalSpy windowAddedSpy(pm.get(), &KWayland::Client::PlasmaWindowManagement::windowCreated);
546 QVERIFY(windowAddedSpy.wait());
547 auto window = pm->windows().first();
548 QCOMPARE(window->geometry(), QRect(0, 0, 35, 45));
549}
550
551void TestWindowManagement::testIcon()
552{
553 // initially, there shouldn't be any icon
554 QSignalSpy iconChangedSpy(m_window, &KWayland::Client::PlasmaWindow::iconChanged);
555 QVERIFY(m_window->icon().isNull());
556
557 // create an icon with a pixmap
558 QImage p(32, 32, QImage::Format_ARGB32_Premultiplied);
559 p.fill(Qt::red);
560 const QIcon dummyIcon(QPixmap::fromImage(p));
561 m_windowInterface->setIcon(dummyIcon);
562 QVERIFY(iconChangedSpy.wait());
563 QCOMPARE(iconChangedSpy.count(), 1);
564 QCOMPARE(m_window->icon().pixmap(32, 32), dummyIcon.pixmap(32, 32));
565
566 // let's set a themed icon
567 m_windowInterface->setIcon(QIcon::fromTheme(QStringLiteral("wayland")));
568 QVERIFY(iconChangedSpy.wait());
569 QCOMPARE(iconChangedSpy.count(), 2);
570 if (!QIcon::hasThemeIcon(QStringLiteral("wayland"))) {
571 QEXPECT_FAIL("", "no wayland icon", Continue);
572 }
573 QCOMPARE(m_window->icon().name(), QStringLiteral("wayland"));
574}
575
576void TestWindowManagement::testPid()
577{
578 QVERIFY(m_window);
579 QVERIFY(m_window->pid() == 1337);
580
581 // test server not setting a PID for whatever reason
582 std::unique_ptr<KWin::PlasmaWindowInterface> newWindowInterface(m_windowManagementInterface->createWindow(this, QUuid::createUuid()));
583 QSignalSpy windowSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
584 QVERIFY(windowSpy.wait());
585 std::unique_ptr<KWayland::Client::PlasmaWindow> newWindow(windowSpy.first().first().value<KWayland::Client::PlasmaWindow *>());
586 QVERIFY(newWindow);
587 QVERIFY(newWindow->pid() == 0);
588}
589
590void TestWindowManagement::testApplicationMenu()
591{
592 const auto serviceName = QStringLiteral("org.kde.foo");
593 const auto objectPath = QStringLiteral("/org/kde/bar");
594
595 m_windowInterface->setApplicationMenuPaths(serviceName, objectPath);
596
597 QSignalSpy applicationMenuChangedSpy(m_window, &KWayland::Client::PlasmaWindow::applicationMenuChanged);
598 QVERIFY(applicationMenuChangedSpy.wait());
599
600 QCOMPARE(m_window->applicationMenuServiceName(), serviceName);
601 QCOMPARE(m_window->applicationMenuObjectPath(), objectPath);
602}
603
605#include "test_wayland_windowmanagement.moc"
The Client class encapsulates a window decoration frame.
void surfaceCreated(KWin::SurfaceInterface *surface)
Class holding the Wayland server display loop.
Definition display.h:34
void dispatchEvents()
Definition display.cpp:116
bool addSocketName(const QString &name=QString())
Definition display.cpp:68
bool isRunning() const
Definition display.cpp:144
bool start()
Definition display.cpp:92
void setApplicationMenuPaths(const QString &serviceName, const QString &objectPath)
void setGeometry(const QRect &geometry)
void setTitle(const QString &title)
QHash< SurfaceInterface *, QRect > minimizedGeometries() const
void setShowingDesktopState(ShowingDesktopState state)
PlasmaWindowInterface * createWindow(QObject *parent, const QUuid &uuid)
Resource representing a wl_surface.
Definition surface.h:80
TestWindowManagement(QObject *parent=nullptr)
Q_DECLARE_METATYPE(KWin::SwitchEvent::State)
QTEST_MAIN(OnScreenNotificationTest)
void(KWin::PlasmaWindowInterface::* ServerWindowSignal)()
void(KWin::PlasmaWindowInterface::* ServerWindowBooleanSignal)(bool)
void(KWayland::Client::PlasmaWindow::* ClientWindowVoidSetter)()