17#include "KWayland/Client/compositor.h"
18#include "KWayland/Client/connection_thread.h"
19#include "KWayland/Client/event_queue.h"
20#include "KWayland/Client/registry.h"
21#include "KWayland/Client/surface.h"
23#include "qwayland-wlr-layer-shell-unstable-v1.h"
24#include "qwayland-xdg-shell.h"
94 void testDesiredSize();
96 void testAnchor_data();
99 void testExclusiveZone();
100 void testExclusiveEdge_data();
101 void testExclusiveEdge();
102 void testLayer_data();
107 KWayland::Client::ConnectionThread *m_connection;
108 KWayland::Client::EventQueue *m_queue;
109 KWayland::Client::Compositor *m_clientCompositor;
116 XdgShell *m_clientXdgShell =
nullptr;
120static const QString s_socketName = QStringLiteral(
"kwin-wayland-server-layer-shell-v1-test-0");
122void TestLayerShellV1Interface::initTestCase()
132 m_connection =
new KWayland::Client::ConnectionThread;
133 QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
134 m_connection->setSocketName(s_socketName);
136 m_thread =
new QThread(
this);
137 m_connection->moveToThread(m_thread);
140 m_connection->initConnection();
141 QVERIFY(connectedSpy.wait());
142 QVERIFY(!m_connection->connections().isEmpty());
144 m_queue =
new KWayland::Client::EventQueue(
this);
145 QVERIFY(!m_queue->isValid());
146 m_queue->setup(m_connection);
147 QVERIFY(m_queue->isValid());
149 auto registry =
new KWayland::Client::Registry(
this);
150 connect(registry, &KWayland::Client::Registry::interfaceAnnounced,
this, [
this, registry](
const QByteArray &interface, quint32
id, quint32
version) {
151 if (interface == QByteArrayLiteral(
"zwlr_layer_shell_v1")) {
153 m_clientLayerShell->init(*registry,
id,
version);
155 if (interface == QByteArrayLiteral(
"xdg_wm_base")) {
157 m_clientXdgShell->init(*registry,
id,
version);
160 QSignalSpy allAnnouncedSpy(registry, &KWayland::Client::Registry::interfaceAnnounced);
161 QSignalSpy compositorSpy(registry, &KWayland::Client::Registry::compositorAnnounced);
162 QSignalSpy shmSpy(registry, &KWayland::Client::Registry::shmAnnounced);
164 registry->create(m_connection->display());
167 QVERIFY(allAnnouncedSpy.wait());
169 m_clientCompositor =
registry->createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(),
this);
170 QVERIFY(m_clientCompositor->isValid());
175 if (m_clientXdgShell) {
176 delete m_clientXdgShell;
177 m_clientXdgShell =
nullptr;
179 if (m_clientLayerShell) {
180 delete m_clientLayerShell;
181 m_clientLayerShell =
nullptr;
193 m_connection->deleteLater();
194 m_connection =
nullptr;
197void TestLayerShellV1Interface::testDesiredSize()
201 std::unique_ptr<KWayland::Client::Surface> clientSurface(m_clientCompositor->createSurface(
this));
202 QVERIFY(serverSurfaceCreatedSpy.wait());
204 QVERIFY(serverSurface);
207 std::unique_ptr<LayerSurfaceV1> clientShellSurface(
new LayerSurfaceV1);
208 clientShellSurface->init(m_clientLayerShell->get_layer_surface(*clientSurface,
nullptr, LayerShellV1::layer_top, QStringLiteral(
"test")));
210 QVERIFY(layerSurfaceCreatedSpy.wait());
212 QVERIFY(serverShellSurface);
214 clientShellSurface->set_size(10, 20);
215 clientSurface->commit(KWayland::Client::Surface::CommitFlag::None);
218 QVERIFY(desiredSizeChangedSpy.wait());
220 QCOMPARE(serverShellSurface->desiredSize(), QSize(10, 20));
223void TestLayerShellV1Interface::testScope()
227 std::unique_ptr<KWayland::Client::Surface> clientSurface(m_clientCompositor->createSurface(
this));
228 QVERIFY(serverSurfaceCreatedSpy.wait());
230 QVERIFY(serverSurface);
233 std::unique_ptr<LayerSurfaceV1> clientShellSurface(
new LayerSurfaceV1);
234 clientShellSurface->init(m_clientLayerShell->get_layer_surface(*clientSurface,
nullptr, LayerShellV1::layer_top, QStringLiteral(
"foobar")));
235 clientShellSurface->set_size(100, 50);
237 QVERIFY(layerSurfaceCreatedSpy.wait());
239 QVERIFY(serverShellSurface);
241 QCOMPARE(serverShellSurface->scope(), QStringLiteral(
"foobar"));
244void TestLayerShellV1Interface::testAnchor_data()
246 QTest::addColumn<int>(
"anchor");
247 QTest::addColumn<Qt::Edge>(
"expected");
249 QTest::addRow(
"left") << int(QtWayland::zwlr_layer_surface_v1::anchor_left) << Qt::LeftEdge;
250 QTest::addRow(
"right") << int(QtWayland::zwlr_layer_surface_v1::anchor_right) << Qt::RightEdge;
251 QTest::addRow(
"top") << int(QtWayland::zwlr_layer_surface_v1::anchor_top) << Qt::TopEdge;
252 QTest::addRow(
"bottom") << int(QtWayland::zwlr_layer_surface_v1::anchor_bottom) << Qt::BottomEdge;
255void TestLayerShellV1Interface::testAnchor()
259 std::unique_ptr<KWayland::Client::Surface> clientSurface(m_clientCompositor->createSurface(
this));
260 QVERIFY(serverSurfaceCreatedSpy.wait());
262 QVERIFY(serverSurface);
265 std::unique_ptr<LayerSurfaceV1> clientShellSurface(
new LayerSurfaceV1);
266 clientShellSurface->init(m_clientLayerShell->get_layer_surface(*clientSurface,
nullptr, LayerShellV1::layer_top, QStringLiteral(
"test")));
268 QVERIFY(layerSurfaceCreatedSpy.wait());
270 QVERIFY(serverShellSurface);
273 QFETCH(Qt::Edge, expected);
275 clientShellSurface->set_anchor(anchor);
276 clientShellSurface->set_size(100, 50);
277 clientSurface->commit(KWayland::Client::Surface::CommitFlag::None);
280 QVERIFY(anchorChangedSpy.wait());
282 QCOMPARE(serverShellSurface->anchor(), expected);
285void TestLayerShellV1Interface::testMargins()
289 std::unique_ptr<KWayland::Client::Surface> clientSurface(m_clientCompositor->createSurface(
this));
290 QVERIFY(serverSurfaceCreatedSpy.wait());
292 QVERIFY(serverSurface);
295 std::unique_ptr<LayerSurfaceV1> clientShellSurface(
new LayerSurfaceV1);
296 clientShellSurface->init(m_clientLayerShell->get_layer_surface(*clientSurface,
nullptr, LayerShellV1::layer_top, QStringLiteral(
"test")));
298 QVERIFY(layerSurfaceCreatedSpy.wait());
300 QVERIFY(serverShellSurface);
302 clientShellSurface->set_margin(10, 20, 30, 40);
303 clientShellSurface->set_size(100, 50);
304 clientSurface->commit(KWayland::Client::Surface::CommitFlag::None);
307 QVERIFY(marginsChangedSpy.wait());
309 QCOMPARE(serverShellSurface->margins(), QMargins(40, 10, 20, 30));
312void TestLayerShellV1Interface::testExclusiveZone()
316 std::unique_ptr<KWayland::Client::Surface> clientSurface(m_clientCompositor->createSurface(
this));
317 QVERIFY(serverSurfaceCreatedSpy.wait());
319 QVERIFY(serverSurface);
322 std::unique_ptr<LayerSurfaceV1> clientShellSurface(
new LayerSurfaceV1);
323 clientShellSurface->init(m_clientLayerShell->get_layer_surface(*clientSurface,
nullptr, LayerShellV1::layer_top, QStringLiteral(
"test")));
325 QVERIFY(layerSurfaceCreatedSpy.wait());
327 QVERIFY(serverShellSurface);
329 clientShellSurface->set_exclusive_zone(10);
330 clientShellSurface->set_size(100, 50);
331 clientSurface->commit(KWayland::Client::Surface::CommitFlag::None);
334 QVERIFY(exclusiveZoneChangedSpy.wait());
336 QCOMPARE(serverShellSurface->exclusiveZone(), 10);
339void TestLayerShellV1Interface::testExclusiveEdge_data()
341 QTest::addColumn<int>(
"anchor");
342 QTest::addColumn<Qt::Edge>(
"expected");
344 QTest::addRow(
"left (singular)") << int(QtWayland::zwlr_layer_surface_v1::anchor_left) << Qt::LeftEdge;
346 QTest::addRow(
"left (triplet)") << (QtWayland::zwlr_layer_surface_v1::anchor_bottom | QtWayland::zwlr_layer_surface_v1::anchor_left
347 | QtWayland::zwlr_layer_surface_v1::anchor_top)
350 QTest::addRow(
"right (singular)") << int(QtWayland::zwlr_layer_surface_v1::anchor_right) << Qt::RightEdge;
352 QTest::addRow(
"right (triplet)") << (QtWayland::zwlr_layer_surface_v1::anchor_top | QtWayland::zwlr_layer_surface_v1::anchor_right
353 | QtWayland::zwlr_layer_surface_v1::anchor_bottom)
356 QTest::addRow(
"top (singular)") << int(QtWayland::zwlr_layer_surface_v1::anchor_top) << Qt::TopEdge;
358 QTest::addRow(
"top (triplet)") << (QtWayland::zwlr_layer_surface_v1::anchor_left | QtWayland::zwlr_layer_surface_v1::anchor_top
359 | QtWayland::zwlr_layer_surface_v1::anchor_right)
362 QTest::addRow(
"bottom (singular)") << int(QtWayland::zwlr_layer_surface_v1::anchor_bottom) << Qt::BottomEdge;
364 QTest::addRow(
"bottom (triplet)") << (QtWayland::zwlr_layer_surface_v1::anchor_right | QtWayland::zwlr_layer_surface_v1::anchor_bottom
365 | QtWayland::zwlr_layer_surface_v1::anchor_left)
368 QTest::addRow(
"all") << (QtWayland::zwlr_layer_surface_v1::anchor_left | QtWayland::zwlr_layer_surface_v1::anchor_right
369 | QtWayland::zwlr_layer_surface_v1::anchor_top | QtWayland::zwlr_layer_surface_v1::anchor_bottom)
373void TestLayerShellV1Interface::testExclusiveEdge()
377 std::unique_ptr<KWayland::Client::Surface> clientSurface(m_clientCompositor->createSurface(
this));
378 QVERIFY(serverSurfaceCreatedSpy.wait());
380 QVERIFY(serverSurface);
383 std::unique_ptr<LayerSurfaceV1> clientShellSurface(
new LayerSurfaceV1);
384 clientShellSurface->init(m_clientLayerShell->get_layer_surface(*clientSurface,
nullptr, LayerShellV1::layer_top, QStringLiteral(
"test")));
386 QVERIFY(layerSurfaceCreatedSpy.wait());
388 QVERIFY(serverShellSurface);
391 QFETCH(Qt::Edge, expected);
393 clientShellSurface->set_exclusive_zone(10);
394 clientShellSurface->set_size(100, 50);
395 clientShellSurface->set_anchor(anchor);
396 clientSurface->commit(KWayland::Client::Surface::CommitFlag::None);
399 QVERIFY(anchorChangedSpy.wait());
401 QCOMPARE(serverShellSurface->exclusiveEdge(), expected);
404void TestLayerShellV1Interface::testLayer_data()
406 QTest::addColumn<int>(
"layer");
407 QTest::addColumn<LayerSurfaceV1Interface::Layer>(
"expected");
415void TestLayerShellV1Interface::testLayer()
419 std::unique_ptr<KWayland::Client::Surface> clientSurface(m_clientCompositor->createSurface(
this));
420 QVERIFY(serverSurfaceCreatedSpy.wait());
422 QVERIFY(serverSurface);
425 std::unique_ptr<LayerSurfaceV1> clientShellSurface(
new LayerSurfaceV1);
426 clientShellSurface->init(m_clientLayerShell->get_layer_surface(*clientSurface,
nullptr, LayerShellV1::layer_top, QStringLiteral(
"test")));
428 QVERIFY(layerSurfaceCreatedSpy.wait());
430 QVERIFY(serverShellSurface);
435 clientShellSurface->set_layer(layer);
436 clientShellSurface->set_size(100, 50);
437 clientSurface->commit(KWayland::Client::Surface::CommitFlag::None);
440 QVERIFY(committedSpy.wait());
442 QCOMPARE(serverShellSurface->layer(), expected);
445void TestLayerShellV1Interface::testPopup()
449 std::unique_ptr<KWayland::Client::Surface> clientPanelSurface(m_clientCompositor->createSurface(
this));
450 QVERIFY(serverPanelSurfaceCreatedSpy.wait());
452 QVERIFY(serverPanelSurface);
455 std::unique_ptr<LayerSurfaceV1> clientPanelShellSurface(
new LayerSurfaceV1);
456 clientPanelShellSurface->init(m_clientLayerShell->get_layer_surface(*clientPanelSurface,
nullptr, LayerShellV1::layer_top, QStringLiteral(
"panel")));
457 clientPanelShellSurface->set_size(100, 50);
459 QVERIFY(layerSurfaceCreatedSpy.wait());
461 QVERIFY(serverPanelShellSurface);
464 std::unique_ptr<KWayland::Client::Surface> clientPopupSurface(m_clientCompositor->createSurface(
this));
465 QVERIFY(serverPanelSurfaceCreatedSpy.wait());
467 QVERIFY(serverPopupSurface);
470 std::unique_ptr<XdgSurface> clientXdgSurface(
new XdgSurface);
471 clientXdgSurface->init(m_clientXdgShell->get_xdg_surface(*clientPopupSurface));
474 std::unique_ptr<::XdgPositioner> positioner(new ::XdgPositioner);
475 positioner->init(m_clientXdgShell->create_positioner());
476 positioner->set_size(100, 100);
477 positioner->set_anchor_rect(0, 0, 10, 10);
480 std::unique_ptr<XdgPopup> clientXdgPopup(
new XdgPopup);
481 clientXdgPopup->init(clientXdgSurface->get_popup(
nullptr, positioner->object()));
485 QVERIFY(popupCreatedSpy.wait());
487 QVERIFY(serverPopupShellSurface);
491 clientPanelShellSurface->get_popup(clientXdgPopup->object());
494 clientPopupSurface->commit(KWayland::Client::Surface::CommitFlag::None);
496 QVERIFY(initializeRequestedSpy.wait());
499 QCOMPARE(serverPopupShellSurface->
parentSurface(), serverPanelSurface);
504#include "test_layershellv1_interface.moc"
void surfaceCreated(KWin::SurfaceInterface *surface)
Class holding the Wayland server display loop.
bool addSocketName(const QString &name=QString())
void surfaceCreated(LayerSurfaceV1Interface *surface)
void desiredSizeChanged()
void exclusiveZoneChanged()
Resource representing a wl_surface.
void popupCreated(XdgPopupInterface *popup)
~LayerSurfaceV1() override
~TestLayerShellV1Interface() override
KWayland::Client::Registry * registry