File indexing completed on 2024-05-05 17:35:50

0001 /*
0002     SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kwin_wayland_test.h"
0008 
0009 #include "core/output.h"
0010 #include "core/outputbackend.h"
0011 #include "main.h"
0012 #include "wayland_server.h"
0013 #include "window.h"
0014 #include "workspace.h"
0015 
0016 #include <KWayland/Client/output.h>
0017 #include <KWayland/Client/surface.h>
0018 
0019 Q_DECLARE_METATYPE(QMargins)
0020 Q_DECLARE_METATYPE(KWin::Layer)
0021 
0022 namespace KWin
0023 {
0024 
0025 static const QString s_socketName = QStringLiteral("wayland_test_kwin_layershellv1window-0");
0026 
0027 class LayerShellV1WindowTest : public QObject
0028 {
0029     Q_OBJECT
0030 
0031 private Q_SLOTS:
0032     void initTestCase();
0033     void init();
0034     void cleanup();
0035     void testOutput_data();
0036     void testOutput();
0037     void testAnchor_data();
0038     void testAnchor();
0039     void testMargins_data();
0040     void testMargins();
0041     void testLayer_data();
0042     void testLayer();
0043     void testPlacementArea_data();
0044     void testPlacementArea();
0045     void testFill_data();
0046     void testFill();
0047     void testStack();
0048     void testFocus();
0049     void testActivate_data();
0050     void testActivate();
0051     void testUnmap();
0052 };
0053 
0054 void LayerShellV1WindowTest::initTestCase()
0055 {
0056     QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
0057     QVERIFY(waylandServer()->init(s_socketName));
0058     QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024)));
0059 
0060     kwinApp()->start();
0061     QVERIFY(applicationStartedSpy.wait());
0062     const auto outputs = workspace()->outputs();
0063     QCOMPARE(outputs.count(), 2);
0064     QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
0065     QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
0066 }
0067 
0068 void LayerShellV1WindowTest::init()
0069 {
0070     QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::LayerShellV1));
0071 
0072     workspace()->setActiveOutput(QPoint(640, 512));
0073     Cursors::self()->mouse()->setPos(QPoint(640, 512));
0074 }
0075 
0076 void LayerShellV1WindowTest::cleanup()
0077 {
0078     Test::destroyWaylandConnection();
0079 }
0080 
0081 void LayerShellV1WindowTest::testOutput_data()
0082 {
0083     QTest::addColumn<int>("screenId");
0084 
0085     QTest::addRow("first output") << 0;
0086     QTest::addRow("second output") << 1;
0087 }
0088 
0089 void LayerShellV1WindowTest::testOutput()
0090 {
0091     // Fetch the wl_output object.
0092     QFETCH(int, screenId);
0093     KWayland::Client::Output *output = Test::waylandOutputs().value(screenId);
0094     QVERIFY(output);
0095 
0096     // Create a layer shell surface.
0097     std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
0098     std::unique_ptr<Test::LayerSurfaceV1> shellSurface(Test::createLayerSurfaceV1(surface.get(), QStringLiteral("test"), output));
0099 
0100     // Set the initial state of the layer surface.
0101     shellSurface->set_size(280, 124);
0102     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0103 
0104     // Wait for the compositor to position the surface.
0105     QSignalSpy configureRequestedSpy(shellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
0106     QVERIFY(configureRequestedSpy.wait());
0107     const QSize requestedSize = configureRequestedSpy.last().at(1).toSize();
0108 
0109     // Map the layer surface.
0110     shellSurface->ack_configure(configureRequestedSpy.last().at(0).toUInt());
0111     Window *window = Test::renderAndWaitForShown(surface.get(), requestedSize, Qt::red);
0112     QVERIFY(window);
0113 
0114     // Verify that the window is on the requested screen.
0115     QVERIFY(output->geometry().contains(window->frameGeometry().toRect()));
0116 
0117     // Destroy the window.
0118     shellSurface.reset();
0119     QVERIFY(Test::waitForWindowDestroyed(window));
0120 }
0121 
0122 void LayerShellV1WindowTest::testAnchor_data()
0123 {
0124     QTest::addColumn<int>("anchor");
0125     QTest::addColumn<QRectF>("expectedGeometry");
0126 
0127     QTest::addRow("left") << int(Test::LayerSurfaceV1::anchor_left)
0128                           << QRectF(0, 450, 280, 124);
0129 
0130     QTest::addRow("top left") << (Test::LayerSurfaceV1::anchor_top | Test::LayerSurfaceV1::anchor_left)
0131                               << QRectF(0, 0, 280, 124);
0132 
0133     QTest::addRow("top") << int(Test::LayerSurfaceV1::anchor_top)
0134                          << QRectF(500, 0, 280, 124);
0135 
0136     QTest::addRow("top right") << (Test::LayerSurfaceV1::anchor_top | Test::LayerSurfaceV1::anchor_right)
0137                                << QRectF(1000, 0, 280, 124);
0138 
0139     QTest::addRow("right") << int(Test::LayerSurfaceV1::anchor_right)
0140                            << QRectF(1000, 450, 280, 124);
0141 
0142     QTest::addRow("bottom right") << (Test::LayerSurfaceV1::anchor_bottom | Test::LayerSurfaceV1::anchor_right)
0143                                   << QRectF(1000, 900, 280, 124);
0144 
0145     QTest::addRow("bottom") << int(Test::LayerSurfaceV1::anchor_bottom)
0146                             << QRectF(500, 900, 280, 124);
0147 
0148     QTest::addRow("bottom left") << (Test::LayerSurfaceV1::anchor_bottom | Test::LayerSurfaceV1::anchor_left)
0149                                  << QRectF(0, 900, 280, 124);
0150 }
0151 
0152 void LayerShellV1WindowTest::testAnchor()
0153 {
0154     // Create a layer shell surface.
0155     std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
0156     std::unique_ptr<Test::LayerSurfaceV1> shellSurface(Test::createLayerSurfaceV1(surface.get(), QStringLiteral("test")));
0157 
0158     // Set the initial state of the layer surface.
0159     QFETCH(int, anchor);
0160     shellSurface->set_anchor(anchor);
0161     shellSurface->set_size(280, 124);
0162     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0163 
0164     // Wait for the compositor to position the surface.
0165     QSignalSpy configureRequestedSpy(shellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
0166     QVERIFY(configureRequestedSpy.wait());
0167     const QSize requestedSize = configureRequestedSpy.last().at(1).toSize();
0168     QCOMPARE(requestedSize, QSize(280, 124));
0169 
0170     // Map the layer surface.
0171     shellSurface->ack_configure(configureRequestedSpy.last().at(0).toUInt());
0172     Window *window = Test::renderAndWaitForShown(surface.get(), QSize(280, 124), Qt::red);
0173     QVERIFY(window);
0174 
0175     // Verify that the window is placed at expected location.
0176     QTEST(window->frameGeometry(), "expectedGeometry");
0177 
0178     // Destroy the window.
0179     shellSurface.reset();
0180     QVERIFY(Test::waitForWindowDestroyed(window));
0181 }
0182 
0183 void LayerShellV1WindowTest::testMargins_data()
0184 {
0185     QTest::addColumn<int>("anchor");
0186     QTest::addColumn<QMargins>("margins");
0187     QTest::addColumn<QRectF>("expectedGeometry");
0188 
0189     QTest::addRow("left") << int(Test::LayerSurfaceV1::anchor_left)
0190                           << QMargins(100, 0, 0, 0)
0191                           << QRectF(100, 450, 280, 124);
0192 
0193     QTest::addRow("top left") << (Test::LayerSurfaceV1::anchor_top | Test::LayerSurfaceV1::anchor_left)
0194                               << QMargins(100, 200, 0, 0)
0195                               << QRectF(100, 200, 280, 124);
0196 
0197     QTest::addRow("top") << int(Test::LayerSurfaceV1::anchor_top)
0198                          << QMargins(0, 200, 0, 0)
0199                          << QRectF(500, 200, 280, 124);
0200 
0201     QTest::addRow("top right") << (Test::LayerSurfaceV1::anchor_top | Test::LayerSurfaceV1::anchor_right)
0202                                << QMargins(0, 200, 300, 0)
0203                                << QRectF(700, 200, 280, 124);
0204 
0205     QTest::addRow("right") << int(Test::LayerSurfaceV1::anchor_right)
0206                            << QMargins(0, 0, 300, 0)
0207                            << QRectF(700, 450, 280, 124);
0208 
0209     QTest::addRow("bottom right") << (Test::LayerSurfaceV1::anchor_bottom | Test::LayerSurfaceV1::anchor_right)
0210                                   << QMargins(0, 0, 300, 400)
0211                                   << QRectF(700, 500, 280, 124);
0212 
0213     QTest::addRow("bottom") << int(Test::LayerSurfaceV1::anchor_bottom)
0214                             << QMargins(0, 0, 0, 400)
0215                             << QRectF(500, 500, 280, 124);
0216 
0217     QTest::addRow("bottom left") << (Test::LayerSurfaceV1::anchor_bottom | Test::LayerSurfaceV1::anchor_left)
0218                                  << QMargins(100, 0, 0, 400)
0219                                  << QRectF(100, 500, 280, 124);
0220 }
0221 
0222 void LayerShellV1WindowTest::testMargins()
0223 {
0224     // Create a layer shell surface.
0225     std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
0226     std::unique_ptr<Test::LayerSurfaceV1> shellSurface(Test::createLayerSurfaceV1(surface.get(), QStringLiteral("test")));
0227 
0228     // Set the initial state of the layer surface.
0229     QFETCH(QMargins, margins);
0230     QFETCH(int, anchor);
0231     shellSurface->set_anchor(anchor);
0232     shellSurface->set_margin(margins.top(), margins.right(), margins.bottom(), margins.left());
0233     shellSurface->set_size(280, 124);
0234     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0235 
0236     // Wait for the compositor to position the surface.
0237     QSignalSpy configureRequestedSpy(shellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
0238     QVERIFY(configureRequestedSpy.wait());
0239     const QSize requestedSize = configureRequestedSpy.last().at(1).toSize();
0240 
0241     // Map the layer surface.
0242     shellSurface->ack_configure(configureRequestedSpy.last().at(0).toUInt());
0243     Window *window = Test::renderAndWaitForShown(surface.get(), requestedSize, Qt::red);
0244     QVERIFY(window);
0245 
0246     // Verify that the window is placed at expected location.
0247     QTEST(window->frameGeometry(), "expectedGeometry");
0248 
0249     // Destroy the window.
0250     shellSurface.reset();
0251     QVERIFY(Test::waitForWindowDestroyed(window));
0252 }
0253 
0254 void LayerShellV1WindowTest::testLayer_data()
0255 {
0256     QTest::addColumn<int>("protocolLayer");
0257     QTest::addColumn<Layer>("compositorLayer");
0258 
0259     QTest::addRow("overlay") << int(Test::LayerShellV1::layer_overlay) << UnmanagedLayer;
0260     QTest::addRow("top") << int(Test::LayerShellV1::layer_top) << AboveLayer;
0261     QTest::addRow("bottom") << int(Test::LayerShellV1::layer_bottom) << BelowLayer;
0262     QTest::addRow("background") << int(Test::LayerShellV1::layer_background) << DesktopLayer;
0263 }
0264 
0265 void LayerShellV1WindowTest::testLayer()
0266 {
0267     // Create a layer shell surface.
0268     std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
0269     std::unique_ptr<Test::LayerSurfaceV1> shellSurface(Test::createLayerSurfaceV1(surface.get(), QStringLiteral("test")));
0270 
0271     // Set the initial state of the layer surface.
0272     QFETCH(int, protocolLayer);
0273     shellSurface->set_layer(protocolLayer);
0274     shellSurface->set_size(280, 124);
0275     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0276 
0277     // Wait for the compositor to position the surface.
0278     QSignalSpy configureRequestedSpy(shellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
0279     QVERIFY(configureRequestedSpy.wait());
0280     const QSize requestedSize = configureRequestedSpy.last().at(1).toSize();
0281 
0282     // Map the layer surface.
0283     shellSurface->ack_configure(configureRequestedSpy.last().at(0).toUInt());
0284     Window *window = Test::renderAndWaitForShown(surface.get(), requestedSize, Qt::red);
0285     QVERIFY(window);
0286 
0287     // Verify that the window is placed at expected location.
0288     QTEST(window->layer(), "compositorLayer");
0289 
0290     // Destroy the window.
0291     shellSurface.reset();
0292     QVERIFY(Test::waitForWindowDestroyed(window));
0293 }
0294 
0295 void LayerShellV1WindowTest::testPlacementArea_data()
0296 {
0297     QTest::addColumn<int>("anchor");
0298     QTest::addColumn<int>("exclusiveZone");
0299     QTest::addColumn<QRectF>("placementArea");
0300 
0301     QTest::addRow("left") << int(Test::LayerSurfaceV1::anchor_left) << 300 << QRectF(300, 0, 980, 1024);
0302     QTest::addRow("top") << int(Test::LayerSurfaceV1::anchor_top) << 300 << QRectF(0, 300, 1280, 724);
0303     QTest::addRow("right") << int(Test::LayerSurfaceV1::anchor_right) << 300 << QRectF(0, 0, 980, 1024);
0304     QTest::addRow("bottom") << int(Test::LayerSurfaceV1::anchor_bottom) << 300 << QRectF(0, 0, 1280, 724);
0305 }
0306 
0307 void LayerShellV1WindowTest::testPlacementArea()
0308 {
0309     // Create a layer shell surface.
0310     std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
0311     std::unique_ptr<Test::LayerSurfaceV1> shellSurface(Test::createLayerSurfaceV1(surface.get(), QStringLiteral("test")));
0312 
0313     // Set the initial state of the layer surface.
0314     QFETCH(int, anchor);
0315     QFETCH(int, exclusiveZone);
0316     shellSurface->set_anchor(anchor);
0317     shellSurface->set_exclusive_zone(exclusiveZone);
0318     shellSurface->set_size(280, 124);
0319     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0320 
0321     // Wait for the compositor to position the surface.
0322     QSignalSpy configureRequestedSpy(shellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
0323     QVERIFY(configureRequestedSpy.wait());
0324     const QSize requestedSize = configureRequestedSpy.last().at(1).toSize();
0325 
0326     // Map the layer surface.
0327     shellSurface->ack_configure(configureRequestedSpy.last().at(0).toUInt());
0328     Window *window = Test::renderAndWaitForShown(surface.get(), requestedSize, Qt::red);
0329     QVERIFY(window);
0330 
0331     // Verify that the work area has been adjusted.
0332     QTEST(workspace()->clientArea(PlacementArea, window), "placementArea");
0333 
0334     // Destroy the window.
0335     shellSurface.reset();
0336     QVERIFY(Test::waitForWindowDestroyed(window));
0337 }
0338 
0339 void LayerShellV1WindowTest::testFill_data()
0340 {
0341     QTest::addColumn<int>("anchor");
0342     QTest::addColumn<QSize>("desiredSize");
0343     QTest::addColumn<QRectF>("expectedGeometry");
0344 
0345     QTest::addRow("horizontal") << (Test::LayerSurfaceV1::anchor_left | Test::LayerSurfaceV1::anchor_right)
0346                                 << QSize(0, 124)
0347                                 << QRectF(0, 450, 1280, 124);
0348 
0349     QTest::addRow("vertical") << (Test::LayerSurfaceV1::anchor_top | Test::LayerSurfaceV1::anchor_bottom)
0350                               << QSize(280, 0)
0351                               << QRectF(500, 0, 280, 1024);
0352 
0353     QTest::addRow("all") << (Test::LayerSurfaceV1::anchor_left | Test::LayerSurfaceV1::anchor_top | Test::LayerSurfaceV1::anchor_right | Test::LayerSurfaceV1::anchor_bottom)
0354                          << QSize(0, 0)
0355                          << QRectF(0, 0, 1280, 1024);
0356 }
0357 
0358 void LayerShellV1WindowTest::testFill()
0359 {
0360     // Create a layer shell surface.
0361     std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
0362     std::unique_ptr<Test::LayerSurfaceV1> shellSurface(Test::createLayerSurfaceV1(surface.get(), QStringLiteral("test")));
0363 
0364     // Set the initial state of the layer surface.
0365     QFETCH(int, anchor);
0366     QFETCH(QSize, desiredSize);
0367     shellSurface->set_anchor(anchor);
0368     shellSurface->set_size(desiredSize.width(), desiredSize.height());
0369     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0370 
0371     // Wait for the compositor to position the surface.
0372     QSignalSpy configureRequestedSpy(shellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
0373     QVERIFY(configureRequestedSpy.wait());
0374     const QSize requestedSize = configureRequestedSpy.last().at(1).toSize();
0375 
0376     // Map the layer surface.
0377     shellSurface->ack_configure(configureRequestedSpy.last().at(0).toUInt());
0378     Window *window = Test::renderAndWaitForShown(surface.get(), requestedSize, Qt::red);
0379     QVERIFY(window);
0380 
0381     // Verify that the window is placed at expected location.
0382     QTEST(window->frameGeometry(), "expectedGeometry");
0383 
0384     // Destroy the window.
0385     shellSurface.reset();
0386     QVERIFY(Test::waitForWindowDestroyed(window));
0387 }
0388 
0389 void LayerShellV1WindowTest::testStack()
0390 {
0391     // Create a layer shell surface.
0392     std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
0393     std::unique_ptr<Test::LayerSurfaceV1> shellSurface1(Test::createLayerSurfaceV1(surface1.get(), QStringLiteral("test")));
0394 
0395     std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
0396     std::unique_ptr<Test::LayerSurfaceV1> shellSurface2(Test::createLayerSurfaceV1(surface2.get(), QStringLiteral("test")));
0397 
0398     // Set the initial state of the layer surface.
0399     shellSurface1->set_anchor(Test::LayerSurfaceV1::anchor_left);
0400     shellSurface1->set_size(80, 124);
0401     shellSurface1->set_exclusive_zone(80);
0402     surface1->commit(KWayland::Client::Surface::CommitFlag::None);
0403 
0404     shellSurface2->set_anchor(Test::LayerSurfaceV1::anchor_left);
0405     shellSurface2->set_size(200, 124);
0406     shellSurface2->set_exclusive_zone(200);
0407     surface2->commit(KWayland::Client::Surface::CommitFlag::None);
0408 
0409     // Wait for the compositor to position the surfaces.
0410     QSignalSpy configureRequestedSpy1(shellSurface1.get(), &Test::LayerSurfaceV1::configureRequested);
0411     QSignalSpy configureRequestedSpy2(shellSurface2.get(), &Test::LayerSurfaceV1::configureRequested);
0412     QVERIFY(configureRequestedSpy2.wait());
0413     const QSize requestedSize1 = configureRequestedSpy1.last().at(1).toSize();
0414     const QSize requestedSize2 = configureRequestedSpy2.last().at(1).toSize();
0415 
0416     // Map the layer surface.
0417     shellSurface1->ack_configure(configureRequestedSpy1.last().at(0).toUInt());
0418     Window *window1 = Test::renderAndWaitForShown(surface1.get(), requestedSize1, Qt::red);
0419     QVERIFY(window1);
0420 
0421     shellSurface2->ack_configure(configureRequestedSpy2.last().at(0).toUInt());
0422     Window *window2 = Test::renderAndWaitForShown(surface2.get(), requestedSize2, Qt::red);
0423     QVERIFY(window2);
0424 
0425     // Check that the second layer surface is placed next to the first.
0426     QCOMPARE(window1->frameGeometry(), QRect(0, 450, 80, 124));
0427     QCOMPARE(window2->frameGeometry(), QRect(80, 450, 200, 124));
0428 
0429     // Check that the work area has been adjusted accordingly.
0430     QCOMPARE(workspace()->clientArea(PlacementArea, window1), QRect(280, 0, 1000, 1024));
0431     QCOMPARE(workspace()->clientArea(PlacementArea, window2), QRect(280, 0, 1000, 1024));
0432 
0433     // Destroy the window.
0434     shellSurface1.reset();
0435     QVERIFY(Test::waitForWindowDestroyed(window1));
0436     shellSurface2.reset();
0437     QVERIFY(Test::waitForWindowDestroyed(window2));
0438 }
0439 
0440 void LayerShellV1WindowTest::testFocus()
0441 {
0442     // Create a layer shell surface.
0443     std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
0444     std::unique_ptr<Test::LayerSurfaceV1> shellSurface(Test::createLayerSurfaceV1(surface.get(), QStringLiteral("test")));
0445 
0446     // Set the initial state of the layer surface.
0447     shellSurface->set_keyboard_interactivity(1);
0448     shellSurface->set_size(280, 124);
0449     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0450 
0451     // Wait for the compositor to position the surface.
0452     QSignalSpy configureRequestedSpy(shellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
0453     QVERIFY(configureRequestedSpy.wait());
0454     const QSize requestedSize = configureRequestedSpy.last().at(1).toSize();
0455 
0456     // Map the layer surface.
0457     shellSurface->ack_configure(configureRequestedSpy.last().at(0).toUInt());
0458     Window *window = Test::renderAndWaitForShown(surface.get(), requestedSize, Qt::red);
0459     QVERIFY(window);
0460 
0461     // The layer surface must be focused when it's mapped.
0462     QVERIFY(window->isActive());
0463 
0464     // Destroy the window.
0465     shellSurface.reset();
0466     QVERIFY(Test::waitForWindowDestroyed(window));
0467 }
0468 
0469 void LayerShellV1WindowTest::testActivate_data()
0470 {
0471     QTest::addColumn<int>("layer");
0472     QTest::addColumn<bool>("active");
0473 
0474     QTest::addRow("overlay") << int(Test::LayerShellV1::layer_overlay) << true;
0475     QTest::addRow("top") << int(Test::LayerShellV1::layer_top) << true;
0476     QTest::addRow("bottom") << int(Test::LayerShellV1::layer_bottom) << false;
0477     QTest::addRow("background") << int(Test::LayerShellV1::layer_background) << false;
0478 }
0479 
0480 void LayerShellV1WindowTest::testActivate()
0481 {
0482     // Create a layer shell surface.
0483     std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
0484     std::unique_ptr<Test::LayerSurfaceV1> shellSurface(Test::createLayerSurfaceV1(surface.get(), QStringLiteral("test")));
0485 
0486     // Set the initial state of the layer surface.
0487     QFETCH(int, layer);
0488     shellSurface->set_layer(layer);
0489     shellSurface->set_size(280, 124);
0490     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0491 
0492     // Wait for the compositor to position the surface.
0493     QSignalSpy configureRequestedSpy(shellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
0494     QVERIFY(configureRequestedSpy.wait());
0495     const QSize requestedSize = configureRequestedSpy.last().at(1).toSize();
0496 
0497     // Map the layer surface.
0498     shellSurface->ack_configure(configureRequestedSpy.last().at(0).toUInt());
0499     Window *window = Test::renderAndWaitForShown(surface.get(), requestedSize, Qt::red);
0500     QVERIFY(window);
0501     QVERIFY(!window->isActive());
0502 
0503     // Try to activate the layer surface.
0504     shellSurface->set_keyboard_interactivity(1);
0505     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0506 
0507     QSignalSpy activeChangedSpy(window, &Window::activeChanged);
0508     QTEST(activeChangedSpy.wait(1000), "active");
0509 
0510     // Destroy the window.
0511     shellSurface.reset();
0512     QVERIFY(Test::waitForWindowDestroyed(window));
0513 }
0514 
0515 void LayerShellV1WindowTest::testUnmap()
0516 {
0517     // Create a layer shell surface.
0518     std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
0519     std::unique_ptr<Test::LayerSurfaceV1> shellSurface(Test::createLayerSurfaceV1(surface.get(), QStringLiteral("test")));
0520 
0521     // Set the initial state of the layer surface.
0522     shellSurface->set_size(280, 124);
0523     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0524 
0525     // Wait for the compositor to position the surface.
0526     QSignalSpy configureRequestedSpy(shellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
0527     QVERIFY(configureRequestedSpy.wait());
0528 
0529     // Map the layer surface.
0530     shellSurface->ack_configure(configureRequestedSpy.last().at(0).toUInt());
0531     Window *window = Test::renderAndWaitForShown(surface.get(), QSize(280, 124), Qt::red);
0532     QVERIFY(window);
0533 
0534     // Unmap the layer surface.
0535     surface->attachBuffer(KWayland::Client::Buffer::Ptr());
0536     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0537     QVERIFY(Test::waitForWindowDestroyed(window));
0538 
0539     // Notify the compositor that we want to map the layer surface.
0540     shellSurface->set_size(280, 124);
0541     surface->commit(KWayland::Client::Surface::CommitFlag::None);
0542 
0543     // Wait for the configure event.
0544     QVERIFY(configureRequestedSpy.wait());
0545 
0546     // Map the layer surface back.
0547     shellSurface->ack_configure(configureRequestedSpy.last().at(0).toUInt());
0548     window = Test::renderAndWaitForShown(surface.get(), QSize(280, 124), Qt::red);
0549     QVERIFY(window);
0550 
0551     // Destroy the window.
0552     shellSurface.reset();
0553     QVERIFY(Test::waitForWindowDestroyed(window));
0554 }
0555 
0556 } // namespace KWin
0557 
0558 WAYLANDTEST_MAIN(KWin::LayerShellV1WindowTest)
0559 #include "layershellv1window_test.moc"