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"
35 void testConnectNewClient();
39 void testEnterLeaveDesktop();
40 void testAllDesktops();
41 void testCreateRequested();
42 void testRemoveRequested();
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;
61static const QString s_socketName = QStringLiteral(
"kwayland-test-wayland-virtual-desktop-0");
66 , m_compositorInterface(nullptr)
67 , m_connection(nullptr)
68 , m_compositor(nullptr)
74void TestVirtualDesktop::init()
84 m_connection =
new KWayland::Client::ConnectionThread;
85 QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
86 m_connection->setSocketName(s_socketName);
88 m_thread =
new QThread(
this);
89 m_connection->moveToThread(m_thread);
92 m_connection->initConnection();
93 QVERIFY(connectedSpy.wait());
95 m_queue =
new KWayland::Client::EventQueue(
this);
96 QVERIFY(!m_queue->isValid());
97 m_queue->setup(m_connection);
98 QVERIFY(m_queue->isValid());
100 KWayland::Client::Registry registry;
101 QSignalSpy compositorSpy(®istry, &KWayland::Client::Registry::compositorAnnounced);
103 QSignalSpy plasmaVirtualDesktopManagementSpy(®istry, &KWayland::Client::Registry::plasmaVirtualDesktopManagementAnnounced);
105 QSignalSpy windowManagementSpy(®istry, &KWayland::Client::Registry::plasmaWindowManagementAnnounced);
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());
115 QVERIFY(compositorSpy.wait());
116 m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(),
this);
120 QVERIFY(plasmaVirtualDesktopManagementSpy.wait());
121 m_plasmaVirtualDesktopManagement = registry.createPlasmaVirtualDesktopManagement(plasmaVirtualDesktopManagementSpy.first().first().value<quint32>(),
122 plasmaVirtualDesktopManagementSpy.first().last().value<quint32>(),
128 QVERIFY(windowManagementSpy.wait());
130 registry.createPlasmaWindowManagement(windowManagementSpy.first().first().value<quint32>(), windowManagementSpy.first().last().value<quint32>(),
this);
132 QSignalSpy windowSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
133 m_windowInterface = m_windowManagementInterface->
createWindow(
this, QUuid::createUuid());
134 m_windowInterface->
setPid(1337);
136 QVERIFY(windowSpy.wait());
137 m_window = windowSpy.first().first().value<KWayland::Client::PlasmaWindow *>();
140void TestVirtualDesktop::cleanup()
142#define CLEANUP(variable) \
145 variable = nullptr; \
148 CLEANUP(m_plasmaVirtualDesktopManagement)
153 m_connection->deleteLater();
154 m_connection =
nullptr;
163 CLEANUP(m_plasmaVirtualDesktopManagementInterface)
164 CLEANUP(m_windowManagementInterface)
169void TestVirtualDesktop::testCreate()
171 QSignalSpy desktopCreatedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopCreated);
172 QSignalSpy managementDoneSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::done);
176 desktop1Int->
setName(
"Desktop 1");
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());
185 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 1);
187 KWayland::Client::PlasmaVirtualDesktop *desktop1 = m_plasmaVirtualDesktopManagement->desktops().first();
188 QSignalSpy desktop1DoneSpy(desktop1, &KWayland::Client::PlasmaVirtualDesktop::done);
190 QVERIFY(desktop1DoneSpy.wait());
192 QCOMPARE(desktop1->id(), QStringLiteral(
"0-1"));
193 QCOMPARE(desktop1->name(), QStringLiteral(
"Desktop 1"));
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);
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);
211 m_plasmaVirtualDesktopManagementInterface->
sendDone();
212 QVERIFY(managementDoneSpy.wait());
215 KWayland::Client::PlasmaVirtualDesktop *desktop2 = m_plasmaVirtualDesktopManagement->desktops()[1];
216 QSignalSpy desktop2DoneSpy(desktop2, &KWayland::Client::PlasmaVirtualDesktop::done);
218 QVERIFY(desktop2DoneSpy.wait());
220 KWayland::Client::PlasmaVirtualDesktop *desktop3 = m_plasmaVirtualDesktopManagement->desktops()[2];
221 QSignalSpy desktop3DoneSpy(desktop3, &KWayland::Client::PlasmaVirtualDesktop::done);
223 QVERIFY(desktop3DoneSpy.wait());
225 QCOMPARE(desktop1->id(), QStringLiteral(
"0-1"));
226 QCOMPARE(desktop1->name(), QStringLiteral(
"Desktop 1"));
228 QCOMPARE(desktop2->id(), QStringLiteral(
"0-2"));
229 QCOMPARE(desktop2->name(), QStringLiteral(
"Desktop 2"));
231 QCOMPARE(desktop3->id(), QStringLiteral(
"0-3"));
232 QCOMPARE(desktop3->name(), QStringLiteral(
"Desktop 3"));
235 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->
desktops().length(), 3);
236 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 3);
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());
243void TestVirtualDesktop::testSetRows()
248 QSignalSpy rowsChangedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::rowsChanged);
250 m_plasmaVirtualDesktopManagementInterface->
setRows(3);
251 QVERIFY(rowsChangedSpy.wait());
252 QCOMPARE(m_plasmaVirtualDesktopManagement->rows(), 3);
255void TestVirtualDesktop::testConnectNewClient()
260 KWayland::Client::Registry
registry;
263 QCOMPARE(
registry.eventQueue(), m_queue);
264 registry.create(m_connection->display());
268 QSignalSpy plasmaVirtualDesktopManagementSpy(®istry, &KWayland::Client::Registry::plasmaVirtualDesktopManagementAnnounced);
270 QVERIFY(plasmaVirtualDesktopManagementSpy.wait());
272 KWayland::Client::PlasmaVirtualDesktopManagement *otherPlasmaVirtualDesktopManagement =
273 registry.createPlasmaVirtualDesktopManagement(plasmaVirtualDesktopManagementSpy.first().first().value<quint32>(),
274 plasmaVirtualDesktopManagementSpy.first().last().value<quint32>(),
277 QSignalSpy managementDoneSpy(otherPlasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::done);
279 QVERIFY(managementDoneSpy.wait());
280 QCOMPARE(otherPlasmaVirtualDesktopManagement->desktops().length(), 3);
282 delete otherPlasmaVirtualDesktopManagement;
285void TestVirtualDesktop::testDestroy()
291 KWayland::Client::PlasmaVirtualDesktop *desktop1 = m_plasmaVirtualDesktopManagement->desktops().first();
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"));
299 QVERIFY(!desktop1IntDestroyedSpy.isEmpty());
300 QVERIFY(desktop1RemovedSpy.wait());
301 QVERIFY(desktop1DestroyedSpy.wait());
304 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->
desktops().length(), 2);
305 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 2);
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());
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"));
317 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->
desktops().length(), 1);
318 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 1);
321void TestVirtualDesktop::testActivate()
327 KWayland::Client::PlasmaVirtualDesktop *desktop1 = m_plasmaVirtualDesktopManagement->desktops().first();
328 QVERIFY(desktop1->isActive());
332 KWayland::Client::PlasmaVirtualDesktop *desktop2 = m_plasmaVirtualDesktopManagement->desktops()[1];
336 QSignalSpy activatedSpy(desktop2, &KWayland::Client::PlasmaVirtualDesktop::activated);
338 desktop2->requestActivate();
339 QVERIFY(requestActivateSpy.wait());
342 for (
auto *deskInt : m_plasmaVirtualDesktopManagementInterface->desktops()) {
343 if (deskInt->id() == desktop2->id()) {
344 deskInt->setActive(
true);
346 deskInt->setActive(
false);
349 QVERIFY(activatedSpy.wait());
359 QSignalSpy deactivatedSpy(desktop2, &KWayland::Client::PlasmaVirtualDesktop::deactivated);
361 for (
auto *deskInt : m_plasmaVirtualDesktopManagementInterface->desktops()) {
362 if (deskInt->id() == desktop1->id()) {
363 deskInt->setActive(
true);
365 deskInt->setActive(
false);
368 QVERIFY(deactivatedSpy.wait());
371void TestVirtualDesktop::testEnterLeaveDesktop()
376 m_window->requestEnterVirtualDesktop(QStringLiteral(
"0-1"));
377 QVERIFY(enterRequestedSpy.wait());
379 QCOMPARE(enterRequestedSpy.takeFirst().at(0).toString(), QStringLiteral(
"0-1"));
381 QSignalSpy virtualDesktopEnteredSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopEntered);
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"));
396 QVERIFY(virtualDesktopEnteredSpy.wait());
397 QCOMPARE(virtualDesktopEnteredSpy.takeFirst().at(0).toString(), QStringLiteral(
"0-3"));
399 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 2);
400 QCOMPARE(m_window->plasmaVirtualDesktops()[1], QStringLiteral(
"0-3"));
404 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 2);
408 m_window->requestLeaveVirtualDesktop(QStringLiteral(
"0-1"));
409 QVERIFY(leaveRequestedSpy.wait());
411 QCOMPARE(leaveRequestedSpy.takeFirst().at(0).toString(), QStringLiteral(
"0-1"));
413 QSignalSpy virtualDesktopLeftSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopLeft);
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"));
427 m_plasmaVirtualDesktopManagementInterface->
removeDesktop(QStringLiteral(
"0-3"));
429 QVERIFY(virtualDesktopLeftSpy.wait());
431 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0);
434void TestVirtualDesktop::testAllDesktops()
437 QSignalSpy virtualDesktopEnteredSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopEntered);
438 QSignalSpy virtualDesktopLeftSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopLeft);
443 QVERIFY(virtualDesktopEnteredSpy.wait());
446 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 2);
450 QVERIFY(virtualDesktopLeftSpy.wait());
451 QCOMPARE(virtualDesktopLeftSpy.count(), 2);
452 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0);
453 QVERIFY(m_window->isOnAllDesktops());
455 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0);
456 QVERIFY(m_window->isOnAllDesktops());
460 QVERIFY(virtualDesktopEnteredSpy.wait());
461 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 1);
463 QVERIFY(!m_window->isOnAllDesktops());
466void TestVirtualDesktop::testCreateRequested()
471 QSignalSpy desktopCreateRequestedSpy(m_plasmaVirtualDesktopManagementInterface,
473 QSignalSpy desktopCreatedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopCreated);
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);
482 m_plasmaVirtualDesktopManagementInterface->
createDesktop(QStringLiteral(
"0-4"), 1);
485 QCOMPARE(desktopInt->
id(), QStringLiteral(
"0-4"));
486 desktopInt->
setName(QStringLiteral(
"Desktop"));
488 QVERIFY(desktopCreatedSpy.wait());
490 QCOMPARE(desktopCreatedSpy.first().first().toString(), QStringLiteral(
"0-4"));
491 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().count(), 4);
493 KWayland::Client::PlasmaVirtualDesktop *desktop = m_plasmaVirtualDesktopManagement->desktops().at(1);
494 QSignalSpy desktopDoneSpy(desktop, &KWayland::Client::PlasmaVirtualDesktop::done);
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"));
504void TestVirtualDesktop::testRemoveRequested()
509 QSignalSpy desktopRemoveRequestedSpy(m_plasmaVirtualDesktopManagementInterface,
513 m_plasmaVirtualDesktopManagement->requestRemoveVirtualDesktop(QStringLiteral(
"0-1"));
514 QVERIFY(desktopRemoveRequestedSpy.wait());
515 QCOMPARE(desktopRemoveRequestedSpy.first().first().toString(), QStringLiteral(
"0-1"));
519#include "test_plasma_virtual_desktop.moc"
Class holding the Wayland server display loop.
bool addSocketName(const QString &name=QString())
void setName(const QString &name)
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 setRows(quint32 rows)
void desktopCreateRequested(const QString &name, quint32 position)
void desktopRemoveRequested(const QString &id)
void removeDesktop(const QString &id)
void leavePlasmaVirtualDesktopRequested(const QString &desktop)
void removePlasmaVirtualDesktop(const QString &id)
QStringList plasmaVirtualDesktops() const
void addPlasmaVirtualDesktop(const QString &id)
void enterPlasmaVirtualDesktopRequested(const QString &desktop)
void setOnAllDesktops(bool set)
PlasmaWindowInterface * createWindow(QObject *parent, const QUuid &uuid)
void setPlasmaVirtualDesktopManagementInterface(PlasmaVirtualDesktopManagementInterface *manager)
TestVirtualDesktop(QObject *parent=nullptr)
KWayland::Client::Registry * registry
#define CLEANUP(variable)