KWin
Loading...
Searching...
No Matches
test_plasma_virtual_desktop.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2018 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"
14
15#include "KWayland/Client/compositor.h"
16#include "KWayland/Client/connection_thread.h"
17#include "KWayland/Client/event_queue.h"
18#include "KWayland/Client/plasmavirtualdesktop.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
24class TestVirtualDesktop : public QObject
25{
26 Q_OBJECT
27public:
28 explicit TestVirtualDesktop(QObject *parent = nullptr);
29private Q_SLOTS:
30 void init();
31 void cleanup();
32
33 void testCreate();
34 void testSetRows();
35 void testConnectNewClient();
36 void testDestroy();
37 void testActivate();
38
39 void testEnterLeaveDesktop();
40 void testAllDesktops();
41 void testCreateRequested();
42 void testRemoveRequested();
43
44private:
45 KWin::Display *m_display;
46 KWin::CompositorInterface *m_compositorInterface;
47 KWin::PlasmaVirtualDesktopManagementInterface *m_plasmaVirtualDesktopManagementInterface;
48 KWin::PlasmaWindowManagementInterface *m_windowManagementInterface;
49 KWin::PlasmaWindowInterface *m_windowInterface;
50
51 KWayland::Client::ConnectionThread *m_connection;
52 KWayland::Client::Compositor *m_compositor;
53 KWayland::Client::PlasmaVirtualDesktopManagement *m_plasmaVirtualDesktopManagement;
54 KWayland::Client::EventQueue *m_queue;
55 KWayland::Client::PlasmaWindowManagement *m_windowManagement;
56 KWayland::Client::PlasmaWindow *m_window;
57
58 QThread *m_thread;
59};
60
61static const QString s_socketName = QStringLiteral("kwayland-test-wayland-virtual-desktop-0");
62
64 : QObject(parent)
65 , m_display(nullptr)
66 , m_compositorInterface(nullptr)
67 , m_connection(nullptr)
68 , m_compositor(nullptr)
69 , m_queue(nullptr)
70 , m_thread(nullptr)
71{
72}
73
74void TestVirtualDesktop::init()
75{
76 using namespace KWin;
77 delete m_display;
78 m_display = new KWin::Display(this);
79 m_display->addSocketName(s_socketName);
80 m_display->start();
81 QVERIFY(m_display->isRunning());
82
83 // setup connection
84 m_connection = new KWayland::Client::ConnectionThread;
85 QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
86 m_connection->setSocketName(s_socketName);
87
88 m_thread = new QThread(this);
89 m_connection->moveToThread(m_thread);
90 m_thread->start();
91
92 m_connection->initConnection();
93 QVERIFY(connectedSpy.wait());
94
95 m_queue = new KWayland::Client::EventQueue(this);
96 QVERIFY(!m_queue->isValid());
97 m_queue->setup(m_connection);
98 QVERIFY(m_queue->isValid());
99
100 KWayland::Client::Registry registry;
101 QSignalSpy compositorSpy(&registry, &KWayland::Client::Registry::compositorAnnounced);
102
103 QSignalSpy plasmaVirtualDesktopManagementSpy(&registry, &KWayland::Client::Registry::plasmaVirtualDesktopManagementAnnounced);
104
105 QSignalSpy windowManagementSpy(&registry, &KWayland::Client::Registry::plasmaWindowManagementAnnounced);
106
107 QVERIFY(!registry.eventQueue());
108 registry.setEventQueue(m_queue);
109 QCOMPARE(registry.eventQueue(), m_queue);
110 registry.create(m_connection->display());
111 QVERIFY(registry.isValid());
112 registry.setup();
113
114 m_compositorInterface = new CompositorInterface(m_display, m_display);
115 QVERIFY(compositorSpy.wait());
116 m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
117
118 m_plasmaVirtualDesktopManagementInterface = new PlasmaVirtualDesktopManagementInterface(m_display, m_display);
119
120 QVERIFY(plasmaVirtualDesktopManagementSpy.wait());
121 m_plasmaVirtualDesktopManagement = registry.createPlasmaVirtualDesktopManagement(plasmaVirtualDesktopManagementSpy.first().first().value<quint32>(),
122 plasmaVirtualDesktopManagementSpy.first().last().value<quint32>(),
123 this);
124
125 m_windowManagementInterface = new PlasmaWindowManagementInterface(m_display, m_display);
126 m_windowManagementInterface->setPlasmaVirtualDesktopManagementInterface(m_plasmaVirtualDesktopManagementInterface);
127
128 QVERIFY(windowManagementSpy.wait());
129 m_windowManagement =
130 registry.createPlasmaWindowManagement(windowManagementSpy.first().first().value<quint32>(), windowManagementSpy.first().last().value<quint32>(), this);
131
132 QSignalSpy windowSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
133 m_windowInterface = m_windowManagementInterface->createWindow(this, QUuid::createUuid());
134 m_windowInterface->setPid(1337);
135
136 QVERIFY(windowSpy.wait());
137 m_window = windowSpy.first().first().value<KWayland::Client::PlasmaWindow *>();
138}
139
140void TestVirtualDesktop::cleanup()
141{
142#define CLEANUP(variable) \
143 if (variable) { \
144 delete variable; \
145 variable = nullptr; \
146 }
147 CLEANUP(m_compositor)
148 CLEANUP(m_plasmaVirtualDesktopManagement)
149 CLEANUP(m_windowInterface)
150 CLEANUP(m_windowManagement)
151 CLEANUP(m_queue)
152 if (m_connection) {
153 m_connection->deleteLater();
154 m_connection = nullptr;
155 }
156 if (m_thread) {
157 m_thread->quit();
158 m_thread->wait();
159 delete m_thread;
160 m_thread = nullptr;
161 }
162 CLEANUP(m_compositorInterface)
163 CLEANUP(m_plasmaVirtualDesktopManagementInterface)
164 CLEANUP(m_windowManagementInterface)
165 CLEANUP(m_display)
166#undef CLEANUP
167}
168
169void TestVirtualDesktop::testCreate()
170{
171 QSignalSpy desktopCreatedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopCreated);
172 QSignalSpy managementDoneSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::done);
173
174 // on this createDesktop bind() isn't called already, the desktopadded signals will be sent after bind happened
175 KWin::PlasmaVirtualDesktopInterface *desktop1Int = m_plasmaVirtualDesktopManagementInterface->createDesktop(QStringLiteral("0-1"));
176 desktop1Int->setName("Desktop 1");
177
178 QVERIFY(desktopCreatedSpy.wait());
179 QList<QVariant> arguments = desktopCreatedSpy.takeFirst();
180 QCOMPARE(arguments.at(0).toString(), QStringLiteral("0-1"));
181 QCOMPARE(arguments.at(1).toUInt(), (quint32)0);
182 m_plasmaVirtualDesktopManagementInterface->sendDone();
183 QVERIFY(managementDoneSpy.wait());
184
185 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 1);
186
187 KWayland::Client::PlasmaVirtualDesktop *desktop1 = m_plasmaVirtualDesktopManagement->desktops().first();
188 QSignalSpy desktop1DoneSpy(desktop1, &KWayland::Client::PlasmaVirtualDesktop::done);
189 desktop1Int->sendDone();
190 QVERIFY(desktop1DoneSpy.wait());
191
192 QCOMPARE(desktop1->id(), QStringLiteral("0-1"));
193 QCOMPARE(desktop1->name(), QStringLiteral("Desktop 1"));
194
195 // on those createDesktop the bind will already be done
196 KWin::PlasmaVirtualDesktopInterface *desktop2Int = m_plasmaVirtualDesktopManagementInterface->createDesktop(QStringLiteral("0-2"));
197 desktop2Int->setName("Desktop 2");
198 QVERIFY(desktopCreatedSpy.wait());
199 arguments = desktopCreatedSpy.takeFirst();
200 QCOMPARE(arguments.at(0).toString(), QStringLiteral("0-2"));
201 QCOMPARE(arguments.at(1).toUInt(), (quint32)1);
202 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 2);
203
204 KWin::PlasmaVirtualDesktopInterface *desktop3Int = m_plasmaVirtualDesktopManagementInterface->createDesktop(QStringLiteral("0-3"));
205 desktop3Int->setName("Desktop 3");
206 QVERIFY(desktopCreatedSpy.wait());
207 arguments = desktopCreatedSpy.takeFirst();
208 QCOMPARE(arguments.at(0).toString(), QStringLiteral("0-3"));
209 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 3);
210
211 m_plasmaVirtualDesktopManagementInterface->sendDone();
212 QVERIFY(managementDoneSpy.wait());
213
214 // get the clients
215 KWayland::Client::PlasmaVirtualDesktop *desktop2 = m_plasmaVirtualDesktopManagement->desktops()[1];
216 QSignalSpy desktop2DoneSpy(desktop2, &KWayland::Client::PlasmaVirtualDesktop::done);
217 desktop2Int->sendDone();
218 QVERIFY(desktop2DoneSpy.wait());
219
220 KWayland::Client::PlasmaVirtualDesktop *desktop3 = m_plasmaVirtualDesktopManagement->desktops()[2];
221 QSignalSpy desktop3DoneSpy(desktop3, &KWayland::Client::PlasmaVirtualDesktop::done);
222 desktop3Int->sendDone();
223 QVERIFY(desktop3DoneSpy.wait());
224
225 QCOMPARE(desktop1->id(), QStringLiteral("0-1"));
226 QCOMPARE(desktop1->name(), QStringLiteral("Desktop 1"));
227
228 QCOMPARE(desktop2->id(), QStringLiteral("0-2"));
229 QCOMPARE(desktop2->name(), QStringLiteral("Desktop 2"));
230
231 QCOMPARE(desktop3->id(), QStringLiteral("0-3"));
232 QCOMPARE(desktop3->name(), QStringLiteral("Desktop 3"));
233
234 // coherence of order between client and server
235 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->desktops().length(), 3);
236 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 3);
237
238 for (int i = 0; i < m_plasmaVirtualDesktopManagement->desktops().length(); ++i) {
239 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->desktops().at(i)->id(), m_plasmaVirtualDesktopManagement->desktops().at(i)->id());
240 }
241}
242
243void TestVirtualDesktop::testSetRows()
244{
245 // rebuild some desktops
246 testCreate();
247
248 QSignalSpy rowsChangedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::rowsChanged);
249
250 m_plasmaVirtualDesktopManagementInterface->setRows(3);
251 QVERIFY(rowsChangedSpy.wait());
252 QCOMPARE(m_plasmaVirtualDesktopManagement->rows(), 3);
253}
254
255void TestVirtualDesktop::testConnectNewClient()
256{
257 // rebuild some desktops
258 testCreate();
259
260 KWayland::Client::Registry registry;
261 QVERIFY(!registry.eventQueue());
262 registry.setEventQueue(m_queue);
263 QCOMPARE(registry.eventQueue(), m_queue);
264 registry.create(m_connection->display());
265 QVERIFY(registry.isValid());
266 registry.setup();
267
268 QSignalSpy plasmaVirtualDesktopManagementSpy(&registry, &KWayland::Client::Registry::plasmaVirtualDesktopManagementAnnounced);
269
270 QVERIFY(plasmaVirtualDesktopManagementSpy.wait());
271
272 KWayland::Client::PlasmaVirtualDesktopManagement *otherPlasmaVirtualDesktopManagement =
273 registry.createPlasmaVirtualDesktopManagement(plasmaVirtualDesktopManagementSpy.first().first().value<quint32>(),
274 plasmaVirtualDesktopManagementSpy.first().last().value<quint32>(),
275 this);
276
277 QSignalSpy managementDoneSpy(otherPlasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::done);
278
279 QVERIFY(managementDoneSpy.wait());
280 QCOMPARE(otherPlasmaVirtualDesktopManagement->desktops().length(), 3);
281
282 delete otherPlasmaVirtualDesktopManagement;
283}
284
285void TestVirtualDesktop::testDestroy()
286{
287 // rebuild some desktops
288 testCreate();
289
290 KWin::PlasmaVirtualDesktopInterface *desktop1Int = m_plasmaVirtualDesktopManagementInterface->desktops().first();
291 KWayland::Client::PlasmaVirtualDesktop *desktop1 = m_plasmaVirtualDesktopManagement->desktops().first();
292
293 QSignalSpy desktop1IntDestroyedSpy(desktop1Int, &QObject::destroyed);
294 QSignalSpy desktop1DestroyedSpy(desktop1, &QObject::destroyed);
295 QSignalSpy desktop1RemovedSpy(desktop1, &KWayland::Client::PlasmaVirtualDesktop::removed);
296 m_plasmaVirtualDesktopManagementInterface->removeDesktop(QStringLiteral("0-1"));
297
298 // test that both server and client desktoip interfaces go away
299 QVERIFY(!desktop1IntDestroyedSpy.isEmpty());
300 QVERIFY(desktop1RemovedSpy.wait());
301 QVERIFY(desktop1DestroyedSpy.wait());
302
303 // coherence of order between client and server
304 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->desktops().length(), 2);
305 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 2);
306
307 for (int i = 0; i < m_plasmaVirtualDesktopManagement->desktops().length(); ++i) {
308 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->desktops().at(i)->id(), m_plasmaVirtualDesktopManagement->desktops().at(i)->id());
309 }
310
311 // Test the desktopRemoved signal of the manager, remove another desktop as the signals can't be tested at the same time
312 QSignalSpy desktopManagerRemovedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopRemoved);
313 m_plasmaVirtualDesktopManagementInterface->removeDesktop(QStringLiteral("0-2"));
314 QVERIFY(desktopManagerRemovedSpy.wait());
315 QCOMPARE(desktopManagerRemovedSpy.takeFirst().at(0).toString(), QStringLiteral("0-2"));
316
317 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->desktops().length(), 1);
318 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 1);
319}
320
321void TestVirtualDesktop::testActivate()
322{
323 // rebuild some desktops
324 testCreate();
325
326 KWin::PlasmaVirtualDesktopInterface *desktop1Int = m_plasmaVirtualDesktopManagementInterface->desktops().first();
327 KWayland::Client::PlasmaVirtualDesktop *desktop1 = m_plasmaVirtualDesktopManagement->desktops().first();
328 QVERIFY(desktop1->isActive());
329 QVERIFY(desktop1Int->isActive());
330
331 KWin::PlasmaVirtualDesktopInterface *desktop2Int = m_plasmaVirtualDesktopManagementInterface->desktops()[1];
332 KWayland::Client::PlasmaVirtualDesktop *desktop2 = m_plasmaVirtualDesktopManagement->desktops()[1];
333 QVERIFY(!desktop2Int->isActive());
334
335 QSignalSpy requestActivateSpy(desktop2Int, &KWin::PlasmaVirtualDesktopInterface::activateRequested);
336 QSignalSpy activatedSpy(desktop2, &KWayland::Client::PlasmaVirtualDesktop::activated);
337
338 desktop2->requestActivate();
339 QVERIFY(requestActivateSpy.wait());
340
341 // This simulates a compositor which supports only one active desktop at a time
342 for (auto *deskInt : m_plasmaVirtualDesktopManagementInterface->desktops()) {
343 if (deskInt->id() == desktop2->id()) {
344 deskInt->setActive(true);
345 } else {
346 deskInt->setActive(false);
347 }
348 }
349 QVERIFY(activatedSpy.wait());
350
351 // correct state in the server
352 QVERIFY(desktop2Int->isActive());
353 QVERIFY(!desktop1Int->isActive());
354 // correct state in the client
355 QVERIFY(desktop2Int->isActive());
356 QVERIFY(!desktop1Int->isActive());
357
358 // Test the deactivated signal
359 QSignalSpy deactivatedSpy(desktop2, &KWayland::Client::PlasmaVirtualDesktop::deactivated);
360
361 for (auto *deskInt : m_plasmaVirtualDesktopManagementInterface->desktops()) {
362 if (deskInt->id() == desktop1->id()) {
363 deskInt->setActive(true);
364 } else {
365 deskInt->setActive(false);
366 }
367 }
368 QVERIFY(deactivatedSpy.wait());
369}
370
371void TestVirtualDesktop::testEnterLeaveDesktop()
372{
373 testCreate();
374
375 QSignalSpy enterRequestedSpy(m_windowInterface, &KWin::PlasmaWindowInterface::enterPlasmaVirtualDesktopRequested);
376 m_window->requestEnterVirtualDesktop(QStringLiteral("0-1"));
377 QVERIFY(enterRequestedSpy.wait());
378
379 QCOMPARE(enterRequestedSpy.takeFirst().at(0).toString(), QStringLiteral("0-1"));
380
381 QSignalSpy virtualDesktopEnteredSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopEntered);
382
383 // agree to the request
384 m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("0-1"));
385 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().length(), 1);
386 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().first(), QStringLiteral("0-1"));
387
388 // check if the client received the enter
389 QVERIFY(virtualDesktopEnteredSpy.wait());
390 QCOMPARE(virtualDesktopEnteredSpy.takeFirst().at(0).toString(), QStringLiteral("0-1"));
391 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 1);
392 QCOMPARE(m_window->plasmaVirtualDesktops().first(), QStringLiteral("0-1"));
393
394 // add another desktop, server side
395 m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("0-3"));
396 QVERIFY(virtualDesktopEnteredSpy.wait());
397 QCOMPARE(virtualDesktopEnteredSpy.takeFirst().at(0).toString(), QStringLiteral("0-3"));
398 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().length(), 2);
399 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 2);
400 QCOMPARE(m_window->plasmaVirtualDesktops()[1], QStringLiteral("0-3"));
401
402 // try to add an invalid desktop
403 m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("invalid"));
404 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 2);
405
406 // remove a desktop
407 QSignalSpy leaveRequestedSpy(m_windowInterface, &KWin::PlasmaWindowInterface::leavePlasmaVirtualDesktopRequested);
408 m_window->requestLeaveVirtualDesktop(QStringLiteral("0-1"));
409 QVERIFY(leaveRequestedSpy.wait());
410
411 QCOMPARE(leaveRequestedSpy.takeFirst().at(0).toString(), QStringLiteral("0-1"));
412
413 QSignalSpy virtualDesktopLeftSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopLeft);
414
415 // agree to the request
416 m_windowInterface->removePlasmaVirtualDesktop(QStringLiteral("0-1"));
417 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().length(), 1);
418 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().first(), QStringLiteral("0-3"));
419
420 // check if the client received the leave
421 QVERIFY(virtualDesktopLeftSpy.wait());
422 QCOMPARE(virtualDesktopLeftSpy.takeFirst().at(0).toString(), QStringLiteral("0-1"));
423 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 1);
424 QCOMPARE(m_window->plasmaVirtualDesktops().first(), QStringLiteral("0-3"));
425
426 // Destroy desktop 2
427 m_plasmaVirtualDesktopManagementInterface->removeDesktop(QStringLiteral("0-3"));
428 // the window should receive a left signal from the destroyed desktop
429 QVERIFY(virtualDesktopLeftSpy.wait());
430
431 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0);
432}
433
434void TestVirtualDesktop::testAllDesktops()
435{
436 testCreate();
437 QSignalSpy virtualDesktopEnteredSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopEntered);
438 QSignalSpy virtualDesktopLeftSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopLeft);
439
440 // in the beginning the window is on desktop 1 and desktop 3
441 m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("0-1"));
442 m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("0-3"));
443 QVERIFY(virtualDesktopEnteredSpy.wait());
444
445 // setting on all desktops
446 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 2);
447 m_windowInterface->setOnAllDesktops(true);
448 // setting on all desktops, the window will leave every desktop
449
450 QVERIFY(virtualDesktopLeftSpy.wait());
451 QCOMPARE(virtualDesktopLeftSpy.count(), 2);
452 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0);
453 QVERIFY(m_window->isOnAllDesktops());
454
455 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0);
456 QVERIFY(m_window->isOnAllDesktops());
457
458 // return to the active desktop (0-1)
459 m_windowInterface->setOnAllDesktops(false);
460 QVERIFY(virtualDesktopEnteredSpy.wait());
461 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 1);
462 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().first(), QStringLiteral("0-1"));
463 QVERIFY(!m_window->isOnAllDesktops());
464}
465
466void TestVirtualDesktop::testCreateRequested()
467{
468 // rebuild some desktops
469 testCreate();
470
471 QSignalSpy desktopCreateRequestedSpy(m_plasmaVirtualDesktopManagementInterface,
473 QSignalSpy desktopCreatedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopCreated);
474
475 // listen for createdRequested
476 m_plasmaVirtualDesktopManagement->requestCreateVirtualDesktop(QStringLiteral("Desktop"), 1);
477 QVERIFY(desktopCreateRequestedSpy.wait());
478 QCOMPARE(desktopCreateRequestedSpy.first().first().toString(), QStringLiteral("Desktop"));
479 QCOMPARE(desktopCreateRequestedSpy.first().at(1).toUInt(), (quint32)1);
480
481 // actually create
482 m_plasmaVirtualDesktopManagementInterface->createDesktop(QStringLiteral("0-4"), 1);
483 KWin::PlasmaVirtualDesktopInterface *desktopInt = m_plasmaVirtualDesktopManagementInterface->desktops().at(1);
484
485 QCOMPARE(desktopInt->id(), QStringLiteral("0-4"));
486 desktopInt->setName(QStringLiteral("Desktop"));
487
488 QVERIFY(desktopCreatedSpy.wait());
489
490 QCOMPARE(desktopCreatedSpy.first().first().toString(), QStringLiteral("0-4"));
491 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().count(), 4);
492
493 KWayland::Client::PlasmaVirtualDesktop *desktop = m_plasmaVirtualDesktopManagement->desktops().at(1);
494 QSignalSpy desktopDoneSpy(desktop, &KWayland::Client::PlasmaVirtualDesktop::done);
495 desktopInt->sendDone();
496 // desktopDoneSpy.wait();
497 // check the order is correct
498 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().at(0)->id(), QStringLiteral("0-1"));
499 QCOMPARE(desktop->id(), QStringLiteral("0-4"));
500 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().at(2)->id(), QStringLiteral("0-2"));
501 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().at(3)->id(), QStringLiteral("0-3"));
502}
503
504void TestVirtualDesktop::testRemoveRequested()
505{
506 // rebuild some desktops
507 testCreate();
508
509 QSignalSpy desktopRemoveRequestedSpy(m_plasmaVirtualDesktopManagementInterface,
511
512 // request a remove, just check the request arrived, ignore the request.
513 m_plasmaVirtualDesktopManagement->requestRemoveVirtualDesktop(QStringLiteral("0-1"));
514 QVERIFY(desktopRemoveRequestedSpy.wait());
515 QCOMPARE(desktopRemoveRequestedSpy.first().first().toString(), QStringLiteral("0-1"));
516}
517
518QTEST_GUILESS_MAIN(TestVirtualDesktop)
519#include "test_plasma_virtual_desktop.moc"
Class holding the Wayland server display loop.
Definition display.h:34
bool addSocketName(const QString &name=QString())
Definition display.cpp:68
bool isRunning() const
Definition display.cpp:144
bool start()
Definition display.cpp:92
Wrapper for the org_kde_plasma_virtual_desktop_management interface.
QList< PlasmaVirtualDesktopInterface * > desktops() const
PlasmaVirtualDesktopInterface * createDesktop(const QString &id, quint32 position=std::numeric_limits< uint32_t >::max())
void desktopCreateRequested(const QString &name, quint32 position)
void desktopRemoveRequested(const QString &id)
void leavePlasmaVirtualDesktopRequested(const QString &desktop)
void removePlasmaVirtualDesktop(const QString &id)
void addPlasmaVirtualDesktop(const QString &id)
void enterPlasmaVirtualDesktopRequested(const QString &desktop)
PlasmaWindowInterface * createWindow(QObject *parent, const QUuid &uuid)
void setPlasmaVirtualDesktopManagementInterface(PlasmaVirtualDesktopManagementInterface *manager)
TestVirtualDesktop(QObject *parent=nullptr)
KWayland::Client::Registry * registry
#define CLEANUP(variable)