diff --git a/autotests/client/test_plasmashell.cpp b/autotests/client/test_plasmashell.cpp index 56bd6ea..d21f621 100644 --- a/autotests/client/test_plasmashell.cpp +++ b/autotests/client/test_plasmashell.cpp @@ -1,194 +1,233 @@ /******************************************************************** Copyright 2016 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ // Qt #include // KWayland #include "../../src/client/connection_thread.h" #include "../../src/client/compositor.h" #include "../../src/client/event_queue.h" #include "../../src/client/registry.h" #include "../../src/client/surface.h" #include "../../src/client/plasmashell.h" #include "../../src/server/display.h" #include "../../src/server/compositor_interface.h" #include "../../src/server/plasmashell_interface.h" using namespace KWayland::Client; using namespace KWayland::Server; class TestPlasmaShell : public QObject { Q_OBJECT private Q_SLOTS: void init(); void cleanup(); void testRole_data(); void testRole(); + void testDisconnect(); private: Display *m_display = nullptr; CompositorInterface *m_compositorInterface = nullptr; PlasmaShellInterface *m_plasmaShellInterface = nullptr; ConnectionThread *m_connection = nullptr; Compositor *m_compositor = nullptr; EventQueue *m_queue = nullptr; QThread *m_thread = nullptr; Registry *m_registry = nullptr; PlasmaShell *m_plasmaShell = nullptr; }; static const QString s_socketName = QStringLiteral("kwayland-test-wayland-plasma-shell-0"); void TestPlasmaShell::init() { delete m_display; m_display = new Display(this); m_display->setSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_compositorInterface = m_display->createCompositor(m_display); m_compositorInterface->create(); m_display->createShm(); m_plasmaShellInterface = m_display->createPlasmaShell(m_display); m_plasmaShellInterface->create(); // setup connection m_connection = new KWayland::Client::ConnectionThread; QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); QVERIFY(connectedSpy.isValid()); m_connection->setSocketName(s_socketName); m_thread = new QThread(this); m_connection->moveToThread(m_thread); m_thread->start(); m_connection->initConnection(); QVERIFY(connectedSpy.wait()); m_queue = new EventQueue(this); QVERIFY(!m_queue->isValid()); m_queue->setup(m_connection); QVERIFY(m_queue->isValid()); m_registry = new Registry(); QSignalSpy interfacesAnnouncedSpy(m_registry, &Registry::interfaceAnnounced); QVERIFY(interfacesAnnouncedSpy.isValid()); QVERIFY(!m_registry->eventQueue()); m_registry->setEventQueue(m_queue); QCOMPARE(m_registry->eventQueue(), m_queue); m_registry->create(m_connection); QVERIFY(m_registry->isValid()); m_registry->setup(); QVERIFY(interfacesAnnouncedSpy.wait()); #define CREATE(variable, factory, iface) \ variable = m_registry->create##factory(m_registry->interface(Registry::Interface::iface).name, m_registry->interface(Registry::Interface::iface).version, this); \ QVERIFY(variable); CREATE(m_compositor, Compositor, Compositor) CREATE(m_plasmaShell, PlasmaShell, PlasmaShell) #undef CREATE } void TestPlasmaShell::cleanup() { #define DELETE(name) \ if (name) { \ delete name; \ name = nullptr; \ } DELETE(m_plasmaShell) DELETE(m_compositor) DELETE(m_queue) DELETE(m_registry) #undef DELETE if (m_thread) { m_thread->quit(); m_thread->wait(); delete m_thread; m_thread = nullptr; } delete m_connection; m_connection = nullptr; delete m_display; m_display = nullptr; } void TestPlasmaShell::testRole_data() { QTest::addColumn("clientRole"); QTest::addColumn("serverRole"); QTest::newRow("desktop") << PlasmaShellSurface::Role::Desktop << PlasmaShellSurfaceInterface::Role::Desktop; QTest::newRow("osd") << PlasmaShellSurface::Role::OnScreenDisplay << PlasmaShellSurfaceInterface::Role::OnScreenDisplay; QTest::newRow("panel") << PlasmaShellSurface::Role::Panel << PlasmaShellSurfaceInterface::Role::Panel; } void TestPlasmaShell::testRole() { // this test verifies that setting the role on a plasma shell surface works // first create signal spies QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(surfaceCreatedSpy.isValid()); QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated); QVERIFY(plasmaSurfaceCreatedSpy.isValid()); // create the surface QScopedPointer s(m_compositor->createSurface()); QScopedPointer ps(m_plasmaShell->createSurface(s.data())); // and get them on the server QVERIFY(plasmaSurfaceCreatedSpy.wait()); QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1); QCOMPARE(surfaceCreatedSpy.count(), 1); // verify that we got a plasma shell surface auto sps = plasmaSurfaceCreatedSpy.first().first().value(); QVERIFY(sps); QVERIFY(sps->surface()); QCOMPARE(sps->surface(), surfaceCreatedSpy.first().first().value()); // default role should be normal QCOMPARE(sps->role(), PlasmaShellSurfaceInterface::Role::Normal); // now change it QSignalSpy roleChangedSpy(sps, &PlasmaShellSurfaceInterface::roleChanged); QVERIFY(roleChangedSpy.isValid()); QFETCH(PlasmaShellSurface::Role, clientRole); ps->setRole(clientRole); QVERIFY(roleChangedSpy.wait()); QCOMPARE(roleChangedSpy.count(), 1); QTEST(sps->role(), "serverRole"); } +void TestPlasmaShell::testDisconnect() +{ + // this test verifies that a disconnect cleans up + QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated); + QVERIFY(plasmaSurfaceCreatedSpy.isValid()); + // create the surface + QScopedPointer s(m_compositor->createSurface()); + QScopedPointer ps(m_plasmaShell->createSurface(s.data())); + + // and get them on the server + QVERIFY(plasmaSurfaceCreatedSpy.wait()); + QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1); + auto sps = plasmaSurfaceCreatedSpy.first().first().value(); + QVERIFY(sps); + + // disconnect + QSignalSpy clientDisconnectedSpy(sps->client(), &ClientConnection::disconnected); + QVERIFY(clientDisconnectedSpy.isValid()); + QSignalSpy surfaceDestroyedSpy(sps, &QObject::destroyed); + QVERIFY(surfaceDestroyedSpy.isValid()); + if (m_connection) { + m_connection->deleteLater(); + m_connection = nullptr; + } + QVERIFY(clientDisconnectedSpy.wait()); + QCOMPARE(clientDisconnectedSpy.count(), 1); + QCOMPARE(surfaceDestroyedSpy.count(), 0); + QVERIFY(surfaceDestroyedSpy.wait()); + QCOMPARE(surfaceDestroyedSpy.count(), 1); + + s->destroy(); + ps->destroy(); + m_plasmaShell->destroy(); + m_compositor->destroy(); + m_registry->destroy(); + m_queue->destroy(); +} + QTEST_GUILESS_MAIN(TestPlasmaShell) #include "test_plasmashell.moc" diff --git a/autotests/client/test_wayland_region.cpp b/autotests/client/test_wayland_region.cpp index 7249682..5a45992 100644 --- a/autotests/client/test_wayland_region.cpp +++ b/autotests/client/test_wayland_region.cpp @@ -1,285 +1,319 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ // Qt #include // KWin #include "../../src/client/compositor.h" #include "../../src/client/connection_thread.h" #include "../../src/client/event_queue.h" #include "../../src/client/region.h" #include "../../src/client/registry.h" #include "../../src/server/display.h" #include "../../src/server/compositor_interface.h" #include "../../src/server/region_interface.h" class TestRegion : public QObject { Q_OBJECT public: explicit TestRegion(QObject *parent = nullptr); private Q_SLOTS: void init(); void cleanup(); void testCreate(); void testCreateWithRegion(); void testCreateUniquePtr(); void testAdd(); void testRemove(); void testDestroy(); + void testDisconnect(); private: KWayland::Server::Display *m_display; KWayland::Server::CompositorInterface *m_compositorInterface; KWayland::Client::ConnectionThread *m_connection; KWayland::Client::Compositor *m_compositor; KWayland::Client::EventQueue *m_queue; QThread *m_thread; }; static const QString s_socketName = QStringLiteral("kwayland-test-wayland-region-0"); TestRegion::TestRegion(QObject *parent) : QObject(parent) , m_display(nullptr) , m_compositorInterface(nullptr) , m_connection(nullptr) , m_compositor(nullptr) , m_queue(nullptr) , m_thread(nullptr) { } void TestRegion::init() { using namespace KWayland::Server; delete m_display; m_display = new Display(this); m_display->setSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); // setup connection m_connection = new KWayland::Client::ConnectionThread; QSignalSpy connectedSpy(m_connection, SIGNAL(connected())); m_connection->setSocketName(s_socketName); m_thread = new QThread(this); m_connection->moveToThread(m_thread); m_thread->start(); m_connection->initConnection(); QVERIFY(connectedSpy.wait()); m_queue = new KWayland::Client::EventQueue(this); QVERIFY(!m_queue->isValid()); m_queue->setup(m_connection); QVERIFY(m_queue->isValid()); KWayland::Client::Registry registry; QSignalSpy compositorSpy(®istry, SIGNAL(compositorAnnounced(quint32,quint32))); QVERIFY(compositorSpy.isValid()); QVERIFY(!registry.eventQueue()); registry.setEventQueue(m_queue); QCOMPARE(registry.eventQueue(), m_queue); registry.create(m_connection->display()); QVERIFY(registry.isValid()); registry.setup(); m_compositorInterface = m_display->createCompositor(m_display); m_compositorInterface->create(); QVERIFY(m_compositorInterface->isValid()); QVERIFY(compositorSpy.wait()); m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); } void TestRegion::cleanup() { if (m_compositor) { delete m_compositor; m_compositor = nullptr; } if (m_queue) { delete m_queue; m_queue = nullptr; } if (m_thread) { m_thread->quit(); m_thread->wait(); delete m_thread; m_thread = nullptr; } delete m_connection; m_connection = nullptr; delete m_display; m_display = nullptr; } void TestRegion::testCreate() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy regionCreatedSpy(m_compositorInterface, SIGNAL(regionCreated(KWayland::Server::RegionInterface*))); QVERIFY(regionCreatedSpy.isValid()); QScopedPointer region(m_compositor->createRegion()); QCOMPARE(region->region(), QRegion()); QVERIFY(regionCreatedSpy.wait()); QCOMPARE(regionCreatedSpy.count(), 1); auto serverRegion = regionCreatedSpy.first().first().value(); QVERIFY(serverRegion); QCOMPARE(serverRegion->region(), QRegion()); QCOMPARE(serverRegion->global(), m_compositorInterface); } void TestRegion::testCreateWithRegion() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy regionCreatedSpy(m_compositorInterface, SIGNAL(regionCreated(KWayland::Server::RegionInterface*))); QVERIFY(regionCreatedSpy.isValid()); QScopedPointer region(m_compositor->createRegion(QRegion(0, 0, 10, 20), nullptr)); QCOMPARE(region->region(), QRegion(0, 0, 10, 20)); QVERIFY(regionCreatedSpy.wait()); QCOMPARE(regionCreatedSpy.count(), 1); auto serverRegion = regionCreatedSpy.first().first().value(); QVERIFY(serverRegion); QCOMPARE(serverRegion->region(), QRegion(0, 0, 10, 20)); QVERIFY(serverRegion->parentResource()); } void TestRegion::testCreateUniquePtr() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy regionCreatedSpy(m_compositorInterface, SIGNAL(regionCreated(KWayland::Server::RegionInterface*))); QVERIFY(regionCreatedSpy.isValid()); std::unique_ptr region(m_compositor->createRegion(QRegion(0, 0, 10, 20))); QCOMPARE(region->region(), QRegion(0, 0, 10, 20)); QVERIFY(regionCreatedSpy.wait()); QCOMPARE(regionCreatedSpy.count(), 1); auto serverRegion = regionCreatedSpy.first().first().value(); QVERIFY(serverRegion); QCOMPARE(serverRegion->region(), QRegion(0, 0, 10, 20)); } void TestRegion::testAdd() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy regionCreatedSpy(m_compositorInterface, SIGNAL(regionCreated(KWayland::Server::RegionInterface*))); QVERIFY(regionCreatedSpy.isValid()); QScopedPointer region(m_compositor->createRegion()); QVERIFY(regionCreatedSpy.wait()); auto serverRegion = regionCreatedSpy.first().first().value(); QSignalSpy regionChangedSpy(serverRegion, SIGNAL(regionChanged(QRegion))); QVERIFY(regionChangedSpy.isValid()); // adding a QRect region->add(QRect(0, 0, 10, 20)); QCOMPARE(region->region(), QRegion(0, 0, 10, 20)); QVERIFY(regionChangedSpy.wait()); QCOMPARE(regionChangedSpy.count(), 1); QCOMPARE(regionChangedSpy.last().first().value(), QRegion(0, 0, 10, 20)); QCOMPARE(serverRegion->region(), QRegion(0, 0, 10, 20)); // adding a QRegion region->add(QRegion(5, 5, 10, 50)); QRegion compareRegion(0, 0, 10, 20); compareRegion = compareRegion.united(QRect(5, 5, 10, 50)); QCOMPARE(region->region(), compareRegion); QVERIFY(regionChangedSpy.wait()); QCOMPARE(regionChangedSpy.count(), 2); QCOMPARE(regionChangedSpy.last().first().value(), compareRegion); QCOMPARE(serverRegion->region(), compareRegion); } void TestRegion::testRemove() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy regionCreatedSpy(m_compositorInterface, SIGNAL(regionCreated(KWayland::Server::RegionInterface*))); QVERIFY(regionCreatedSpy.isValid()); std::unique_ptr region(m_compositor->createRegion(QRegion(0, 0, 100, 200))); QVERIFY(regionCreatedSpy.wait()); auto serverRegion = regionCreatedSpy.first().first().value(); QSignalSpy regionChangedSpy(serverRegion, SIGNAL(regionChanged(QRegion))); QVERIFY(regionChangedSpy.isValid()); // subtract a QRect region->subtract(QRect(0, 0, 10, 20)); QRegion compareRegion(0, 0, 100, 200); compareRegion = compareRegion.subtracted(QRect(0, 0, 10, 20)); QCOMPARE(region->region(), compareRegion); QVERIFY(regionChangedSpy.wait()); QCOMPARE(regionChangedSpy.count(), 1); QCOMPARE(regionChangedSpy.last().first().value(), compareRegion); QCOMPARE(serverRegion->region(), compareRegion); // subtracting a QRegion region->subtract(QRegion(5, 5, 10, 50)); compareRegion = compareRegion.subtracted(QRect(5, 5, 10, 50)); QCOMPARE(region->region(), compareRegion); QVERIFY(regionChangedSpy.wait()); QCOMPARE(regionChangedSpy.count(), 2); QCOMPARE(regionChangedSpy.last().first().value(), compareRegion); QCOMPARE(serverRegion->region(), compareRegion); } void TestRegion::testDestroy() { using namespace KWayland::Client; QScopedPointer region(m_compositor->createRegion()); connect(m_connection, &ConnectionThread::connectionDied, region.data(), &Region::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_compositor, &Compositor::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_queue, &EventQueue::destroy); QVERIFY(region->isValid()); QSignalSpy connectionDiedSpy(m_connection, SIGNAL(connectionDied())); QVERIFY(connectionDiedSpy.isValid()); delete m_display; m_display = nullptr; QVERIFY(connectionDiedSpy.wait()); // now the region should be destroyed; QVERIFY(!region->isValid()); // calling destroy again should not fail region->destroy(); } +void TestRegion::testDisconnect() +{ + // this test verifies that the server side correctly tears down the resources when the client disconnects + using namespace KWayland::Client; + using namespace KWayland::Server; + QScopedPointer r(m_compositor->createRegion()); + QVERIFY(!r.isNull()); + QVERIFY(r->isValid()); + QSignalSpy regionCreatedSpy(m_compositorInterface, &CompositorInterface::regionCreated); + QVERIFY(regionCreatedSpy.isValid()); + QVERIFY(regionCreatedSpy.wait()); + auto serverRegion = regionCreatedSpy.first().first().value(); + + // destroy client + QSignalSpy clientDisconnectedSpy(serverRegion->client(), &ClientConnection::disconnected); + QVERIFY(clientDisconnectedSpy.isValid()); + QSignalSpy regionDestroyedSpy(serverRegion, &QObject::destroyed); + QVERIFY(regionDestroyedSpy.isValid()); + if (m_connection) { + m_connection->deleteLater(); + m_connection = nullptr; + } + QVERIFY(clientDisconnectedSpy.wait()); + QCOMPARE(clientDisconnectedSpy.count(), 1); + QCOMPARE(regionDestroyedSpy.count(), 0); + QVERIFY(regionDestroyedSpy.wait()); + QCOMPARE(regionDestroyedSpy.count(), 1); + + r->destroy(); + m_compositor->destroy(); + m_queue->destroy(); +} + QTEST_GUILESS_MAIN(TestRegion) #include "test_wayland_region.moc" diff --git a/autotests/client/test_wayland_seat.cpp b/autotests/client/test_wayland_seat.cpp index 8c68024..f51ad94 100644 --- a/autotests/client/test_wayland_seat.cpp +++ b/autotests/client/test_wayland_seat.cpp @@ -1,1539 +1,1612 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ // Qt #include // KWin #include "../../src/client/compositor.h" #include "../../src/client/connection_thread.h" #include "../../src/client/datadevice.h" #include "../../src/client/datadevicemanager.h" #include "../../src/client/datasource.h" #include "../../src/client/event_queue.h" #include "../../src/client/keyboard.h" #include "../../src/client/pointer.h" #include "../../src/client/surface.h" #include "../../src/client/registry.h" #include "../../src/client/seat.h" #include "../../src/client/shm_pool.h" #include "../../src/client/subcompositor.h" #include "../../src/client/subsurface.h" #include "../../src/client/touch.h" #include "../../src/server/buffer_interface.h" #include "../../src/server/compositor_interface.h" #include "../../src/server/datadevicemanager_interface.h" #include "../../src/server/display.h" #include "../../src/server/keyboard_interface.h" #include "../../src/server/pointer_interface.h" #include "../../src/server/seat_interface.h" #include "../../src/server/subcompositor_interface.h" #include "../../src/server/surface_interface.h" // Wayland #include #include class TestWaylandSeat : public QObject { Q_OBJECT public: explicit TestWaylandSeat(QObject *parent = nullptr); private Q_SLOTS: void init(); void cleanup(); void testName(); void testCapabilities_data(); void testCapabilities(); void testPointer(); void testPointerTransformation_data(); void testPointerTransformation(); void testPointerButton_data(); void testPointerButton(); void testPointerSubSurfaceTree(); void testKeyboardSubSurfaceTreeFromPointer(); void testCursor(); void testCursorDamage(); void testKeyboard(); void testCast(); void testDestroy(); void testSelection(); void testTouch(); + void testDisconnect(); // TODO: add test for keymap private: KWayland::Server::Display *m_display; KWayland::Server::CompositorInterface *m_compositorInterface; KWayland::Server::SeatInterface *m_seatInterface; KWayland::Server::SubCompositorInterface *m_subCompositorInterface; KWayland::Client::ConnectionThread *m_connection; KWayland::Client::Compositor *m_compositor; KWayland::Client::Seat *m_seat; KWayland::Client::ShmPool *m_shm; KWayland::Client::SubCompositor * m_subCompositor; KWayland::Client::EventQueue *m_queue; QThread *m_thread; }; static const QString s_socketName = QStringLiteral("kwin-test-wayland-seat-0"); TestWaylandSeat::TestWaylandSeat(QObject *parent) : QObject(parent) , m_display(nullptr) , m_compositorInterface(nullptr) , m_seatInterface(nullptr) , m_subCompositorInterface(nullptr) , m_connection(nullptr) , m_compositor(nullptr) , m_seat(nullptr) , m_shm(nullptr) , m_subCompositor(nullptr) , m_queue(nullptr) , m_thread(nullptr) { } void TestWaylandSeat::init() { using namespace KWayland::Server; delete m_display; m_display = new Display(this); m_display->setSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); m_compositorInterface = m_display->createCompositor(m_display); QVERIFY(m_compositorInterface); m_compositorInterface->create(); QVERIFY(m_compositorInterface->isValid()); m_subCompositorInterface = m_display->createSubCompositor(m_display); QVERIFY(m_subCompositorInterface); m_subCompositorInterface->create(); QVERIFY(m_subCompositorInterface->isValid()); // setup connection m_connection = new KWayland::Client::ConnectionThread; QSignalSpy connectedSpy(m_connection, SIGNAL(connected())); m_connection->setSocketName(s_socketName); m_thread = new QThread(this); m_connection->moveToThread(m_thread); m_thread->start(); m_connection->initConnection(); QVERIFY(connectedSpy.wait()); m_queue = new KWayland::Client::EventQueue(this); m_queue->setup(m_connection); KWayland::Client::Registry registry; QSignalSpy compositorSpy(®istry, SIGNAL(compositorAnnounced(quint32,quint32))); QSignalSpy seatSpy(®istry, SIGNAL(seatAnnounced(quint32,quint32))); QSignalSpy shmSpy(®istry, SIGNAL(shmAnnounced(quint32,quint32))); registry.setEventQueue(m_queue); registry.create(m_connection->display()); QVERIFY(registry.isValid()); registry.setup(); QVERIFY(compositorSpy.wait()); m_seatInterface = m_display->createSeat(); QVERIFY(m_seatInterface); m_seatInterface->setName(QStringLiteral("seat0")); m_seatInterface->create(); QVERIFY(m_seatInterface->isValid()); QVERIFY(seatSpy.wait()); m_compositor = new KWayland::Client::Compositor(this); m_compositor->setup(registry.bindCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value())); QVERIFY(m_compositor->isValid()); m_seat = registry.createSeat(seatSpy.first().first().value(), seatSpy.first().last().value(), this); QSignalSpy nameSpy(m_seat, SIGNAL(nameChanged(QString))); QVERIFY(nameSpy.wait()); m_shm = new KWayland::Client::ShmPool(this); m_shm->setup(registry.bindShm(shmSpy.first().first().value(), shmSpy.first().last().value())); QVERIFY(m_shm->isValid()); m_subCompositor = registry.createSubCompositor(registry.interface(KWayland::Client::Registry::Interface::SubCompositor).name, registry.interface(KWayland::Client::Registry::Interface::SubCompositor).version, this); QVERIFY(m_subCompositor->isValid()); } void TestWaylandSeat::cleanup() { if (m_subCompositor) { delete m_subCompositor; m_subCompositor = nullptr; } if (m_shm) { delete m_shm; m_shm = nullptr; } if (m_seat) { delete m_seat; m_seat = nullptr; } if (m_compositor) { delete m_compositor; m_compositor = nullptr; } if (m_queue) { delete m_queue; m_queue = nullptr; } if (m_connection) { m_connection->deleteLater(); m_connection = nullptr; } if (m_thread) { m_thread->quit(); m_thread->wait(); delete m_thread; m_thread = nullptr; } delete m_compositorInterface; m_compositorInterface = nullptr; delete m_seatInterface; m_seatInterface = nullptr; delete m_subCompositorInterface; m_subCompositorInterface = nullptr; delete m_display; m_display = nullptr; } void TestWaylandSeat::testName() { // no name set yet QCOMPARE(m_seat->name(), QStringLiteral("seat0")); QSignalSpy spy(m_seat, SIGNAL(nameChanged(QString))); QVERIFY(spy.isValid()); const QString name = QStringLiteral("foobar"); m_seatInterface->setName(name); QVERIFY(spy.wait()); QCOMPARE(m_seat->name(), name); QCOMPARE(spy.count(), 1); QCOMPARE(spy.first().first().toString(), name); } void TestWaylandSeat::testCapabilities_data() { QTest::addColumn("pointer"); QTest::addColumn("keyboard"); QTest::addColumn("touch"); QTest::newRow("none") << false << false << false; QTest::newRow("pointer") << true << false << false; QTest::newRow("keyboard") << false << true << false; QTest::newRow("touch") << false << false << true; QTest::newRow("pointer/keyboard") << true << true << false; QTest::newRow("pointer/touch") << true << false << true; QTest::newRow("keyboard/touch") << false << true << true; QTest::newRow("all") << true << true << true; } void TestWaylandSeat::testCapabilities() { QVERIFY(!m_seat->hasPointer()); QVERIFY(!m_seat->hasKeyboard()); QVERIFY(!m_seat->hasTouch()); QFETCH(bool, pointer); QFETCH(bool, keyboard); QFETCH(bool, touch); QSignalSpy pointerSpy(m_seat, SIGNAL(hasPointerChanged(bool))); QVERIFY(pointerSpy.isValid()); QSignalSpy keyboardSpy(m_seat, SIGNAL(hasKeyboardChanged(bool))); QVERIFY(keyboardSpy.isValid()); QSignalSpy touchSpy(m_seat, SIGNAL(hasTouchChanged(bool))); QVERIFY(touchSpy.isValid()); m_seatInterface->setHasPointer(pointer); m_seatInterface->setHasKeyboard(keyboard); m_seatInterface->setHasTouch(touch); // do processing QCOMPARE(pointerSpy.wait(1000), pointer); QCOMPARE(pointerSpy.isEmpty(), !pointer); if (!pointerSpy.isEmpty()) { QCOMPARE(pointerSpy.first().first().toBool(), pointer); } if (keyboardSpy.isEmpty()) { QCOMPARE(keyboardSpy.wait(1000), keyboard); } QCOMPARE(keyboardSpy.isEmpty(), !keyboard); if (!keyboardSpy.isEmpty()) { QCOMPARE(keyboardSpy.first().first().toBool(), keyboard); } if (touchSpy.isEmpty()) { QCOMPARE(touchSpy.wait(1000), touch); } QCOMPARE(touchSpy.isEmpty(), !touch); if (!touchSpy.isEmpty()) { QCOMPARE(touchSpy.first().first().toBool(), touch); } QCOMPARE(m_seat->hasPointer(), pointer); QCOMPARE(m_seat->hasKeyboard(), keyboard); QCOMPARE(m_seat->hasTouch(), touch); } void TestWaylandSeat::testPointer() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy pointerSpy(m_seat, SIGNAL(hasPointerChanged(bool))); QVERIFY(pointerSpy.isValid()); m_seatInterface->setHasPointer(true); QVERIFY(pointerSpy.wait()); QSignalSpy surfaceCreatedSpy(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(surfaceCreatedSpy.isValid()); Surface *s = m_compositor->createSurface(m_compositor); QVERIFY(surfaceCreatedSpy.wait()); SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value(); QVERIFY(serverSurface); QSignalSpy focusedPointerChangedSpy(m_seatInterface, &SeatInterface::focusedPointerChanged); QVERIFY(focusedPointerChangedSpy.isValid()); m_seatInterface->setPointerPos(QPoint(20, 18)); m_seatInterface->setFocusedPointerSurface(serverSurface, QPoint(10, 15)); QCOMPARE(focusedPointerChangedSpy.count(), 1); QVERIFY(!focusedPointerChangedSpy.first().first().value()); // no pointer yet QVERIFY(m_seatInterface->focusedPointerSurface()); QVERIFY(!m_seatInterface->focusedPointer()); Pointer *p = m_seat->createPointer(m_seat); const Pointer &cp = *p; QVERIFY(p->isValid()); QSignalSpy pointerCreatedSpy(m_seatInterface, SIGNAL(pointerCreated(KWayland::Server::PointerInterface*))); QVERIFY(pointerCreatedSpy.isValid()); // once the pointer is created it should be set as the focused pointer QVERIFY(pointerCreatedSpy.wait()); QVERIFY(m_seatInterface->focusedPointer()); QCOMPARE(pointerCreatedSpy.first().first().value(), m_seatInterface->focusedPointer()); QCOMPARE(focusedPointerChangedSpy.count(), 2); QCOMPARE(focusedPointerChangedSpy.last().first().value(), m_seatInterface->focusedPointer()); m_seatInterface->setFocusedPointerSurface(nullptr); QCOMPARE(focusedPointerChangedSpy.count(), 3); QVERIFY(!focusedPointerChangedSpy.last().first().value()); serverSurface->client()->flush(); QTest::qWait(100); QSignalSpy enteredSpy(p, SIGNAL(entered(quint32,QPointF))); QVERIFY(enteredSpy.isValid()); QSignalSpy leftSpy(p, SIGNAL(left(quint32))); QVERIFY(leftSpy.isValid()); QSignalSpy motionSpy(p, SIGNAL(motion(QPointF,quint32))); QVERIFY(motionSpy.isValid()); QSignalSpy axisSpy(p, SIGNAL(axisChanged(quint32,KWayland::Client::Pointer::Axis,qreal))); QVERIFY(axisSpy.isValid()); QSignalSpy buttonSpy(p, SIGNAL(buttonStateChanged(quint32,quint32,quint32,KWayland::Client::Pointer::ButtonState))); QVERIFY(buttonSpy.isValid()); QVERIFY(!p->enteredSurface()); QVERIFY(!cp.enteredSurface()); m_seatInterface->setFocusedPointerSurface(serverSurface, QPoint(10, 15)); QCOMPARE(m_seatInterface->focusedPointerSurface(), serverSurface); QVERIFY(enteredSpy.wait()); QCOMPARE(enteredSpy.first().first().value(), m_display->serial()); QCOMPARE(enteredSpy.first().last().toPoint(), QPoint(10, 3)); PointerInterface *serverPointer = m_seatInterface->focusedPointer(); QVERIFY(serverPointer); QCOMPARE(p->enteredSurface(), s); QCOMPARE(cp.enteredSurface(), s); QCOMPARE(focusedPointerChangedSpy.count(), 4); QCOMPARE(focusedPointerChangedSpy.last().first().value(), serverPointer); // test motion m_seatInterface->setTimestamp(1); m_seatInterface->setPointerPos(QPoint(10, 16)); QVERIFY(motionSpy.wait()); QCOMPARE(motionSpy.first().first().toPoint(), QPoint(0, 1)); QCOMPARE(motionSpy.first().last().value(), quint32(1)); // test axis m_seatInterface->setTimestamp(2); m_seatInterface->pointerAxis(Qt::Horizontal, 10); QVERIFY(axisSpy.wait()); m_seatInterface->setTimestamp(3); m_seatInterface->pointerAxis(Qt::Vertical, 20); QVERIFY(axisSpy.wait()); QCOMPARE(axisSpy.first().at(0).value(), quint32(2)); QCOMPARE(axisSpy.first().at(1).value(), Pointer::Axis::Horizontal); QCOMPARE(axisSpy.first().at(2).value(), qreal(10)); QCOMPARE(axisSpy.last().at(0).value(), quint32(3)); QCOMPARE(axisSpy.last().at(1).value(), Pointer::Axis::Vertical); QCOMPARE(axisSpy.last().at(2).value(), qreal(20)); // test button m_seatInterface->setTimestamp(4); m_seatInterface->pointerButtonPressed(1); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.at(0).at(0).value(), m_display->serial()); m_seatInterface->setTimestamp(5); m_seatInterface->pointerButtonPressed(2); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.at(1).at(0).value(), m_display->serial()); m_seatInterface->setTimestamp(6); m_seatInterface->pointerButtonReleased(2); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.at(2).at(0).value(), m_display->serial()); m_seatInterface->setTimestamp(7); m_seatInterface->pointerButtonReleased(1); QVERIFY(buttonSpy.wait()); QCOMPARE(buttonSpy.count(), 4); // timestamp QCOMPARE(buttonSpy.at(0).at(1).value(), quint32(4)); // button QCOMPARE(buttonSpy.at(0).at(2).value(), quint32(1)); QCOMPARE(buttonSpy.at(0).at(3).value(), KWayland::Client::Pointer::ButtonState::Pressed); // timestamp QCOMPARE(buttonSpy.at(1).at(1).value(), quint32(5)); // button QCOMPARE(buttonSpy.at(1).at(2).value(), quint32(2)); QCOMPARE(buttonSpy.at(1).at(3).value(), KWayland::Client::Pointer::ButtonState::Pressed); QCOMPARE(buttonSpy.at(2).at(0).value(), m_seatInterface->pointerButtonSerial(2)); // timestamp QCOMPARE(buttonSpy.at(2).at(1).value(), quint32(6)); // button QCOMPARE(buttonSpy.at(2).at(2).value(), quint32(2)); QCOMPARE(buttonSpy.at(2).at(3).value(), KWayland::Client::Pointer::ButtonState::Released); QCOMPARE(buttonSpy.at(3).at(0).value(), m_seatInterface->pointerButtonSerial(1)); // timestamp QCOMPARE(buttonSpy.at(3).at(1).value(), quint32(7)); // button QCOMPARE(buttonSpy.at(3).at(2).value(), quint32(1)); QCOMPARE(buttonSpy.at(3).at(3).value(), KWayland::Client::Pointer::ButtonState::Released); // leave the surface m_seatInterface->setFocusedPointerSurface(nullptr); QCOMPARE(focusedPointerChangedSpy.count(), 5); QVERIFY(leftSpy.wait()); QCOMPARE(leftSpy.first().first().value(), m_display->serial()); QVERIFY(!p->enteredSurface()); QVERIFY(!cp.enteredSurface()); // enter it again m_seatInterface->setFocusedPointerSurface(serverSurface, QPoint(0, 0)); QCOMPARE(focusedPointerChangedSpy.count(), 6); QVERIFY(enteredSpy.wait()); QCOMPARE(p->enteredSurface(), s); QCOMPARE(cp.enteredSurface(), s); delete s; wl_display_flush(m_connection->display()); QVERIFY(focusedPointerChangedSpy.wait()); QCOMPARE(focusedPointerChangedSpy.count(), 7); QVERIFY(!m_seatInterface->focusedPointerSurface()); } void TestWaylandSeat::testPointerTransformation_data() { QTest::addColumn("enterTransformation"); // global position at 20/18 QTest::addColumn("expectedEnterPoint"); // global position at 10/16 QTest::addColumn("expectedMovePoint"); QMatrix4x4 tm; tm.translate(-10, -15); QTest::newRow("translation") << tm << QPointF(10, 3) << QPointF(0, 1); QMatrix4x4 sm; sm.scale(2, 2); QTest::newRow("scale") << sm << QPointF(40, 36) << QPointF(20, 32); QMatrix4x4 rotate; rotate.rotate(90, 0, 0, 1); QTest::newRow("rotate") << rotate << QPointF(-18, 20) << QPointF(-16, 10); } void TestWaylandSeat::testPointerTransformation() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy pointerSpy(m_seat, &Seat::hasPointerChanged); QVERIFY(pointerSpy.isValid()); m_seatInterface->setHasPointer(true); QVERIFY(pointerSpy.wait()); QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(surfaceCreatedSpy.isValid()); Surface *s = m_compositor->createSurface(m_compositor); QVERIFY(surfaceCreatedSpy.wait()); SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value(); QVERIFY(serverSurface); m_seatInterface->setPointerPos(QPoint(20, 18)); QFETCH(QMatrix4x4, enterTransformation); m_seatInterface->setFocusedPointerSurface(serverSurface, enterTransformation); QCOMPARE(m_seatInterface->focusedPointerSurfaceTransformation(), enterTransformation); // no pointer yet QVERIFY(m_seatInterface->focusedPointerSurface()); QVERIFY(!m_seatInterface->focusedPointer()); Pointer *p = m_seat->createPointer(m_seat); const Pointer &cp = *p; QVERIFY(p->isValid()); QSignalSpy pointerCreatedSpy(m_seatInterface, &SeatInterface::pointerCreated); QVERIFY(pointerCreatedSpy.isValid()); // once the pointer is created it should be set as the focused pointer QVERIFY(pointerCreatedSpy.wait()); QVERIFY(m_seatInterface->focusedPointer()); QCOMPARE(pointerCreatedSpy.first().first().value(), m_seatInterface->focusedPointer()); m_seatInterface->setFocusedPointerSurface(nullptr); serverSurface->client()->flush(); QTest::qWait(100); QSignalSpy enteredSpy(p, &Pointer::entered); QVERIFY(enteredSpy.isValid()); QSignalSpy leftSpy(p, &Pointer::left); QVERIFY(leftSpy.isValid()); QSignalSpy motionSpy(p, &Pointer::motion); QVERIFY(motionSpy.isValid()); QVERIFY(!p->enteredSurface()); QVERIFY(!cp.enteredSurface()); m_seatInterface->setFocusedPointerSurface(serverSurface, enterTransformation); QCOMPARE(m_seatInterface->focusedPointerSurface(), serverSurface); QVERIFY(enteredSpy.wait()); QCOMPARE(enteredSpy.first().first().value(), m_display->serial()); QTEST(enteredSpy.first().last().toPointF(), "expectedEnterPoint"); PointerInterface *serverPointer = m_seatInterface->focusedPointer(); QVERIFY(serverPointer); QCOMPARE(p->enteredSurface(), s); QCOMPARE(cp.enteredSurface(), s); // test motion m_seatInterface->setTimestamp(1); m_seatInterface->setPointerPos(QPoint(10, 16)); QVERIFY(motionSpy.wait()); QTEST(motionSpy.first().first().toPointF(), "expectedMovePoint"); QCOMPARE(motionSpy.first().last().value(), quint32(1)); // leave the surface m_seatInterface->setFocusedPointerSurface(nullptr); QVERIFY(leftSpy.wait()); QCOMPARE(leftSpy.first().first().value(), m_display->serial()); QVERIFY(!p->enteredSurface()); QVERIFY(!cp.enteredSurface()); // enter it again m_seatInterface->setFocusedPointerSurface(serverSurface); QVERIFY(enteredSpy.wait()); QCOMPARE(p->enteredSurface(), s); QCOMPARE(cp.enteredSurface(), s); delete s; wl_display_flush(m_connection->display()); QTest::qWait(100); QVERIFY(!m_seatInterface->focusedPointerSurface()); } Q_DECLARE_METATYPE(Qt::MouseButton) void TestWaylandSeat::testPointerButton_data() { QTest::addColumn("qtButton"); QTest::addColumn("waylandButton"); QTest::newRow("left") << Qt::LeftButton << quint32(BTN_LEFT); QTest::newRow("right") << Qt::RightButton << quint32(BTN_RIGHT); QTest::newRow("mid") << Qt::MidButton << quint32(BTN_MIDDLE); QTest::newRow("middle") << Qt::MiddleButton << quint32(BTN_MIDDLE); QTest::newRow("back") << Qt::BackButton << quint32(BTN_BACK); QTest::newRow("x1") << Qt::XButton1 << quint32(BTN_BACK); QTest::newRow("extra1") << Qt::ExtraButton1 << quint32(BTN_BACK); QTest::newRow("forward") << Qt::ForwardButton << quint32(BTN_FORWARD); QTest::newRow("x2") << Qt::XButton2 << quint32(BTN_FORWARD); QTest::newRow("extra2") << Qt::ExtraButton2 << quint32(BTN_FORWARD); QTest::newRow("task") << Qt::TaskButton << quint32(BTN_TASK); QTest::newRow("extra3") << Qt::ExtraButton3 << quint32(BTN_TASK); QTest::newRow("extra4") << Qt::ExtraButton4 << quint32(BTN_EXTRA); QTest::newRow("extra5") << Qt::ExtraButton5 << quint32(BTN_SIDE); QTest::newRow("extra6") << Qt::ExtraButton6 << quint32(0x118); QTest::newRow("extra7") << Qt::ExtraButton7 << quint32(0x119); QTest::newRow("extra8") << Qt::ExtraButton8 << quint32(0x11a); QTest::newRow("extra9") << Qt::ExtraButton9 << quint32(0x11b); QTest::newRow("extra10") << Qt::ExtraButton10 << quint32(0x11c); QTest::newRow("extra11") << Qt::ExtraButton11 << quint32(0x11d); QTest::newRow("extra12") << Qt::ExtraButton12 << quint32(0x11e); QTest::newRow("extra13") << Qt::ExtraButton13 << quint32(0x11f); } void TestWaylandSeat::testPointerButton() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy pointerSpy(m_seat, SIGNAL(hasPointerChanged(bool))); QVERIFY(pointerSpy.isValid()); m_seatInterface->setHasPointer(true); QVERIFY(pointerSpy.wait()); QSignalSpy surfaceCreatedSpy(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(surfaceCreatedSpy.isValid()); m_compositor->createSurface(m_compositor); QVERIFY(surfaceCreatedSpy.wait()); SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value(); QVERIFY(serverSurface); QScopedPointer p(m_seat->createPointer()); QVERIFY(p->isValid()); QSignalSpy buttonChangedSpy(p.data(), SIGNAL(buttonStateChanged(quint32,quint32,quint32,KWayland::Client::Pointer::ButtonState))); QVERIFY(buttonChangedSpy.isValid()); wl_display_flush(m_connection->display()); QCoreApplication::processEvents(); m_seatInterface->setPointerPos(QPoint(20, 18)); m_seatInterface->setFocusedPointerSurface(serverSurface, QPoint(10, 15)); QVERIFY(m_seatInterface->focusedPointerSurface()); QVERIFY(m_seatInterface->focusedPointer()); QCoreApplication::processEvents(); m_seatInterface->setFocusedPointerSurface(serverSurface, QPoint(10, 15)); PointerInterface *serverPointer = m_seatInterface->focusedPointer(); QVERIFY(serverPointer); QFETCH(Qt::MouseButton, qtButton); QFETCH(quint32, waylandButton); quint32 msec = QDateTime::currentMSecsSinceEpoch(); QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), false); QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), false); m_seatInterface->setTimestamp(msec); m_seatInterface->pointerButtonPressed(qtButton); QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), true); QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), true); QVERIFY(buttonChangedSpy.wait()); QCOMPARE(buttonChangedSpy.count(), 1); QCOMPARE(buttonChangedSpy.last().at(0).value(), m_seatInterface->pointerButtonSerial(waylandButton)); QCOMPARE(buttonChangedSpy.last().at(0).value(), m_seatInterface->pointerButtonSerial(qtButton)); QCOMPARE(buttonChangedSpy.last().at(1).value(), msec); QCOMPARE(buttonChangedSpy.last().at(2).value(), waylandButton); QCOMPARE(buttonChangedSpy.last().at(3).value(), Pointer::ButtonState::Pressed); msec = QDateTime::currentMSecsSinceEpoch(); m_seatInterface->setTimestamp(QDateTime::currentMSecsSinceEpoch()); m_seatInterface->pointerButtonReleased(qtButton); QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), false); QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), false); QVERIFY(buttonChangedSpy.wait()); QCOMPARE(buttonChangedSpy.count(), 2); QCOMPARE(buttonChangedSpy.last().at(0).value(), m_seatInterface->pointerButtonSerial(waylandButton)); QCOMPARE(buttonChangedSpy.last().at(0).value(), m_seatInterface->pointerButtonSerial(qtButton)); QCOMPARE(buttonChangedSpy.last().at(1).value(), msec); QCOMPARE(buttonChangedSpy.last().at(2).value(), waylandButton); QCOMPARE(buttonChangedSpy.last().at(3).value(), Pointer::ButtonState::Released); } void TestWaylandSeat::testPointerSubSurfaceTree() { // this test verifies that pointer motion on a surface with sub-surfaces sends motion enter/leave to the sub-surface using namespace KWayland::Client; using namespace KWayland::Server; // first create the pointer QSignalSpy hasPointerChangedSpy(m_seat, &Seat::hasPointerChanged); QVERIFY(hasPointerChangedSpy.isValid()); m_seatInterface->setHasPointer(true); QVERIFY(hasPointerChangedSpy.wait()); QScopedPointer pointer(m_seat->createPointer()); // create a sub surface tree // parent surface (100, 100) with one sub surface taking the half of it's size (50, 100) // which has two further children (50, 50) which are overlapping QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(surfaceCreatedSpy.isValid()); QScopedPointer parentSurface(m_compositor->createSurface()); QScopedPointer childSurface(m_compositor->createSurface()); QScopedPointer grandChild1Surface(m_compositor->createSurface()); QScopedPointer grandChild2Surface(m_compositor->createSurface()); QScopedPointer childSubSurface(m_subCompositor->createSubSurface(childSurface.data(), parentSurface.data())); QScopedPointer grandChild1SubSurface(m_subCompositor->createSubSurface(grandChild1Surface.data(), childSurface.data())); QScopedPointer grandChild2SubSurface(m_subCompositor->createSubSurface(grandChild2Surface.data(), childSurface.data())); grandChild2SubSurface->setPosition(QPoint(0, 25)); // let's map the surfaces auto render = [this] (Surface *s, const QSize &size) { QImage image(size, QImage::Format_ARGB32); image.fill(Qt::black); s->attachBuffer(m_shm->createBuffer(image)); s->damage(QRect(QPoint(0, 0), size)); s->commit(Surface::CommitFlag::None); }; render(grandChild2Surface.data(), QSize(50, 50)); render(grandChild1Surface.data(), QSize(50, 50)); render(childSurface.data(), QSize(50, 100)); render(parentSurface.data(), QSize(100, 100)); QVERIFY(surfaceCreatedSpy.wait()); auto serverSurface = surfaceCreatedSpy.first().first().value(); QVERIFY(serverSurface->isMapped()); // send in pointer events QSignalSpy enteredSpy(pointer.data(), &Pointer::entered); QVERIFY(enteredSpy.isValid()); QSignalSpy leftSpy(pointer.data(), &Pointer::left); QVERIFY(leftSpy.isValid()); QSignalSpy motionSpy(pointer.data(), &Pointer::motion); QVERIFY(motionSpy.isValid()); // first to the grandChild2 in the overlapped area quint32 timestamp = 1; m_seatInterface->setTimestamp(timestamp++); m_seatInterface->setPointerPos(QPointF(25, 50)); m_seatInterface->setFocusedPointerSurface(serverSurface); QVERIFY(enteredSpy.wait()); QCOMPARE(enteredSpy.count(), 1); QCOMPARE(leftSpy.count(), 0); QCOMPARE(motionSpy.count(), 0); QCOMPARE(enteredSpy.last().last().toPointF(), QPointF(25, 25)); QCOMPARE(pointer->enteredSurface(), grandChild2Surface.data()); // a motion on grandchild2 m_seatInterface->setTimestamp(timestamp++); m_seatInterface->setPointerPos(QPointF(25, 60)); QVERIFY(motionSpy.wait()); QCOMPARE(enteredSpy.count(), 1); QCOMPARE(leftSpy.count(), 0); QCOMPARE(motionSpy.count(), 1); QCOMPARE(motionSpy.last().first().toPointF(), QPointF(25, 35)); // motion which changes to childSurface m_seatInterface->setTimestamp(timestamp++); m_seatInterface->setPointerPos(QPointF(25, 80)); QVERIFY(enteredSpy.wait()); QCOMPARE(enteredSpy.count(), 2); QCOMPARE(leftSpy.count(), 1); QCOMPARE(motionSpy.count(), 1); QCOMPARE(enteredSpy.last().last().toPointF(), QPointF(25, 80)); QCOMPARE(pointer->enteredSurface(), childSurface.data()); // a leave for the whole surface m_seatInterface->setTimestamp(timestamp++); m_seatInterface->setFocusedPointerSurface(nullptr); QVERIFY(leftSpy.wait()); QCOMPARE(enteredSpy.count(), 2); QCOMPARE(leftSpy.count(), 2); QCOMPARE(motionSpy.count(), 1); // a new enter on the main surface m_seatInterface->setTimestamp(timestamp++); m_seatInterface->setPointerPos(QPointF(75, 50)); m_seatInterface->setFocusedPointerSurface(serverSurface); QVERIFY(enteredSpy.wait()); QCOMPARE(enteredSpy.count(), 3); QCOMPARE(leftSpy.count(), 2); QCOMPARE(motionSpy.count(), 1); QCOMPARE(enteredSpy.last().last().toPointF(), QPointF(75, 50)); QCOMPARE(pointer->enteredSurface(), parentSurface.data()); } void TestWaylandSeat::testKeyboardSubSurfaceTreeFromPointer() { // this test verifies that when clicking on a sub-surface the keyboard focus passes to it using namespace KWayland::Client; using namespace KWayland::Server; // first create the pointer QSignalSpy hasPointerChangedSpy(m_seat, &Seat::hasPointerChanged); QVERIFY(hasPointerChangedSpy.isValid()); m_seatInterface->setHasPointer(true); QVERIFY(hasPointerChangedSpy.wait()); QScopedPointer pointer(m_seat->createPointer()); // and create keyboard QSignalSpy hasKeyboardChangedSpy(m_seat, &Seat::hasKeyboardChanged); QVERIFY(hasKeyboardChangedSpy.isValid()); m_seatInterface->setHasKeyboard(true); QVERIFY(hasKeyboardChangedSpy.wait()); QScopedPointer keyboard(m_seat->createKeyboard()); // create a sub surface tree // parent surface (100, 100) with one sub surface taking the half of it's size (50, 100) // which has two further children (50, 50) which are overlapping QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(surfaceCreatedSpy.isValid()); QScopedPointer parentSurface(m_compositor->createSurface()); QScopedPointer childSurface(m_compositor->createSurface()); QScopedPointer grandChild1Surface(m_compositor->createSurface()); QScopedPointer grandChild2Surface(m_compositor->createSurface()); QScopedPointer childSubSurface(m_subCompositor->createSubSurface(childSurface.data(), parentSurface.data())); QScopedPointer grandChild1SubSurface(m_subCompositor->createSubSurface(grandChild1Surface.data(), childSurface.data())); QScopedPointer grandChild2SubSurface(m_subCompositor->createSubSurface(grandChild2Surface.data(), childSurface.data())); grandChild2SubSurface->setPosition(QPoint(0, 25)); // let's map the surfaces auto render = [this] (Surface *s, const QSize &size) { QImage image(size, QImage::Format_ARGB32); image.fill(Qt::black); s->attachBuffer(m_shm->createBuffer(image)); s->damage(QRect(QPoint(0, 0), size)); s->commit(Surface::CommitFlag::None); }; render(grandChild2Surface.data(), QSize(50, 50)); render(grandChild1Surface.data(), QSize(50, 50)); render(childSurface.data(), QSize(50, 100)); render(parentSurface.data(), QSize(100, 100)); QVERIFY(surfaceCreatedSpy.wait()); auto serverSurface = surfaceCreatedSpy.first().first().value(); QVERIFY(serverSurface->isMapped()); // pass keyboard focus to the main surface QSignalSpy enterSpy(keyboard.data(), &Keyboard::entered); QVERIFY(enterSpy.isValid()); QSignalSpy leftSpy(keyboard.data(), &Keyboard::left); QVERIFY(leftSpy.isValid()); m_seatInterface->setFocusedKeyboardSurface(serverSurface); QVERIFY(enterSpy.wait()); QCOMPARE(enterSpy.count(), 1); QCOMPARE(leftSpy.count(), 0); QCOMPARE(keyboard->enteredSurface(), parentSurface.data()); // now pass also pointer focus to the surface QSignalSpy pointerEnterSpy(pointer.data(), &Pointer::entered); QVERIFY(pointerEnterSpy.isValid()); quint32 timestamp = 1; m_seatInterface->setTimestamp(timestamp++); m_seatInterface->setPointerPos(QPointF(25, 50)); m_seatInterface->setFocusedPointerSurface(serverSurface); QVERIFY(pointerEnterSpy.wait()); QCOMPARE(pointerEnterSpy.count(), 1); // should not have affected the keyboard QCOMPARE(enterSpy.count(), 1); QCOMPARE(leftSpy.count(), 0); // let's click m_seatInterface->setTimestamp(timestamp++); m_seatInterface->pointerButtonPressed(Qt::LeftButton); m_seatInterface->setTimestamp(timestamp++); m_seatInterface->pointerButtonReleased(Qt::LeftButton); QVERIFY(enterSpy.wait()); QCOMPARE(enterSpy.count(), 2); QCOMPARE(leftSpy.count(), 1); QCOMPARE(keyboard->enteredSurface(), grandChild2Surface.data()); // click on same surface should not trigger another enter m_seatInterface->setTimestamp(timestamp++); m_seatInterface->pointerButtonPressed(Qt::LeftButton); m_seatInterface->setTimestamp(timestamp++); m_seatInterface->pointerButtonReleased(Qt::LeftButton); QVERIFY(!enterSpy.wait(200)); QCOMPARE(enterSpy.count(), 2); QCOMPARE(leftSpy.count(), 1); QCOMPARE(keyboard->enteredSurface(), grandChild2Surface.data()); // unfocus keyboard m_seatInterface->setFocusedKeyboardSurface(nullptr); QVERIFY(leftSpy.wait()); QCOMPARE(enterSpy.count(), 2); QCOMPARE(leftSpy.count(), 2); } void TestWaylandSeat::testCursor() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy pointerSpy(m_seat, SIGNAL(hasPointerChanged(bool))); QVERIFY(pointerSpy.isValid()); m_seatInterface->setHasPointer(true); QVERIFY(pointerSpy.wait()); QSignalSpy surfaceCreatedSpy(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(surfaceCreatedSpy.isValid()); m_compositor->createSurface(m_compositor); QVERIFY(surfaceCreatedSpy.wait()); SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value(); QVERIFY(serverSurface); QScopedPointer p(m_seat->createPointer()); QVERIFY(p->isValid()); wl_display_flush(m_connection->display()); QCoreApplication::processEvents(); QSignalSpy enteredSpy(p.data(), SIGNAL(entered(quint32,QPointF))); QVERIFY(enteredSpy.isValid()); m_seatInterface->setPointerPos(QPoint(20, 18)); m_seatInterface->setFocusedPointerSurface(serverSurface, QPoint(10, 15)); quint32 serial = m_seatInterface->display()->serial(); QVERIFY(enteredSpy.wait()); QCOMPARE(enteredSpy.first().first().value(), serial); QVERIFY(m_seatInterface->focusedPointerSurface()); QVERIFY(m_seatInterface->focusedPointer()); QVERIFY(!m_seatInterface->focusedPointer()->cursor()); QSignalSpy cursorChangedSpy(m_seatInterface->focusedPointer(), SIGNAL(cursorChanged())); QVERIFY(cursorChangedSpy.isValid()); // just remove the pointer p->setCursor(nullptr); QVERIFY(cursorChangedSpy.wait()); QCOMPARE(cursorChangedSpy.count(), 1); auto cursor = m_seatInterface->focusedPointer()->cursor(); QVERIFY(cursor); QVERIFY(!cursor->surface()); QCOMPARE(cursor->hotspot(), QPoint()); QCOMPARE(cursor->enteredSerial(), serial); QSignalSpy hotspotChangedSpy(cursor, SIGNAL(hotspotChanged())); QVERIFY(hotspotChangedSpy.isValid()); QSignalSpy surfaceChangedSpy(cursor, SIGNAL(surfaceChanged())); QVERIFY(surfaceChangedSpy.isValid()); QSignalSpy enteredSerialChangedSpy(cursor, SIGNAL(enteredSerialChanged())); QVERIFY(enteredSerialChangedSpy.isValid()); QSignalSpy changedSpy(cursor, SIGNAL(changed())); QVERIFY(changedSpy.isValid()); // test changing hotspot p->setCursor(nullptr, QPoint(1, 2)); QVERIFY(hotspotChangedSpy.wait()); QCOMPARE(hotspotChangedSpy.count(), 1); QCOMPARE(changedSpy.count(), 1); QCOMPARE(cursorChangedSpy.count(), 2); QCOMPARE(cursor->hotspot(), QPoint(1, 2)); QVERIFY(enteredSerialChangedSpy.isEmpty()); QVERIFY(surfaceChangedSpy.isEmpty()); // set surface auto cursorSurface = m_compositor->createSurface(m_compositor); QVERIFY(cursorSurface->isValid()); p->setCursor(cursorSurface, QPoint(1, 2)); QVERIFY(surfaceChangedSpy.wait()); QCOMPARE(surfaceChangedSpy.count(), 1); QCOMPARE(changedSpy.count(), 2); QCOMPARE(cursorChangedSpy.count(), 3); QVERIFY(enteredSerialChangedSpy.isEmpty()); QCOMPARE(cursor->hotspot(), QPoint(1, 2)); QVERIFY(cursor->surface()); // and add an image to the surface QImage img(QSize(10, 20), QImage::Format_RGB32); img.fill(Qt::red); cursorSurface->attachBuffer(m_shm->createBuffer(img)); cursorSurface->damage(QRect(0, 0, 10, 20)); cursorSurface->commit(Surface::CommitFlag::None); QVERIFY(changedSpy.wait()); QCOMPARE(changedSpy.count(), 3); QCOMPARE(cursorChangedSpy.count(), 4); QCOMPARE(surfaceChangedSpy.count(), 1); QCOMPARE(cursor->surface()->buffer()->data(), img); // and add another image to the surface QImage blue(QSize(10, 20), QImage::Format_ARGB32); blue.fill(Qt::blue); cursorSurface->attachBuffer(m_shm->createBuffer(blue)); cursorSurface->damage(QRect(0, 0, 10, 20)); cursorSurface->commit(Surface::CommitFlag::None); QVERIFY(changedSpy.wait()); QCOMPARE(changedSpy.count(), 4); QCOMPARE(cursorChangedSpy.count(), 5); QCOMPARE(cursor->surface()->buffer()->data(), blue); p->hideCursor(); QVERIFY(surfaceChangedSpy.wait()); QCOMPARE(changedSpy.count(), 5); QCOMPARE(cursorChangedSpy.count(), 6); QCOMPARE(surfaceChangedSpy.count(), 2); QVERIFY(!cursor->surface()); } void TestWaylandSeat::testCursorDamage() { // this test verifies that damaging a cursor surface triggers a cursor changed on the server using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy pointerSpy(m_seat, &Seat::hasPointerChanged); QVERIFY(pointerSpy.isValid()); m_seatInterface->setHasPointer(true); QVERIFY(pointerSpy.wait()); // create pointer QScopedPointer p(m_seat->createPointer()); QVERIFY(p->isValid()); QSignalSpy enteredSpy(p.data(), &Pointer::entered); QVERIFY(enteredSpy.isValid()); // create surface QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(surfaceCreatedSpy.isValid()); m_compositor->createSurface(m_compositor); QVERIFY(surfaceCreatedSpy.wait()); SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value(); QVERIFY(serverSurface); // send enter to the surface m_seatInterface->setFocusedPointerSurface(serverSurface); QVERIFY(enteredSpy.wait()); // create a signal spy for the cursor changed signal auto pointer = m_seatInterface->focusedPointer(); QSignalSpy cursorChangedSpy(pointer, &PointerInterface::cursorChanged); QVERIFY(cursorChangedSpy.isValid()); // now let's set the cursor Surface *cursorSurface = m_compositor->createSurface(m_compositor); QVERIFY(cursorSurface); QImage red(QSize(10, 10), QImage::Format_ARGB32); red.fill(Qt::red); cursorSurface->attachBuffer(m_shm->createBuffer(red)); cursorSurface->damage(QRect(0, 0, 10, 10)); cursorSurface->commit(Surface::CommitFlag::None); p->setCursor(cursorSurface, QPoint(0, 0)); QVERIFY(cursorChangedSpy.wait()); QCOMPARE(pointer->cursor()->surface()->buffer()->data(), red); // and damage the surface QImage blue(QSize(10, 10), QImage::Format_ARGB32); blue.fill(Qt::blue); cursorSurface->attachBuffer(m_shm->createBuffer(blue)); cursorSurface->damage(QRect(0, 0, 10, 10)); cursorSurface->commit(Surface::CommitFlag::None); QVERIFY(cursorChangedSpy.wait()); QCOMPARE(pointer->cursor()->surface()->buffer()->data(), blue); } void TestWaylandSeat::testKeyboard() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy keyboardSpy(m_seat, SIGNAL(hasKeyboardChanged(bool))); QVERIFY(keyboardSpy.isValid()); m_seatInterface->setHasKeyboard(true); QVERIFY(keyboardSpy.wait()); // create the surface QSignalSpy surfaceCreatedSpy(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(surfaceCreatedSpy.isValid()); Surface *s = m_compositor->createSurface(m_compositor); QVERIFY(surfaceCreatedSpy.wait()); SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value(); QVERIFY(serverSurface); m_seatInterface->setFocusedKeyboardSurface(serverSurface); // no keyboard yet QCOMPARE(m_seatInterface->focusedKeyboardSurface(), serverSurface); QVERIFY(!m_seatInterface->focusedKeyboard()); Keyboard *keyboard = m_seat->createKeyboard(m_seat); QSignalSpy repeatInfoSpy(keyboard, &Keyboard::keyRepeatChanged); QVERIFY(repeatInfoSpy.isValid()); const Keyboard &ckeyboard = *keyboard; QVERIFY(keyboard->isValid()); QCOMPARE(keyboard->isKeyRepeatEnabled(), false); QCOMPARE(keyboard->keyRepeatDelay(), 0); QCOMPARE(keyboard->keyRepeatRate(), 0); wl_display_flush(m_connection->display()); QTest::qWait(100); QVERIFY(m_seatInterface->focusedKeyboard()); // we should get the repeat info announced QCOMPARE(repeatInfoSpy.count(), 1); QCOMPARE(keyboard->isKeyRepeatEnabled(), false); QCOMPARE(keyboard->keyRepeatDelay(), 0); QCOMPARE(keyboard->keyRepeatRate(), 0); // let's change repeat in server m_seatInterface->setKeyRepeatInfo(25, 660); m_seatInterface->focusedKeyboard()->client()->flush(); QVERIFY(repeatInfoSpy.wait()); QCOMPARE(repeatInfoSpy.count(), 2); QCOMPARE(keyboard->isKeyRepeatEnabled(), true); QCOMPARE(keyboard->keyRepeatRate(), 25); QCOMPARE(keyboard->keyRepeatDelay(), 660); m_seatInterface->setTimestamp(1); m_seatInterface->keyPressed(KEY_K); m_seatInterface->setTimestamp(2); m_seatInterface->keyPressed(KEY_D); m_seatInterface->setTimestamp(3); m_seatInterface->keyPressed(KEY_E); QSignalSpy modifierSpy(keyboard, SIGNAL(modifiersChanged(quint32,quint32,quint32,quint32))); QVERIFY(modifierSpy.isValid()); QSignalSpy enteredSpy(keyboard, SIGNAL(entered(quint32))); QVERIFY(enteredSpy.isValid()); m_seatInterface->setFocusedKeyboardSurface(serverSurface); QCOMPARE(m_seatInterface->focusedKeyboardSurface(), serverSurface); QCOMPARE(m_seatInterface->focusedKeyboard()->focusedSurface(), serverSurface); // we get the modifiers sent after the enter QVERIFY(modifierSpy.wait()); QCOMPARE(modifierSpy.count(), 1); QCOMPARE(modifierSpy.first().at(0).value(), quint32(0)); QCOMPARE(modifierSpy.first().at(1).value(), quint32(0)); QCOMPARE(modifierSpy.first().at(2).value(), quint32(0)); QCOMPARE(modifierSpy.first().at(3).value(), quint32(0)); QCOMPARE(enteredSpy.count(), 1); QCOMPARE(enteredSpy.first().first().value(), m_display->serial()); QSignalSpy keyChangedSpy(keyboard, SIGNAL(keyChanged(quint32,KWayland::Client::Keyboard::KeyState,quint32))); QVERIFY(keyChangedSpy.isValid()); m_seatInterface->setTimestamp(4); m_seatInterface->keyReleased(KEY_E); QVERIFY(keyChangedSpy.wait()); m_seatInterface->setTimestamp(5); m_seatInterface->keyReleased(KEY_D); QVERIFY(keyChangedSpy.wait()); m_seatInterface->setTimestamp(6); m_seatInterface->keyReleased(KEY_K); QVERIFY(keyChangedSpy.wait()); m_seatInterface->setTimestamp(7); m_seatInterface->keyPressed(KEY_F1); QVERIFY(keyChangedSpy.wait()); m_seatInterface->setTimestamp(8); m_seatInterface->keyReleased(KEY_F1); QVERIFY(keyChangedSpy.wait()); QCOMPARE(keyChangedSpy.count(), 5); QCOMPARE(keyChangedSpy.at(0).at(0).value(), quint32(KEY_E)); QCOMPARE(keyChangedSpy.at(0).at(1).value(), Keyboard::KeyState::Released); QCOMPARE(keyChangedSpy.at(0).at(2).value(), quint32(4)); QCOMPARE(keyChangedSpy.at(1).at(0).value(), quint32(KEY_D)); QCOMPARE(keyChangedSpy.at(1).at(1).value(), Keyboard::KeyState::Released); QCOMPARE(keyChangedSpy.at(1).at(2).value(), quint32(5)); QCOMPARE(keyChangedSpy.at(2).at(0).value(), quint32(KEY_K)); QCOMPARE(keyChangedSpy.at(2).at(1).value(), Keyboard::KeyState::Released); QCOMPARE(keyChangedSpy.at(2).at(2).value(), quint32(6)); QCOMPARE(keyChangedSpy.at(3).at(0).value(), quint32(KEY_F1)); QCOMPARE(keyChangedSpy.at(3).at(1).value(), Keyboard::KeyState::Pressed); QCOMPARE(keyChangedSpy.at(3).at(2).value(), quint32(7)); QCOMPARE(keyChangedSpy.at(4).at(0).value(), quint32(KEY_F1)); QCOMPARE(keyChangedSpy.at(4).at(1).value(), Keyboard::KeyState::Released); QCOMPARE(keyChangedSpy.at(4).at(2).value(), quint32(8)); m_seatInterface->updateKeyboardModifiers(1, 2, 3, 4); QVERIFY(modifierSpy.wait()); QCOMPARE(modifierSpy.count(), 2); QCOMPARE(modifierSpy.last().at(0).value(), quint32(1)); QCOMPARE(modifierSpy.last().at(1).value(), quint32(2)); QCOMPARE(modifierSpy.last().at(2).value(), quint32(3)); QCOMPARE(modifierSpy.last().at(3).value(), quint32(4)); QSignalSpy leftSpy(keyboard, SIGNAL(left(quint32))); QVERIFY(leftSpy.isValid()); m_seatInterface->setFocusedKeyboardSurface(nullptr); QVERIFY(!m_seatInterface->focusedKeyboardSurface()); QVERIFY(!m_seatInterface->focusedKeyboard()); QVERIFY(leftSpy.wait()); QCOMPARE(leftSpy.count(), 1); QCOMPARE(leftSpy.first().first().value(), m_display->serial()); QVERIFY(!keyboard->enteredSurface()); QVERIFY(!ckeyboard.enteredSurface()); // enter it again m_seatInterface->setFocusedKeyboardSurface(serverSurface); QVERIFY(modifierSpy.wait()); QCOMPARE(m_seatInterface->focusedKeyboardSurface(), serverSurface); QCOMPARE(m_seatInterface->focusedKeyboard()->focusedSurface(), serverSurface); QCOMPARE(enteredSpy.count(), 2); QCOMPARE(keyboard->enteredSurface(), s); QCOMPARE(ckeyboard.enteredSurface(), s); delete s; wl_display_flush(m_connection->display()); QTest::qWait(100); QVERIFY(!m_seatInterface->focusedKeyboardSurface()); QVERIFY(!m_seatInterface->focusedKeyboard()); // create a second Keyboard to verify that repeat info is announced properly Keyboard *keyboard2 = m_seat->createKeyboard(m_seat); QSignalSpy repeatInfoSpy2(keyboard2, &Keyboard::keyRepeatChanged); QVERIFY(repeatInfoSpy2.isValid()); QVERIFY(keyboard2->isValid()); QCOMPARE(keyboard2->isKeyRepeatEnabled(), false); QCOMPARE(keyboard2->keyRepeatDelay(), 0); QCOMPARE(keyboard2->keyRepeatRate(), 0); wl_display_flush(m_connection->display()); QVERIFY(repeatInfoSpy2.wait()); QCOMPARE(keyboard2->isKeyRepeatEnabled(), true); QCOMPARE(keyboard2->keyRepeatRate(), 25); QCOMPARE(keyboard2->keyRepeatDelay(), 660); } void TestWaylandSeat::testCast() { using namespace KWayland::Client; Registry registry; QSignalSpy seatSpy(®istry, SIGNAL(seatAnnounced(quint32,quint32))); registry.create(m_connection->display()); QVERIFY(registry.isValid()); registry.setup(); QVERIFY(seatSpy.wait()); Seat s; QVERIFY(!s.isValid()); auto wlSeat = registry.bindSeat(seatSpy.first().first().value(), seatSpy.first().last().value()); QVERIFY(wlSeat); s.setup(wlSeat); QVERIFY(s.isValid()); QCOMPARE((wl_seat*)s, wlSeat); const Seat &s2(s); QCOMPARE((wl_seat*)s2, wlSeat); } void TestWaylandSeat::testDestroy() { using namespace KWayland::Client; QSignalSpy keyboardSpy(m_seat, SIGNAL(hasKeyboardChanged(bool))); QVERIFY(keyboardSpy.isValid()); m_seatInterface->setHasKeyboard(true); QVERIFY(keyboardSpy.wait()); Keyboard *k = m_seat->createKeyboard(m_seat); QVERIFY(k->isValid()); QSignalSpy pointerSpy(m_seat, SIGNAL(hasPointerChanged(bool))); QVERIFY(pointerSpy.isValid()); m_seatInterface->setHasPointer(true); QVERIFY(pointerSpy.wait()); Pointer *p = m_seat->createPointer(m_seat); QVERIFY(p->isValid()); QSignalSpy touchSpy(m_seat, SIGNAL(hasTouchChanged(bool))); QVERIFY(touchSpy.isValid()); m_seatInterface->setHasTouch(true); QVERIFY(touchSpy.wait()); Touch *t = m_seat->createTouch(m_seat); QVERIFY(t->isValid()); delete m_compositor; m_compositor = nullptr; connect(m_connection, &ConnectionThread::connectionDied, m_seat, &Seat::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_shm, &ShmPool::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_subCompositor, &SubCompositor::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_queue, &EventQueue::destroy); QVERIFY(m_seat->isValid()); QSignalSpy connectionDiedSpy(m_connection, SIGNAL(connectionDied())); QVERIFY(connectionDiedSpy.isValid()); delete m_display; m_display = nullptr; m_compositorInterface = nullptr; m_seatInterface = nullptr; m_subCompositorInterface = nullptr; QVERIFY(connectionDiedSpy.wait()); // now the seat should be destroyed; QVERIFY(!m_seat->isValid()); QVERIFY(!k->isValid()); QVERIFY(!p->isValid()); QVERIFY(!t->isValid()); // calling destroy again should not fail m_seat->destroy(); k->destroy(); p->destroy(); t->destroy(); } void TestWaylandSeat::testSelection() { using namespace KWayland::Client; using namespace KWayland::Server; QScopedPointer ddmi(m_display->createDataDeviceManager()); ddmi->create(); Registry registry; QSignalSpy dataDeviceManagerSpy(®istry, SIGNAL(dataDeviceManagerAnnounced(quint32,quint32))); QVERIFY(dataDeviceManagerSpy.isValid()); registry.setEventQueue(m_queue); registry.create(m_connection->display()); QVERIFY(registry.isValid()); registry.setup(); QVERIFY(dataDeviceManagerSpy.wait()); QScopedPointer ddm(registry.createDataDeviceManager(dataDeviceManagerSpy.first().first().value(), dataDeviceManagerSpy.first().last().value())); QVERIFY(ddm->isValid()); QScopedPointer dd1(ddm->getDataDevice(m_seat)); QVERIFY(dd1->isValid()); QSignalSpy selectionSpy(dd1.data(), SIGNAL(selectionOffered(KWayland::Client::DataOffer*))); QVERIFY(selectionSpy.isValid()); QSignalSpy selectionClearedSpy(dd1.data(), SIGNAL(selectionCleared())); QVERIFY(selectionClearedSpy.isValid()); QSignalSpy surfaceCreatedSpy(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(surfaceCreatedSpy.isValid()); QScopedPointer surface(m_compositor->createSurface()); QVERIFY(surface->isValid()); QVERIFY(surfaceCreatedSpy.wait()); auto serverSurface = surfaceCreatedSpy.first().first().value(); m_seatInterface->setFocusedKeyboardSurface(serverSurface); QCOMPARE(m_seatInterface->focusedKeyboardSurface(), serverSurface); QVERIFY(!m_seatInterface->focusedKeyboard()); serverSurface->client()->flush(); QCoreApplication::processEvents(); QCoreApplication::processEvents(); QVERIFY(selectionSpy.isEmpty()); QVERIFY(selectionClearedSpy.isEmpty()); // now let's try to set a selection - we have keyboard focus, so it should be sent to us QScopedPointer ds(ddm->createDataSource()); QVERIFY(ds->isValid()); ds->offer(QStringLiteral("text/plain")); dd1->setSelection(0, ds.data()); QVERIFY(selectionSpy.wait()); QCOMPARE(selectionSpy.count(), 1); QVERIFY(selectionClearedSpy.isEmpty()); auto df = selectionSpy.first().first().value(); QCOMPARE(df->offeredMimeTypes().count(), 1); QCOMPARE(df->offeredMimeTypes().first().name(), QStringLiteral("text/plain")); // try to clear dd1->setSelection(0); QVERIFY(selectionClearedSpy.wait()); QCOMPARE(selectionClearedSpy.count(), 1); QCOMPARE(selectionSpy.count(), 1); // unset the keyboard focus m_seatInterface->setFocusedKeyboardSurface(nullptr); QVERIFY(!m_seatInterface->focusedKeyboardSurface()); QVERIFY(!m_seatInterface->focusedKeyboard()); serverSurface->client()->flush(); QCoreApplication::processEvents(); QCoreApplication::processEvents(); // try to set Selection dd1->setSelection(0, ds.data()); wl_display_flush(m_connection->display()); QCoreApplication::processEvents(); QCoreApplication::processEvents(); QCOMPARE(selectionSpy.count(), 1); } void TestWaylandSeat::testTouch() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy touchSpy(m_seat, SIGNAL(hasTouchChanged(bool))); QVERIFY(touchSpy.isValid()); m_seatInterface->setHasTouch(true); QVERIFY(touchSpy.wait()); // create the surface QSignalSpy surfaceCreatedSpy(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(surfaceCreatedSpy.isValid()); Surface *s = m_compositor->createSurface(m_compositor); QVERIFY(surfaceCreatedSpy.wait()); SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value(); QVERIFY(serverSurface); m_seatInterface->setFocusedTouchSurface(serverSurface); // no keyboard yet QCOMPARE(m_seatInterface->focusedTouchSurface(), serverSurface); QVERIFY(!m_seatInterface->focusedTouch()); QSignalSpy touchCreatedSpy(m_seatInterface, SIGNAL(touchCreated(KWayland::Server::TouchInterface*))); QVERIFY(touchCreatedSpy.isValid()); Touch *touch = m_seat->createTouch(m_seat); QVERIFY(touch->isValid()); QVERIFY(touchCreatedSpy.wait()); QVERIFY(m_seatInterface->focusedTouch()); QCOMPARE(touchCreatedSpy.first().first().value(), m_seatInterface->focusedTouch()); QSignalSpy sequenceStartedSpy(touch, SIGNAL(sequenceStarted(KWayland::Client::TouchPoint*))); QVERIFY(sequenceStartedSpy.isValid()); QSignalSpy sequenceEndedSpy(touch, SIGNAL(sequenceEnded())); QVERIFY(sequenceEndedSpy.isValid()); QSignalSpy sequenceCanceledSpy(touch, SIGNAL(sequenceCanceled())); QVERIFY(sequenceCanceledSpy.isValid()); QSignalSpy frameEndedSpy(touch, SIGNAL(frameEnded())); QVERIFY(frameEndedSpy.isValid()); QSignalSpy pointAddedSpy(touch, SIGNAL(pointAdded(KWayland::Client::TouchPoint*))); QVERIFY(pointAddedSpy.isValid()); QSignalSpy pointMovedSpy(touch, SIGNAL(pointMoved(KWayland::Client::TouchPoint*))); QVERIFY(pointMovedSpy.isValid()); QSignalSpy pointRemovedSpy(touch, SIGNAL(pointRemoved(KWayland::Client::TouchPoint*))); QVERIFY(pointRemovedSpy.isValid()); // try a few things m_seatInterface->setFocusedTouchSurfacePosition(QPointF(10, 20)); QCOMPARE(m_seatInterface->focusedTouchSurfacePosition(), QPointF(10, 20)); m_seatInterface->setTimestamp(1); QCOMPARE(m_seatInterface->touchDown(QPointF(15, 26)), 0); QVERIFY(sequenceStartedSpy.wait()); QCOMPARE(sequenceStartedSpy.count(), 1); QCOMPARE(sequenceEndedSpy.count(), 0); QCOMPARE(sequenceCanceledSpy.count(), 0); QCOMPARE(frameEndedSpy.count(), 0); QCOMPARE(pointAddedSpy.count(), 0); QCOMPARE(pointMovedSpy.count(), 0); QCOMPARE(pointRemovedSpy.count(), 0); TouchPoint *tp = sequenceStartedSpy.first().first().value(); QVERIFY(tp); QCOMPARE(tp->downSerial(), m_seatInterface->display()->serial()); QCOMPARE(tp->id(), 0); QVERIFY(tp->isDown()); QCOMPARE(tp->position(), QPointF(5, 6)); QCOMPARE(tp->positions().size(), 1); QCOMPARE(tp->time(), 1u); QCOMPARE(tp->timestamps().count(), 1); QCOMPARE(tp->upSerial(), 0u); QCOMPARE(tp->surface().data(), s); QCOMPARE(touch->sequence().count(), 1); QCOMPARE(touch->sequence().first(), tp); // let's end the frame m_seatInterface->touchFrame(); QVERIFY(frameEndedSpy.wait()); QCOMPARE(frameEndedSpy.count(), 1); // move the one point m_seatInterface->setTimestamp(2); m_seatInterface->touchMove(0, QPointF(10, 20)); m_seatInterface->touchFrame(); QVERIFY(frameEndedSpy.wait()); QCOMPARE(sequenceStartedSpy.count(), 1); QCOMPARE(sequenceEndedSpy.count(), 0); QCOMPARE(sequenceCanceledSpy.count(), 0); QCOMPARE(frameEndedSpy.count(), 2); QCOMPARE(pointAddedSpy.count(), 0); QCOMPARE(pointMovedSpy.count(), 1); QCOMPARE(pointRemovedSpy.count(), 0); QCOMPARE(pointMovedSpy.first().first().value(), tp); QCOMPARE(tp->id(), 0); QVERIFY(tp->isDown()); QCOMPARE(tp->position(), QPointF(0, 0)); QCOMPARE(tp->positions().size(), 2); QCOMPARE(tp->time(), 2u); QCOMPARE(tp->timestamps().count(), 2); QCOMPARE(tp->upSerial(), 0u); QCOMPARE(tp->surface().data(), s); // add onther point m_seatInterface->setTimestamp(3); QCOMPARE(m_seatInterface->touchDown(QPointF(15, 26)), 1); m_seatInterface->touchFrame(); QVERIFY(frameEndedSpy.wait()); QCOMPARE(sequenceStartedSpy.count(), 1); QCOMPARE(sequenceEndedSpy.count(), 0); QCOMPARE(sequenceCanceledSpy.count(), 0); QCOMPARE(frameEndedSpy.count(), 3); QCOMPARE(pointAddedSpy.count(), 1); QCOMPARE(pointMovedSpy.count(), 1); QCOMPARE(pointRemovedSpy.count(), 0); QCOMPARE(touch->sequence().count(), 2); QCOMPARE(touch->sequence().first(), tp); TouchPoint *tp2 = pointAddedSpy.first().first().value(); QVERIFY(tp2); QCOMPARE(touch->sequence().last(), tp2); QCOMPARE(tp2->id(), 1); QVERIFY(tp2->isDown()); QCOMPARE(tp2->position(), QPointF(5, 6)); QCOMPARE(tp2->positions().size(), 1); QCOMPARE(tp2->time(), 3u); QCOMPARE(tp2->timestamps().count(), 1); QCOMPARE(tp2->upSerial(), 0u); QCOMPARE(tp2->surface().data(), s); // send it an up m_seatInterface->setTimestamp(4); m_seatInterface->touchUp(1); m_seatInterface->touchFrame(); QVERIFY(frameEndedSpy.wait()); QCOMPARE(sequenceStartedSpy.count(), 1); QCOMPARE(sequenceEndedSpy.count(), 0); QCOMPARE(sequenceCanceledSpy.count(), 0); QCOMPARE(frameEndedSpy.count(), 4); QCOMPARE(pointAddedSpy.count(), 1); QCOMPARE(pointMovedSpy.count(), 1); QCOMPARE(pointRemovedSpy.count(), 1); QCOMPARE(pointRemovedSpy.first().first().value(), tp2); QCOMPARE(tp2->id(), 1); QVERIFY(!tp2->isDown()); QCOMPARE(tp2->position(), QPointF(5, 6)); QCOMPARE(tp2->positions().size(), 1); QCOMPARE(tp2->time(), 4u); QCOMPARE(tp2->timestamps().count(), 2); QCOMPARE(tp2->upSerial(), m_seatInterface->display()->serial()); QCOMPARE(tp2->surface().data(), s); // send another down and up m_seatInterface->setTimestamp(5); QCOMPARE(m_seatInterface->touchDown(QPointF(15, 26)), 1); m_seatInterface->touchFrame(); m_seatInterface->setTimestamp(6); m_seatInterface->touchUp(1); // and send an up for the first point m_seatInterface->touchUp(0); m_seatInterface->touchFrame(); QVERIFY(frameEndedSpy.wait()); QCOMPARE(sequenceStartedSpy.count(), 1); QCOMPARE(sequenceEndedSpy.count(), 1); QCOMPARE(sequenceCanceledSpy.count(), 0); QCOMPARE(frameEndedSpy.count(), 6); QCOMPARE(pointAddedSpy.count(), 2); QCOMPARE(pointMovedSpy.count(), 1); QCOMPARE(pointRemovedSpy.count(), 3); QCOMPARE(touch->sequence().count(), 3); QVERIFY(!touch->sequence().at(0)->isDown()); QVERIFY(!touch->sequence().at(1)->isDown()); QVERIFY(!touch->sequence().at(2)->isDown()); QVERIFY(!m_seatInterface->isTouchSequence()); // try cancel m_seatInterface->setFocusedTouchSurface(serverSurface, QPointF(15, 26)); m_seatInterface->setTimestamp(7); QCOMPARE(m_seatInterface->touchDown(QPointF(15, 26)), 0); m_seatInterface->touchFrame(); m_seatInterface->cancelTouchSequence(); QVERIFY(sequenceCanceledSpy.wait()); QCOMPARE(sequenceStartedSpy.count(), 2); QCOMPARE(sequenceEndedSpy.count(), 1); QCOMPARE(sequenceCanceledSpy.count(), 1); QCOMPARE(frameEndedSpy.count(), 7); QCOMPARE(pointAddedSpy.count(), 2); QCOMPARE(pointMovedSpy.count(), 1); QCOMPARE(pointRemovedSpy.count(), 3); QCOMPARE(touch->sequence().first()->position(), QPointF(0, 0)); } +void TestWaylandSeat::testDisconnect() +{ + // this test verifies that disconnecting the client cleans up correctly + using namespace KWayland::Client; + using namespace KWayland::Server; + QSignalSpy keyboardCreatedSpy(m_seatInterface, &SeatInterface::keyboardCreated); + QVERIFY(keyboardCreatedSpy.isValid()); + QSignalSpy pointerCreatedSpy(m_seatInterface, &SeatInterface::pointerCreated); + QVERIFY(pointerCreatedSpy.isValid()); + QSignalSpy touchCreatedSpy(m_seatInterface, &SeatInterface::touchCreated); + QVERIFY(touchCreatedSpy.isValid()); + + // create the things we need + m_seatInterface->setHasKeyboard(true); + m_seatInterface->setHasPointer(true); + m_seatInterface->setHasTouch(true); + QSignalSpy touchSpy(m_seat, &Seat::hasTouchChanged); + QVERIFY(touchSpy.isValid()); + QVERIFY(touchSpy.wait()); + + QScopedPointer keyboard(m_seat->createKeyboard()); + QVERIFY(!keyboard.isNull()); + QVERIFY(keyboardCreatedSpy.wait()); + auto serverKeyboard = keyboardCreatedSpy.first().first().value(); + QVERIFY(serverKeyboard); + + QScopedPointer pointer(m_seat->createPointer()); + QVERIFY(!pointer.isNull()); + QVERIFY(pointerCreatedSpy.wait()); + auto serverPointer = pointerCreatedSpy.first().first().value(); + QVERIFY(serverPointer); + + QScopedPointer touch(m_seat->createTouch()); + QVERIFY(!touch.isNull()); + QVERIFY(touchCreatedSpy.wait()); + auto serverTouch = touchCreatedSpy.first().first().value(); + QVERIFY(serverTouch); + + // setup destroys + QSignalSpy keyboardDestroyedSpy(serverKeyboard, &QObject::destroyed); + QVERIFY(keyboardDestroyedSpy.isValid()); + QSignalSpy pointerDestroyedSpy(serverPointer, &QObject::destroyed); + QVERIFY(pointerDestroyedSpy.isValid()); + QSignalSpy touchDestroyedSpy(serverTouch, &QObject::destroyed); + QVERIFY(touchDestroyedSpy.isValid()); + QSignalSpy clientDisconnectedSpy(serverKeyboard->client(), &ClientConnection::disconnected); + QVERIFY(clientDisconnectedSpy.isValid()); + + if (m_connection) { + m_connection->deleteLater(); + m_connection = nullptr; + } + QVERIFY(clientDisconnectedSpy.wait()); + QCOMPARE(clientDisconnectedSpy.count(), 1); + QCOMPARE(keyboardDestroyedSpy.count(), 0); + QCOMPARE(pointerDestroyedSpy.count(), 0); + QCOMPARE(touchDestroyedSpy.count(), 0); + QVERIFY(keyboardDestroyedSpy.wait()); + QCOMPARE(keyboardDestroyedSpy.count(), 1); + QCOMPARE(pointerDestroyedSpy.count(), 1); + QCOMPARE(touchDestroyedSpy.count(), 1); + + keyboard->destroy(); + pointer->destroy(); + touch->destroy(); + m_compositor->destroy(); + m_seat->destroy(); + m_shm->destroy(); + m_subCompositor->destroy(); + m_queue->destroy(); +} + QTEST_GUILESS_MAIN(TestWaylandSeat) #include "test_wayland_seat.moc" diff --git a/autotests/client/test_wayland_shell.cpp b/autotests/client/test_wayland_shell.cpp index 4ccaff0..55db68b 100644 --- a/autotests/client/test_wayland_shell.cpp +++ b/autotests/client/test_wayland_shell.cpp @@ -1,705 +1,745 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ // Qt #include // KWin #include "../../src/client/compositor.h" #include "../../src/client/connection_thread.h" #include "../../src/client/event_queue.h" #include "../../src/client/pointer.h" #include "../../src/client/seat.h" #include "../../src/client/shell.h" #include "../../src/client/surface.h" #include "../../src/client/registry.h" #include "../../src/server/buffer_interface.h" #include "../../src/server/compositor_interface.h" #include "../../src/server/display.h" #include "../../src/server/seat_interface.h" #include "../../src/server/shell_interface.h" #include "../../src/server/surface_interface.h" // Wayland #include Q_DECLARE_METATYPE(Qt::Edges) class TestWaylandShell : public QObject { Q_OBJECT public: explicit TestWaylandShell(QObject *parent = nullptr); private Q_SLOTS: void initTestCase(); void init(); void cleanup(); void testCreateMultiple(); void testFullscreen(); void testMaximize(); void testToplevel(); void testTransient_data(); void testTransient(); void testPing(); void testTitle(); void testWindowClass(); void testDestroy(); void testCast(); void testMove(); void testResize_data(); void testResize(); + void testDisconnect(); private: KWayland::Server::Display *m_display; KWayland::Server::CompositorInterface *m_compositorInterface; KWayland::Server::ShellInterface *m_shellInterface; KWayland::Server::SeatInterface *m_seatInterface; KWayland::Client::ConnectionThread *m_connection; KWayland::Client::Compositor *m_compositor; KWayland::Client::Shell *m_shell; KWayland::Client::Seat *m_seat; KWayland::Client::Pointer *m_pointer; KWayland::Client::EventQueue *m_queue; QThread *m_thread; }; static const QString s_socketName = QStringLiteral("kwin-test-wayland-shell-0"); TestWaylandShell::TestWaylandShell(QObject *parent) : QObject(parent) , m_display(nullptr) , m_compositorInterface(nullptr) , m_shellInterface(nullptr) , m_seatInterface(nullptr) , m_connection(nullptr) , m_compositor(nullptr) , m_shell(nullptr) , m_seat(nullptr) , m_pointer(nullptr) , m_queue(nullptr) , m_thread(nullptr) { } void TestWaylandShell::initTestCase() { qRegisterMetaType(); } void TestWaylandShell::init() { using namespace KWayland::Server; delete m_display; m_display = new Display(this); m_display->setSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_compositorInterface = m_display->createCompositor(m_display); QVERIFY(m_compositorInterface); m_compositorInterface->create(); QVERIFY(m_compositorInterface->isValid()); m_shellInterface = m_display->createShell(m_display); QVERIFY(m_shellInterface); m_shellInterface->create(); QVERIFY(m_shellInterface->isValid()); m_seatInterface = m_display->createSeat(m_display); QVERIFY(m_seatInterface); m_seatInterface->setHasPointer(true); m_seatInterface->create(); QVERIFY(m_seatInterface->isValid()); // setup connection m_connection = new KWayland::Client::ConnectionThread; QSignalSpy connectedSpy(m_connection, SIGNAL(connected())); m_connection->setSocketName(s_socketName); m_thread = new QThread(this); m_connection->moveToThread(m_thread); m_thread->start(); m_connection->initConnection(); QVERIFY(connectedSpy.wait()); m_queue = new KWayland::Client::EventQueue(this); QVERIFY(!m_queue->isValid()); m_queue->setup(m_connection); QVERIFY(m_queue->isValid()); using namespace KWayland::Client; KWayland::Client::Registry registry; QSignalSpy interfacesAnnouncedSpy(®istry, &Registry::interfacesAnnounced); QVERIFY(interfacesAnnouncedSpy.isValid()); QSignalSpy compositorSpy(®istry, SIGNAL(compositorAnnounced(quint32,quint32))); QSignalSpy shellSpy(®istry, SIGNAL(shellAnnounced(quint32,quint32))); QSignalSpy seatAnnouncedSpy(®istry, &Registry::seatAnnounced); QVERIFY(seatAnnouncedSpy.isValid()); QVERIFY(!registry.eventQueue()); registry.setEventQueue(m_queue); QCOMPARE(registry.eventQueue(), m_queue); registry.create(m_connection->display()); QVERIFY(registry.isValid()); registry.setup(); QVERIFY(interfacesAnnouncedSpy.wait()); m_compositor = new KWayland::Client::Compositor(this); m_compositor->setup(registry.bindCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value())); QVERIFY(m_compositor->isValid()); if (shellSpy.isEmpty()) { QVERIFY(shellSpy.wait()); } m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); QVERIFY(m_shell->isValid()); QVERIFY(!seatAnnouncedSpy.isEmpty()); m_seat = registry.createSeat(seatAnnouncedSpy.first().first().value(), seatAnnouncedSpy.first().last().value(), this); QVERIFY(seatAnnouncedSpy.isValid()); QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); QVERIFY(hasPointerSpy.isValid()); QVERIFY(hasPointerSpy.wait()); QVERIFY(hasPointerSpy.first().first().toBool()); m_pointer = m_seat->createPointer(m_seat); QVERIFY(m_pointer->isValid()); } void TestWaylandShell::cleanup() { if (m_pointer) { delete m_pointer; m_pointer = nullptr; } if (m_seat) { delete m_seat; m_seat = nullptr; } if (m_shell) { delete m_shell; m_shell = nullptr; } if (m_compositor) { delete m_compositor; m_compositor = nullptr; } if (m_queue) { delete m_queue; m_queue = nullptr; } if (m_connection) { m_connection->deleteLater(); m_connection = nullptr; } if (m_thread) { m_thread->quit(); m_thread->wait(); delete m_thread; m_thread = nullptr; } delete m_seatInterface; m_seatInterface = nullptr; delete m_shellInterface; m_shellInterface = nullptr; delete m_compositorInterface; m_compositorInterface = nullptr; delete m_display; m_display = nullptr; } void TestWaylandShell::testCreateMultiple() { using namespace KWayland::Server; using namespace KWayland::Client; QScopedPointer s1(m_compositor->createSurface()); QScopedPointer s2(m_compositor->createSurface()); QVERIFY(!s1.isNull()); QVERIFY(s1->isValid()); QVERIFY(!s2.isNull()); QVERIFY(s2->isValid()); QSignalSpy serverSurfaceSpy(m_shellInterface, SIGNAL(surfaceCreated(KWayland::Server::ShellSurfaceInterface*))); QVERIFY(serverSurfaceSpy.isValid()); QScopedPointer surface1(m_shell->createSurface(s1.data())); QVERIFY(!surface1.isNull()); QVERIFY(surface1->isValid()); QVERIFY(serverSurfaceSpy.wait()); QCOMPARE(serverSurfaceSpy.count(), 1); QScopedPointer surface2(m_shell->createSurface(s2.data())); QVERIFY(!surface2.isNull()); QVERIFY(surface2->isValid()); QVERIFY(serverSurfaceSpy.wait()); QCOMPARE(serverSurfaceSpy.count(), 2); // try creating for one which already exist should not be possible QScopedPointer surface3(m_shell->createSurface(s2.data())); QVERIFY(!surface3.isNull()); QVERIFY(surface3->isValid()); QVERIFY(!serverSurfaceSpy.wait(100)); QCOMPARE(serverSurfaceSpy.count(), 2); } void TestWaylandShell::testFullscreen() { using namespace KWayland::Server; QScopedPointer s(m_compositor->createSurface()); QVERIFY(!s.isNull()); QVERIFY(s->isValid()); KWayland::Client::ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); QSignalSpy sizeSpy(surface, SIGNAL(sizeChanged(QSize))); QVERIFY(sizeSpy.isValid()); QCOMPARE(surface->size(), QSize()); QSignalSpy serverSurfaceSpy(m_shellInterface, SIGNAL(surfaceCreated(KWayland::Server::ShellSurfaceInterface*))); QVERIFY(serverSurfaceSpy.isValid()); QVERIFY(serverSurfaceSpy.wait()); ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); QVERIFY(serverSurface); QVERIFY(serverSurface->parentResource()); QSignalSpy fullscreenSpy(serverSurface, SIGNAL(fullscreenChanged(bool))); QVERIFY(fullscreenSpy.isValid()); surface->setFullscreen(); QVERIFY(fullscreenSpy.wait()); QCOMPARE(fullscreenSpy.count(), 1); QVERIFY(fullscreenSpy.first().first().toBool()); serverSurface->requestSize(QSize(1024, 768)); QVERIFY(sizeSpy.wait()); QCOMPARE(sizeSpy.count(), 1); QCOMPARE(sizeSpy.first().first().toSize(), QSize(1024, 768)); QCOMPARE(surface->size(), QSize(1024, 768)); // set back to toplevel fullscreenSpy.clear(); wl_shell_surface_set_toplevel(*surface); QVERIFY(fullscreenSpy.wait()); QCOMPARE(fullscreenSpy.count(), 1); QVERIFY(!fullscreenSpy.first().first().toBool()); } void TestWaylandShell::testMaximize() { using namespace KWayland::Server; QScopedPointer s(m_compositor->createSurface()); QVERIFY(!s.isNull()); QVERIFY(s->isValid()); KWayland::Client::ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); QSignalSpy sizeSpy(surface, SIGNAL(sizeChanged(QSize))); QVERIFY(sizeSpy.isValid()); QCOMPARE(surface->size(), QSize()); QSignalSpy serverSurfaceSpy(m_shellInterface, SIGNAL(surfaceCreated(KWayland::Server::ShellSurfaceInterface*))); QVERIFY(serverSurfaceSpy.isValid()); QVERIFY(serverSurfaceSpy.wait()); ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); QVERIFY(serverSurface); QVERIFY(serverSurface->parentResource()); QSignalSpy maximizedSpy(serverSurface, SIGNAL(maximizedChanged(bool))); QVERIFY(maximizedSpy.isValid()); surface->setMaximized(); QVERIFY(maximizedSpy.wait()); QCOMPARE(maximizedSpy.count(), 1); QVERIFY(maximizedSpy.first().first().toBool()); serverSurface->requestSize(QSize(1024, 768)); QVERIFY(sizeSpy.wait()); QCOMPARE(sizeSpy.count(), 1); QCOMPARE(sizeSpy.first().first().toSize(), QSize(1024, 768)); QCOMPARE(surface->size(), QSize(1024, 768)); // set back to toplevel maximizedSpy.clear(); wl_shell_surface_set_toplevel(*surface); QVERIFY(maximizedSpy.wait()); QCOMPARE(maximizedSpy.count(), 1); QVERIFY(!maximizedSpy.first().first().toBool()); } void TestWaylandShell::testToplevel() { using namespace KWayland::Server; QScopedPointer s(m_compositor->createSurface()); QVERIFY(!s.isNull()); QVERIFY(s->isValid()); KWayland::Client::ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); QSignalSpy sizeSpy(surface, SIGNAL(sizeChanged(QSize))); QVERIFY(sizeSpy.isValid()); QCOMPARE(surface->size(), QSize()); QSignalSpy serverSurfaceSpy(m_shellInterface, SIGNAL(surfaceCreated(KWayland::Server::ShellSurfaceInterface*))); QVERIFY(serverSurfaceSpy.isValid()); QVERIFY(serverSurfaceSpy.wait()); ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); QVERIFY(serverSurface); QVERIFY(serverSurface->parentResource()); QSignalSpy toplevelSpy(serverSurface, SIGNAL(toplevelChanged(bool))); QVERIFY(toplevelSpy.isValid()); surface->setFullscreen(); QVERIFY(toplevelSpy.wait()); QCOMPARE(toplevelSpy.count(), 1); QVERIFY(!toplevelSpy.first().first().toBool()); toplevelSpy.clear(); surface->setToplevel(); QVERIFY(toplevelSpy.wait()); QCOMPARE(toplevelSpy.count(), 1); QVERIFY(toplevelSpy.first().first().toBool()); serverSurface->requestSize(QSize(1024, 768)); QVERIFY(sizeSpy.wait()); QCOMPARE(sizeSpy.count(), 1); QCOMPARE(sizeSpy.first().first().toSize(), QSize(1024, 768)); QCOMPARE(surface->size(), QSize(1024, 768)); // set back to fullscreen toplevelSpy.clear(); surface->setFullscreen(); QVERIFY(toplevelSpy.wait()); QCOMPARE(toplevelSpy.count(), 1); QVERIFY(!toplevelSpy.first().first().toBool()); } void TestWaylandShell::testTransient_data() { QTest::addColumn("keyboardFocus"); QTest::newRow("focus") << true; QTest::newRow("no focus") << false; } void TestWaylandShell::testTransient() { using namespace KWayland::Server; using namespace KWayland::Client; QScopedPointer s(m_compositor->createSurface()); QVERIFY(!s.isNull()); QVERIFY(s->isValid()); ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); QSignalSpy serverSurfaceSpy(m_shellInterface, &ShellInterface::surfaceCreated); QVERIFY(serverSurfaceSpy.isValid()); QVERIFY(serverSurfaceSpy.wait()); ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); QVERIFY(serverSurface); QSignalSpy acceptsKeyboardFocusChangedSpy(serverSurface, &ShellSurfaceInterface::acceptsKeyboardFocusChanged); QVERIFY(acceptsKeyboardFocusChangedSpy.isValid()); QCOMPARE(serverSurface->isToplevel(), true); QCOMPARE(serverSurface->isPopup(), false); QCOMPARE(serverSurface->isTransient(), false); QCOMPARE(serverSurface->transientFor(), QPointer()); QCOMPARE(serverSurface->transientOffset(), QPoint()); QVERIFY(serverSurface->acceptsKeyboardFocus()); QVERIFY(acceptsKeyboardFocusChangedSpy.isEmpty()); QSignalSpy transientSpy(serverSurface, &ShellSurfaceInterface::transientChanged); QVERIFY(transientSpy.isValid()); QSignalSpy transientOffsetSpy(serverSurface, &ShellSurfaceInterface::transientOffsetChanged); QVERIFY(transientOffsetSpy.isValid()); QSignalSpy transientForChangedSpy(serverSurface, &ShellSurfaceInterface::transientForChanged); QVERIFY(transientForChangedSpy.isValid()); QScopedPointer s2(m_compositor->createSurface()); m_shell->createSurface(s2.data(), m_shell); serverSurfaceSpy.clear(); QVERIFY(serverSurfaceSpy.wait()); ShellSurfaceInterface *serverSurface2 = serverSurfaceSpy.first().first().value(); QVERIFY(serverSurface2 != serverSurface); QVERIFY(serverSurface2); QVERIFY(serverSurface2->acceptsKeyboardFocus()); QFETCH(bool, keyboardFocus); surface->setTransient(s2.data(), QPoint(10, 20), keyboardFocus ? ShellSurface::TransientFlag::Default : ShellSurface::TransientFlag::NoFocus); QVERIFY(transientSpy.wait()); QCOMPARE(transientSpy.count(), 1); QCOMPARE(transientSpy.first().first().toBool(), true); QCOMPARE(transientOffsetSpy.count(), 1); QCOMPARE(transientOffsetSpy.first().first().toPoint(), QPoint(10, 20)); QCOMPARE(transientForChangedSpy.count(), 1); QCOMPARE(serverSurface->isToplevel(), true); QCOMPARE(serverSurface->isPopup(), false); QCOMPARE(serverSurface->isTransient(), true); QCOMPARE(serverSurface->transientFor(), QPointer(serverSurface2->surface())); QCOMPARE(serverSurface->transientOffset(), QPoint(10, 20)); QCOMPARE(serverSurface->acceptsKeyboardFocus(), keyboardFocus); QCOMPARE(acceptsKeyboardFocusChangedSpy.isEmpty(), keyboardFocus); QCOMPARE(acceptsKeyboardFocusChangedSpy.count(), keyboardFocus ? 0 : 1); QCOMPARE(serverSurface2->isToplevel(), true); QCOMPARE(serverSurface2->isPopup(), false); QCOMPARE(serverSurface2->isTransient(), false); QCOMPARE(serverSurface2->transientFor(), QPointer()); QCOMPARE(serverSurface2->transientOffset(), QPoint()); QVERIFY(serverSurface2->acceptsKeyboardFocus()); } void TestWaylandShell::testPing() { using namespace KWayland::Server; QScopedPointer s(m_compositor->createSurface()); QVERIFY(!s.isNull()); QVERIFY(s->isValid()); KWayland::Client::ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); QSignalSpy pingSpy(surface, SIGNAL(pinged())); QSignalSpy serverSurfaceSpy(m_shellInterface, SIGNAL(surfaceCreated(KWayland::Server::ShellSurfaceInterface*))); QVERIFY(serverSurfaceSpy.isValid()); QVERIFY(serverSurfaceSpy.wait()); ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); QVERIFY(serverSurface); QSignalSpy pingTimeoutSpy(serverSurface, SIGNAL(pingTimeout())); QVERIFY(pingTimeoutSpy.isValid()); QSignalSpy pongSpy(serverSurface, SIGNAL(pongReceived())); QVERIFY(pongSpy.isValid()); serverSurface->ping(); QVERIFY(pingSpy.wait()); wl_display_flush(m_connection->display()); if (pongSpy.isEmpty()) { QVERIFY(pongSpy.wait()); } QVERIFY(!pongSpy.isEmpty()); QVERIFY(pingTimeoutSpy.isEmpty()); // evil trick - timeout of zero will make it not get the pong serverSurface->setPingTimeout(0); pongSpy.clear(); pingTimeoutSpy.clear(); serverSurface->ping(); QTest::qWait(100); if (pingTimeoutSpy.isEmpty()) { QVERIFY(pingTimeoutSpy.wait()); } QCOMPARE(pingTimeoutSpy.count(), 1); QVERIFY(pongSpy.isEmpty()); } void TestWaylandShell::testTitle() { using namespace KWayland::Server; QScopedPointer s(m_compositor->createSurface()); QVERIFY(!s.isNull()); QVERIFY(s->isValid()); KWayland::Client::ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); QSignalSpy serverSurfaceSpy(m_shellInterface, SIGNAL(surfaceCreated(KWayland::Server::ShellSurfaceInterface*))); QVERIFY(serverSurfaceSpy.isValid()); QVERIFY(serverSurfaceSpy.wait()); ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); QVERIFY(serverSurface); QSignalSpy titleSpy(serverSurface, SIGNAL(titleChanged(QString))); QVERIFY(titleSpy.isValid()); QString testTitle = QStringLiteral("fooBar"); QVERIFY(serverSurface->title().isNull()); wl_shell_surface_set_title(*(const KWayland::Client::ShellSurface *)surface, testTitle.toUtf8().constData()); QVERIFY(titleSpy.wait()); QCOMPARE(serverSurface->title(), testTitle); QCOMPARE(titleSpy.first().first().toString(), testTitle); } void TestWaylandShell::testWindowClass() { using namespace KWayland::Server; QScopedPointer s(m_compositor->createSurface()); QVERIFY(!s.isNull()); QVERIFY(s->isValid()); KWayland::Client::ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); QSignalSpy serverSurfaceSpy(m_shellInterface, SIGNAL(surfaceCreated(KWayland::Server::ShellSurfaceInterface*))); QVERIFY(serverSurfaceSpy.isValid()); QVERIFY(serverSurfaceSpy.wait()); ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); QVERIFY(serverSurface); QSignalSpy windowClassSpy(serverSurface, SIGNAL(windowClassChanged(QByteArray))); QVERIFY(windowClassSpy.isValid()); QByteArray testClass = QByteArrayLiteral("fooBar"); QVERIFY(serverSurface->windowClass().isNull()); wl_shell_surface_set_class(*surface, testClass.constData()); QVERIFY(windowClassSpy.wait()); QCOMPARE(serverSurface->windowClass(), testClass); QCOMPARE(windowClassSpy.first().first().toByteArray(), testClass); } void TestWaylandShell::testDestroy() { using namespace KWayland::Client; QScopedPointer s(m_compositor->createSurface()); QVERIFY(!s.isNull()); QVERIFY(s->isValid()); ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); QVERIFY(surface->isValid()); connect(m_connection, &ConnectionThread::connectionDied, m_shell, &Shell::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_pointer, &Pointer::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_seat, &Seat::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_compositor, &Compositor::destroy); connect(m_connection, &ConnectionThread::connectionDied, s.data(), &Surface::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_queue, &EventQueue::destroy); QSignalSpy connectionDiedSpy(m_connection, SIGNAL(connectionDied())); QVERIFY(connectionDiedSpy.isValid()); delete m_display; m_display = nullptr; m_compositorInterface = nullptr; m_shellInterface = nullptr; m_seatInterface = nullptr; QVERIFY(connectionDiedSpy.wait()); QVERIFY(!m_shell->isValid()); QVERIFY(!surface->isValid()); m_shell->destroy(); surface->destroy(); } void TestWaylandShell::testCast() { using namespace KWayland::Client; Registry registry; QSignalSpy shellSpy(®istry, SIGNAL(shellAnnounced(quint32,quint32))); registry.setEventQueue(m_queue); registry.create(m_connection->display()); QVERIFY(registry.isValid()); registry.setup(); QVERIFY(shellSpy.wait()); Shell s; auto wlShell = registry.bindShell(shellSpy.first().first().value(), shellSpy.first().last().value()); m_queue->addProxy(wlShell); QVERIFY(wlShell); QVERIFY(!s.isValid()); s.setup(wlShell); QVERIFY(s.isValid()); QCOMPARE((wl_shell*)s, wlShell); const Shell &s2(s); QCOMPARE((wl_shell*)s2, wlShell); } void TestWaylandShell::testMove() { using namespace KWayland::Client; using namespace KWayland::Server; QScopedPointer s(m_compositor->createSurface()); QVERIFY(!s.isNull()); QVERIFY(s->isValid()); ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); QSignalSpy serverSurfaceSpy(m_shellInterface, &ShellInterface::surfaceCreated); QVERIFY(serverSurfaceSpy.isValid()); QVERIFY(serverSurfaceSpy.wait()); ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); QVERIFY(serverSurface); QSignalSpy moveRequestedSpy(serverSurface, &ShellSurfaceInterface::moveRequested); QVERIFY(moveRequestedSpy.isValid()); QSignalSpy pointerButtonChangedSpy(m_pointer, &Pointer::buttonStateChanged); QVERIFY(pointerButtonChangedSpy.isValid()); m_seatInterface->setFocusedPointerSurface(serverSurface->surface()); m_seatInterface->pointerButtonPressed(Qt::LeftButton); QVERIFY(pointerButtonChangedSpy.wait()); surface->requestMove(m_seat, pointerButtonChangedSpy.first().first().value()); QVERIFY(moveRequestedSpy.wait()); QCOMPARE(moveRequestedSpy.count(), 1); QCOMPARE(moveRequestedSpy.first().at(0).value(), m_seatInterface); QCOMPARE(moveRequestedSpy.first().at(1).value(), m_seatInterface->pointerButtonSerial(Qt::LeftButton)); } void TestWaylandShell::testResize_data() { QTest::addColumn("resizeEdge"); QTest::addColumn("expectedEdge"); QTest::newRow("None") << Qt::Edges() << Qt::Edges(); QTest::newRow("Top") << Qt::Edges(Qt::TopEdge) << Qt::Edges(Qt::TopEdge); QTest::newRow("Bottom") << Qt::Edges(Qt::BottomEdge) << Qt::Edges(Qt::BottomEdge); QTest::newRow("Left") << Qt::Edges(Qt::LeftEdge) << Qt::Edges(Qt::LeftEdge); QTest::newRow("Right") << Qt::Edges(Qt::RightEdge) << Qt::Edges(Qt::RightEdge); QTest::newRow("Top Left") << Qt::Edges(Qt::TopEdge | Qt::LeftEdge) << Qt::Edges(Qt::TopEdge | Qt::LeftEdge); QTest::newRow("Top Right") << Qt::Edges(Qt::TopEdge | Qt::RightEdge) << Qt::Edges(Qt::TopEdge | Qt::RightEdge); QTest::newRow("Bottom Left") << Qt::Edges(Qt::BottomEdge | Qt::LeftEdge) << Qt::Edges(Qt::BottomEdge | Qt::LeftEdge); QTest::newRow("Bottom Right") << Qt::Edges(Qt::BottomEdge | Qt::RightEdge) << Qt::Edges(Qt::BottomEdge | Qt::RightEdge); // invalid combinations QTest::newRow("Top Bottom") << Qt::Edges(Qt::TopEdge | Qt::BottomEdge) << Qt::Edges(); QTest::newRow("Left Right") << Qt::Edges(Qt::RightEdge | Qt::LeftEdge) << Qt::Edges(); QTest::newRow("Top Bottom Right") << Qt::Edges(Qt::TopEdge | Qt::BottomEdge | Qt::RightEdge) << Qt::Edges(); QTest::newRow("Top Bottom Left") << Qt::Edges(Qt::TopEdge | Qt::BottomEdge | Qt::LeftEdge) << Qt::Edges(); QTest::newRow("Left Right Top") << Qt::Edges(Qt::RightEdge | Qt::LeftEdge | Qt::TopEdge) << Qt::Edges(); QTest::newRow("Left Right Bottom") << Qt::Edges(Qt::RightEdge | Qt::LeftEdge | Qt::BottomEdge) << Qt::Edges(); QTest::newRow("All") << Qt::Edges(Qt::RightEdge | Qt::LeftEdge | Qt::BottomEdge | Qt::TopEdge) << Qt::Edges(); } void TestWaylandShell::testResize() { using namespace KWayland::Client; using namespace KWayland::Server; QScopedPointer s(m_compositor->createSurface()); QVERIFY(!s.isNull()); QVERIFY(s->isValid()); ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); QSignalSpy serverSurfaceSpy(m_shellInterface, &ShellInterface::surfaceCreated); QVERIFY(serverSurfaceSpy.isValid()); QVERIFY(serverSurfaceSpy.wait()); ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); QVERIFY(serverSurface); QSignalSpy resizeRequestedSpy(serverSurface, &ShellSurfaceInterface::resizeRequested); QVERIFY(resizeRequestedSpy.isValid()); QSignalSpy pointerButtonChangedSpy(m_pointer, &Pointer::buttonStateChanged); QVERIFY(pointerButtonChangedSpy.isValid()); m_seatInterface->setFocusedPointerSurface(serverSurface->surface()); m_seatInterface->pointerButtonPressed(Qt::LeftButton); QVERIFY(pointerButtonChangedSpy.wait()); QFETCH(Qt::Edges, resizeEdge); surface->requestResize(m_seat, pointerButtonChangedSpy.first().first().value(), resizeEdge); QVERIFY(resizeRequestedSpy.wait()); QCOMPARE(resizeRequestedSpy.count(), 1); QCOMPARE(resizeRequestedSpy.first().at(0).value(), m_seatInterface); QCOMPARE(resizeRequestedSpy.first().at(1).value(), m_seatInterface->pointerButtonSerial(Qt::LeftButton)); QTEST(resizeRequestedSpy.first().at(2).value(), "expectedEdge"); } +void TestWaylandShell::testDisconnect() +{ + // this test verifies that the server side correctly tears down the resources when the client disconnects + using namespace KWayland::Client; + using namespace KWayland::Server; + QScopedPointer s(m_compositor->createSurface()); + QVERIFY(!s.isNull()); + QVERIFY(s->isValid()); + QScopedPointer surface(m_shell->createSurface(s.data(), m_shell)); + QSignalSpy serverSurfaceSpy(m_shellInterface, &ShellInterface::surfaceCreated); + QVERIFY(serverSurfaceSpy.isValid()); + QVERIFY(serverSurfaceSpy.wait()); + ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); + QVERIFY(serverSurface); + + // destroy client + QSignalSpy clientDisconnectedSpy(serverSurface->client(), &ClientConnection::disconnected); + QVERIFY(clientDisconnectedSpy.isValid()); + QSignalSpy shellSurfaceDestroyedSpy(serverSurface, &QObject::destroyed); + QVERIFY(shellSurfaceDestroyedSpy.isValid()); + if (m_connection) { + m_connection->deleteLater(); + m_connection = nullptr; + } + QVERIFY(clientDisconnectedSpy.wait()); + QCOMPARE(clientDisconnectedSpy.count(), 1); + QCOMPARE(shellSurfaceDestroyedSpy.count(), 0); + QVERIFY(shellSurfaceDestroyedSpy.wait()); + QCOMPARE(shellSurfaceDestroyedSpy.count(), 1); + + s->destroy(); + surface->destroy(); + m_shell->destroy(); + m_compositor->destroy(); + m_pointer->destroy(); + m_seat->destroy(); + m_queue->destroy(); +} + QTEST_GUILESS_MAIN(TestWaylandShell) #include "test_wayland_shell.moc" diff --git a/autotests/client/test_wayland_surface.cpp b/autotests/client/test_wayland_surface.cpp index ad2d276..890ec43 100644 --- a/autotests/client/test_wayland_surface.cpp +++ b/autotests/client/test_wayland_surface.cpp @@ -1,877 +1,913 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ // Qt #include #include #include // KWin #include "../../src/client/compositor.h" #include "../../src/client/connection_thread.h" #include "../../src/client/event_queue.h" #include "../../src/client/surface.h" #include "../../src/client/region.h" #include "../../src/client/registry.h" #include "../../src/client/shm_pool.h" #include "../../src/server/buffer_interface.h" #include "../../src/server/compositor_interface.h" #include "../../src/server/display.h" #include "../../src/server/surface_interface.h" // Wayland #include class TestWaylandSurface : public QObject { Q_OBJECT public: explicit TestWaylandSurface(QObject *parent = nullptr); private Q_SLOTS: void init(); void cleanup(); void testStaticAccessor(); void testDamage(); void testFrameCallback(); void testAttachBuffer(); void testMultipleSurfaces(); void testOpaque(); void testInput(); void testScale(); void testDestroy(); void testUnmapOfNotMappedSurface(); void testDamageTracking(); void testSurfaceAt(); void testDestroyAttachedBuffer(); + void testDisconnect(); private: KWayland::Server::Display *m_display; KWayland::Server::CompositorInterface *m_compositorInterface; KWayland::Client::ConnectionThread *m_connection; KWayland::Client::Compositor *m_compositor; KWayland::Client::ShmPool *m_shm; KWayland::Client::EventQueue *m_queue; QThread *m_thread; }; static const QString s_socketName = QStringLiteral("kwin-test-wayland-surface-0"); TestWaylandSurface::TestWaylandSurface(QObject *parent) : QObject(parent) , m_display(nullptr) , m_compositorInterface(nullptr) , m_connection(nullptr) , m_compositor(nullptr) , m_thread(nullptr) { } void TestWaylandSurface::init() { using namespace KWayland::Server; delete m_display; m_display = new Display(this); m_display->setSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); m_compositorInterface = m_display->createCompositor(m_display); QVERIFY(m_compositorInterface); m_compositorInterface->create(); QVERIFY(m_compositorInterface->isValid()); // setup connection m_connection = new KWayland::Client::ConnectionThread; QSignalSpy connectedSpy(m_connection, SIGNAL(connected())); m_connection->setSocketName(s_socketName); m_thread = new QThread(this); m_connection->moveToThread(m_thread); m_thread->start(); /*connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, m_connection, [this]() { if (m_connection->display()) { wl_display_flush(m_connection->display()); } } );*/ m_connection->initConnection(); QVERIFY(connectedSpy.wait()); m_queue = new KWayland::Client::EventQueue(this); QVERIFY(!m_queue->isValid()); m_queue->setup(m_connection); QVERIFY(m_queue->isValid()); KWayland::Client::Registry registry; registry.setEventQueue(m_queue); QSignalSpy compositorSpy(®istry, SIGNAL(compositorAnnounced(quint32,quint32))); QSignalSpy shmSpy(®istry, SIGNAL(shmAnnounced(quint32,quint32))); QSignalSpy allAnnounced(®istry, SIGNAL(interfacesAnnounced())); QVERIFY(allAnnounced.isValid()); QVERIFY(shmSpy.isValid()); registry.create(m_connection->display()); QVERIFY(registry.isValid()); registry.setup(); QVERIFY(allAnnounced.wait()); QVERIFY(!compositorSpy.isEmpty()); QVERIFY(!shmSpy.isEmpty()); m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); QVERIFY(m_compositor->isValid()); m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); QVERIFY(m_shm->isValid()); } void TestWaylandSurface::cleanup() { if (m_compositor) { delete m_compositor; m_compositor = nullptr; } if (m_shm) { delete m_shm; m_shm = nullptr; } if (m_queue) { delete m_queue; m_queue = nullptr; } if (m_thread) { m_thread->quit(); m_thread->wait(); delete m_thread; m_thread = nullptr; } delete m_connection; m_connection = nullptr; delete m_compositorInterface; m_compositorInterface = nullptr; delete m_display; m_display = nullptr; } void TestWaylandSurface::testStaticAccessor() { QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); QVERIFY(KWayland::Client::Surface::all().isEmpty()); KWayland::Client::Surface *s1 = m_compositor->createSurface(); QVERIFY(s1->isValid()); QCOMPARE(KWayland::Client::Surface::all().count(), 1); QCOMPARE(KWayland::Client::Surface::all().first(), s1); QCOMPARE(KWayland::Client::Surface::get(*s1), s1); QVERIFY(serverSurfaceCreated.wait()); auto serverSurface1 = serverSurfaceCreated.first().first().value(); QVERIFY(serverSurface1); QCOMPARE(KWayland::Server::SurfaceInterface::get(serverSurface1->resource()), serverSurface1); QCOMPARE(KWayland::Server::SurfaceInterface::get(serverSurface1->id(), serverSurface1->client()), serverSurface1); QVERIFY(!s1->size().isValid()); QSignalSpy sizeChangedSpy(s1, SIGNAL(sizeChanged(QSize))); QVERIFY(sizeChangedSpy.isValid()); const QSize testSize(200, 300); s1->setSize(testSize); QCOMPARE(s1->size(), testSize); QCOMPARE(sizeChangedSpy.count(), 1); QCOMPARE(sizeChangedSpy.first().first().toSize(), testSize); // add another surface KWayland::Client::Surface *s2 = m_compositor->createSurface(); QVERIFY(s2->isValid()); QCOMPARE(KWayland::Client::Surface::all().count(), 2); QCOMPARE(KWayland::Client::Surface::all().first(), s1); QCOMPARE(KWayland::Client::Surface::all().last(), s2); QCOMPARE(KWayland::Client::Surface::get(*s1), s1); QCOMPARE(KWayland::Client::Surface::get(*s2), s2); serverSurfaceCreated.clear(); QVERIFY(serverSurfaceCreated.wait()); auto serverSurface2 = serverSurfaceCreated.first().first().value(); QVERIFY(serverSurface2); QCOMPARE(KWayland::Server::SurfaceInterface::get(serverSurface1->resource()), serverSurface1); QCOMPARE(KWayland::Server::SurfaceInterface::get(serverSurface1->id(), serverSurface1->client()), serverSurface1); QCOMPARE(KWayland::Server::SurfaceInterface::get(serverSurface2->resource()), serverSurface2); QCOMPARE(KWayland::Server::SurfaceInterface::get(serverSurface2->id(), serverSurface2->client()), serverSurface2); // delete s2 again delete s2; QCOMPARE(KWayland::Client::Surface::all().count(), 1); QCOMPARE(KWayland::Client::Surface::all().first(), s1); QCOMPARE(KWayland::Client::Surface::get(*s1), s1); // and finally delete the last one delete s1; QVERIFY(KWayland::Client::Surface::all().isEmpty()); QVERIFY(!KWayland::Client::Surface::get(nullptr)); } void TestWaylandSurface::testDamage() { QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); KWayland::Client::Surface *s = m_compositor->createSurface(); QVERIFY(serverSurfaceCreated.wait()); KWayland::Server::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); QVERIFY(serverSurface); QCOMPARE(serverSurface->damage(), QRegion()); QVERIFY(serverSurface->parentResource()); QVERIFY(!serverSurface->isMapped()); QSignalSpy damageSpy(serverSurface, SIGNAL(damaged(QRegion))); QVERIFY(damageSpy.isValid()); // send damage without a buffer s->damage(QRect(0, 0, 100, 100)); s->commit(KWayland::Client::Surface::CommitFlag::None); wl_display_flush(m_connection->display()); QCoreApplication::processEvents(); QCoreApplication::processEvents(); QVERIFY(damageSpy.isEmpty()); QVERIFY(!serverSurface->isMapped()); QImage img(QSize(10, 10), QImage::Format_ARGB32); img.fill(Qt::black); auto b = m_shm->createBuffer(img); s->attachBuffer(b); s->damage(QRect(0, 0, 10, 10)); s->commit(KWayland::Client::Surface::CommitFlag::None); QVERIFY(damageSpy.wait()); QCOMPARE(serverSurface->damage(), QRegion(0, 0, 10, 10)); QCOMPARE(damageSpy.first().first().value(), QRegion(0, 0, 10, 10)); QVERIFY(serverSurface->isMapped()); // damage multiple times QRegion testRegion(5, 8, 3, 6); testRegion = testRegion.united(QRect(10, 20, 30, 15)); img = QImage(QSize(40, 35), QImage::Format_ARGB32); img.fill(Qt::black); b = m_shm->createBuffer(img); s->attachBuffer(b); s->damage(testRegion); damageSpy.clear(); s->commit(KWayland::Client::Surface::CommitFlag::None); QVERIFY(damageSpy.wait()); QCOMPARE(serverSurface->damage(), testRegion); QCOMPARE(damageSpy.first().first().value(), testRegion); QVERIFY(serverSurface->isMapped()); } void TestWaylandSurface::testFrameCallback() { QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); KWayland::Client::Surface *s = m_compositor->createSurface(); QVERIFY(serverSurfaceCreated.wait()); KWayland::Server::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); QVERIFY(serverSurface); QSignalSpy damageSpy(serverSurface, SIGNAL(damaged(QRegion))); QVERIFY(damageSpy.isValid()); QSignalSpy frameRenderedSpy(s, SIGNAL(frameRendered())); QVERIFY(frameRenderedSpy.isValid()); QImage img(QSize(10, 10), QImage::Format_ARGB32); img.fill(Qt::black); auto b = m_shm->createBuffer(img); s->attachBuffer(b); s->damage(QRect(0, 0, 10, 10)); s->commit(); QVERIFY(damageSpy.wait()); serverSurface->frameRendered(10); QVERIFY(frameRenderedSpy.isEmpty()); QVERIFY(frameRenderedSpy.wait()); QVERIFY(!frameRenderedSpy.isEmpty()); } void TestWaylandSurface::testAttachBuffer() { // create the surface QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); KWayland::Client::Surface *s = m_compositor->createSurface(); QVERIFY(serverSurfaceCreated.wait()); KWayland::Server::SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); QVERIFY(serverSurface); // create two images QImage black(24, 24, QImage::Format_RGB32); black.fill(Qt::black); QImage red(24, 24, QImage::Format_ARGB32); red.fill(QColor(255, 0, 0, 128)); QImage blue(24, 24, QImage::Format_ARGB32_Premultiplied); blue.fill(QColor(0, 0, 255, 128)); wl_buffer *blackBuffer = *(m_shm->createBuffer(black).data()); auto redBuffer = m_shm->createBuffer(red); auto blueBuffer = m_shm->createBuffer(blue).toStrongRef(); QCOMPARE(blueBuffer->format(), KWayland::Client::Buffer::Format::ARGB32); QCOMPARE(blueBuffer->size(), blue.size()); QVERIFY(!blueBuffer->isReleased()); QVERIFY(!blueBuffer->isUsed()); QCOMPARE(blueBuffer->stride(), blue.bytesPerLine()); s->attachBuffer(redBuffer.data()); s->attachBuffer(blackBuffer); s->damage(QRect(0, 0, 24, 24)); s->commit(KWayland::Client::Surface::CommitFlag::None); QSignalSpy damageSpy(serverSurface, SIGNAL(damaged(QRegion))); QVERIFY(damageSpy.isValid()); QSignalSpy unmappedSpy(serverSurface, SIGNAL(unmapped())); QVERIFY(unmappedSpy.isValid()); QVERIFY(damageSpy.wait()); QVERIFY(unmappedSpy.isEmpty()); // now the ServerSurface should have the black image attached as a buffer KWayland::Server::BufferInterface *buffer = serverSurface->buffer(); buffer->ref(); QVERIFY(buffer->shmBuffer()); QCOMPARE(buffer->data(), black); QCOMPARE(buffer->data().format(), QImage::Format_RGB32); // render another frame s->attachBuffer(redBuffer); s->damage(QRect(0, 0, 24, 24)); s->commit(KWayland::Client::Surface::CommitFlag::None); damageSpy.clear(); QVERIFY(damageSpy.wait()); QVERIFY(unmappedSpy.isEmpty()); KWayland::Server::BufferInterface *buffer2 = serverSurface->buffer(); buffer2->ref(); QVERIFY(buffer2->shmBuffer()); QCOMPARE(buffer2->data(), red); QCOMPARE(buffer2->data().format(), QImage::Format_ARGB32); buffer2->unref(); QVERIFY(buffer2->isReferenced()); QVERIFY(!redBuffer.data()->isReleased()); // render another frame blueBuffer->setUsed(true); QVERIFY(blueBuffer->isUsed()); s->attachBuffer(blueBuffer.data()); s->damage(QRect(0, 0, 24, 24)); QSignalSpy frameRenderedSpy(s, SIGNAL(frameRendered())); QVERIFY(frameRenderedSpy.isValid()); s->commit(); damageSpy.clear(); QVERIFY(damageSpy.wait()); QVERIFY(unmappedSpy.isEmpty()); QVERIFY(!buffer2->isReferenced()); delete buffer2; // TODO: we should have a signal on when the Buffer gets released QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); if (!redBuffer.data()->isReleased()) { QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); } QVERIFY(redBuffer.data()->isReleased()); KWayland::Server::BufferInterface *buffer3 = serverSurface->buffer(); buffer3->ref(); QVERIFY(buffer3->shmBuffer()); QCOMPARE(buffer3->data().format(), QImage::Format_ARGB32); QCOMPARE(buffer3->data().width(), 24); QCOMPARE(buffer3->data().height(), 24); for (int i = 0; i < 24; ++i) { for (int j = 0; j < 24; ++j) { // it's premultiplied in the format QCOMPARE(buffer3->data().pixel(i, j), qRgba(0, 0, 128, 128)); } } buffer3->unref(); QVERIFY(buffer3->isReferenced()); serverSurface->frameRendered(1); QVERIFY(frameRenderedSpy.wait()); // commit a different value shouldn't change our buffer QCOMPARE(serverSurface->buffer(), buffer3); QVERIFY(serverSurface->input().isNull()); damageSpy.clear(); s->setInputRegion(m_compositor->createRegion(QRegion(0, 0, 24, 24)).get()); s->commit(KWayland::Client::Surface::CommitFlag::None); wl_display_flush(m_connection->display()); QCoreApplication::processEvents(); QCoreApplication::processEvents(); QCOMPARE(serverSurface->input(), QRegion(0, 0, 24, 24)); QCOMPARE(serverSurface->buffer(), buffer3); QVERIFY(damageSpy.isEmpty()); QVERIFY(unmappedSpy.isEmpty()); QVERIFY(serverSurface->isMapped()); // clear the surface s->attachBuffer(blackBuffer); s->damage(QRect(0, 0, 1, 1)); // TODO: better method s->attachBuffer((wl_buffer*)nullptr); s->damage(QRect(0, 0, 10, 10)); s->commit(KWayland::Client::Surface::CommitFlag::None); QVERIFY(unmappedSpy.wait()); QVERIFY(!unmappedSpy.isEmpty()); QCOMPARE(unmappedSpy.count(), 1); QVERIFY(damageSpy.isEmpty()); QVERIFY(!serverSurface->isMapped()); // TODO: add signal test on release buffer->unref(); } void TestWaylandSurface::testMultipleSurfaces() { using namespace KWayland::Client; using namespace KWayland::Server; Registry registry; QSignalSpy shmSpy(®istry, SIGNAL(shmAnnounced(quint32,quint32))); registry.create(m_connection->display()); QVERIFY(registry.isValid()); registry.setup(); QVERIFY(shmSpy.wait()); ShmPool pool1; ShmPool pool2; pool1.setup(registry.bindShm(shmSpy.first().first().value(), shmSpy.first().last().value())); pool2.setup(registry.bindShm(shmSpy.first().first().value(), shmSpy.first().last().value())); QVERIFY(pool1.isValid()); QVERIFY(pool2.isValid()); // create the surfaces QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); QScopedPointer s1(m_compositor->createSurface()); QVERIFY(serverSurfaceCreated.wait()); SurfaceInterface *serverSurface1 = serverSurfaceCreated.first().first().value(); QVERIFY(serverSurface1); //second surface QScopedPointer s2(m_compositor->createSurface()); QVERIFY(serverSurfaceCreated.wait()); SurfaceInterface *serverSurface2 = serverSurfaceCreated.last().first().value(); QVERIFY(serverSurface2); QVERIFY(serverSurface1->resource() != serverSurface2->resource()); // create two images QImage black(24, 24, QImage::Format_RGB32); black.fill(Qt::black); QImage red(24, 24, QImage::Format_ARGB32); red.fill(QColor(255, 0, 0, 128)); auto blackBuffer = pool1.createBuffer(black); auto redBuffer = pool2.createBuffer(red); s1->attachBuffer(blackBuffer); s1->damage(QRect(0, 0, 24, 24)); s1->commit(Surface::CommitFlag::None); QSignalSpy damageSpy1(serverSurface1, SIGNAL(damaged(QRegion))); QVERIFY(damageSpy1.isValid()); QVERIFY(damageSpy1.wait()); // now the ServerSurface should have the black image attached as a buffer BufferInterface *buffer1 = serverSurface1->buffer(); QVERIFY(buffer1); QImage buffer1Data = buffer1->data(); QCOMPARE(buffer1Data, black); // accessing the same buffer is OK QImage buffer1Data2 = buffer1->data(); QCOMPARE(buffer1Data2, buffer1Data); buffer1Data = QImage(); QVERIFY(buffer1Data.isNull()); buffer1Data2 = QImage(); QVERIFY(buffer1Data2.isNull()); // attach a buffer for the other surface s2->attachBuffer(redBuffer); s2->damage(QRect(0, 0, 24, 24)); s2->commit(Surface::CommitFlag::None); QSignalSpy damageSpy2(serverSurface2, SIGNAL(damaged(QRegion))); QVERIFY(damageSpy2.isValid()); QVERIFY(damageSpy2.wait()); BufferInterface *buffer2 = serverSurface2->buffer(); QVERIFY(buffer2); QImage buffer2Data = buffer2->data(); QCOMPARE(buffer2Data, red); // while buffer2 is accessed we cannot access buffer1 buffer1Data = buffer1->data(); QVERIFY(buffer1Data.isNull()); // a deep copy can be kept around QImage deepCopy = buffer2Data.copy(); QCOMPARE(deepCopy, red); buffer2Data = QImage(); QVERIFY(buffer2Data.isNull()); QCOMPARE(deepCopy, red); // now that buffer2Data is destroyed we can access buffer1 again buffer1Data = buffer1->data(); QVERIFY(!buffer1Data.isNull()); QCOMPARE(buffer1Data, black); } void TestWaylandSurface::testOpaque() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); Surface *s = m_compositor->createSurface(); QVERIFY(serverSurfaceCreated.wait()); SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); QVERIFY(serverSurface); QSignalSpy opaqueRegionChangedSpy(serverSurface, SIGNAL(opaqueChanged(QRegion))); QVERIFY(opaqueRegionChangedSpy.isValid()); // by default there should be an empty opaque region QCOMPARE(serverSurface->opaque(), QRegion()); // let's install an opaque region s->setOpaqueRegion(m_compositor->createRegion(QRegion(0, 10, 20, 30)).get()); // the region should only be applied after the surface got committed wl_display_flush(m_connection->display()); QCoreApplication::processEvents(); QCOMPARE(serverSurface->opaque(), QRegion()); QCOMPARE(opaqueRegionChangedSpy.count(), 0); // so let's commit to get the new region s->commit(Surface::CommitFlag::None); QVERIFY(opaqueRegionChangedSpy.wait()); QCOMPARE(opaqueRegionChangedSpy.count(), 1); QCOMPARE(opaqueRegionChangedSpy.last().first().value(), QRegion(0, 10, 20, 30)); QCOMPARE(serverSurface->opaque(), QRegion(0, 10, 20, 30)); // committing without setting a new region shouldn't change s->commit(Surface::CommitFlag::None); wl_display_flush(m_connection->display()); QCoreApplication::processEvents(); QCOMPARE(opaqueRegionChangedSpy.count(), 1); QCOMPARE(serverSurface->opaque(), QRegion(0, 10, 20, 30)); // let's change the opaque region s->setOpaqueRegion(m_compositor->createRegion(QRegion(10, 20, 30, 40)).get()); s->commit(Surface::CommitFlag::None); QVERIFY(opaqueRegionChangedSpy.wait()); QCOMPARE(opaqueRegionChangedSpy.count(), 2); QCOMPARE(opaqueRegionChangedSpy.last().first().value(), QRegion(10, 20, 30, 40)); QCOMPARE(serverSurface->opaque(), QRegion(10, 20, 30, 40)); // and let's go back to an empty region s->setOpaqueRegion(); s->commit(Surface::CommitFlag::None); QVERIFY(opaqueRegionChangedSpy.wait()); QCOMPARE(opaqueRegionChangedSpy.count(), 3); QCOMPARE(opaqueRegionChangedSpy.last().first().value(), QRegion()); QCOMPARE(serverSurface->opaque(), QRegion()); } void TestWaylandSurface::testInput() { using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); Surface *s = m_compositor->createSurface(); QVERIFY(serverSurfaceCreated.wait()); SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); QVERIFY(serverSurface); QSignalSpy inputRegionChangedSpy(serverSurface, SIGNAL(inputChanged(QRegion))); QVERIFY(inputRegionChangedSpy.isValid()); // by default there should be an empty == infinite input region QCOMPARE(serverSurface->input(), QRegion()); QCOMPARE(serverSurface->inputIsInfinite(), true); // let's install an input region s->setInputRegion(m_compositor->createRegion(QRegion(0, 10, 20, 30)).get()); // the region should only be applied after the surface got committed wl_display_flush(m_connection->display()); QCoreApplication::processEvents(); QCOMPARE(serverSurface->input(), QRegion()); QCOMPARE(serverSurface->inputIsInfinite(), true); QCOMPARE(inputRegionChangedSpy.count(), 0); // so let's commit to get the new region s->commit(Surface::CommitFlag::None); QVERIFY(inputRegionChangedSpy.wait()); QCOMPARE(inputRegionChangedSpy.count(), 1); QCOMPARE(inputRegionChangedSpy.last().first().value(), QRegion(0, 10, 20, 30)); QCOMPARE(serverSurface->input(), QRegion(0, 10, 20, 30)); QCOMPARE(serverSurface->inputIsInfinite(), false); // committing without setting a new region shouldn't change s->commit(Surface::CommitFlag::None); wl_display_flush(m_connection->display()); QCoreApplication::processEvents(); QCOMPARE(inputRegionChangedSpy.count(), 1); QCOMPARE(serverSurface->input(), QRegion(0, 10, 20, 30)); QCOMPARE(serverSurface->inputIsInfinite(), false); // let's change the input region s->setInputRegion(m_compositor->createRegion(QRegion(10, 20, 30, 40)).get()); s->commit(Surface::CommitFlag::None); QVERIFY(inputRegionChangedSpy.wait()); QCOMPARE(inputRegionChangedSpy.count(), 2); QCOMPARE(inputRegionChangedSpy.last().first().value(), QRegion(10, 20, 30, 40)); QCOMPARE(serverSurface->input(), QRegion(10, 20, 30, 40)); QCOMPARE(serverSurface->inputIsInfinite(), false); // and let's go back to an empty region s->setInputRegion(); s->commit(Surface::CommitFlag::None); QVERIFY(inputRegionChangedSpy.wait()); QCOMPARE(inputRegionChangedSpy.count(), 3); QCOMPARE(inputRegionChangedSpy.last().first().value(), QRegion()); QCOMPARE(serverSurface->input(), QRegion()); QCOMPARE(serverSurface->inputIsInfinite(), true); } void TestWaylandSurface::testScale() { // this test verifies that updating the scale factor is correctly passed to the Wayland server using namespace KWayland::Client; using namespace KWayland::Server; // create surface QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(serverSurfaceCreated.isValid()); QScopedPointer s(m_compositor->createSurface()); QCOMPARE(s->scale(), 1); QVERIFY(serverSurfaceCreated.wait()); SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); QVERIFY(serverSurface); QCOMPARE(serverSurface->scale(), 1); // let's change the scale factor QSignalSpy scaleChangedSpy(serverSurface, &SurfaceInterface::scaleChanged); QVERIFY(scaleChangedSpy.isValid()); s->setScale(2); QCOMPARE(s->scale(), 2); // needs a commit QVERIFY(!scaleChangedSpy.wait(100)); s->commit(Surface::CommitFlag::None); QVERIFY(scaleChangedSpy.wait()); QCOMPARE(scaleChangedSpy.count(), 1); QCOMPARE(scaleChangedSpy.first().first().toInt(), 2); QCOMPARE(serverSurface->scale(), 2); // let's try changing to same factor, should not emit changed on server s->setScale(2); s->commit(Surface::CommitFlag::None); QVERIFY(!scaleChangedSpy.wait(100)); // but changing to a different value should still work s->setScale(4); s->commit(Surface::CommitFlag::None); QVERIFY(scaleChangedSpy.wait()); QCOMPARE(scaleChangedSpy.count(), 2); QCOMPARE(scaleChangedSpy.first().first().toInt(), 2); QCOMPARE(scaleChangedSpy.last().first().toInt(), 4); QCOMPARE(serverSurface->scale(), 4); } void TestWaylandSurface::testDestroy() { using namespace KWayland::Client; Surface *s = m_compositor->createSurface(); connect(m_connection, &ConnectionThread::connectionDied, s, &Surface::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_compositor, &Compositor::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_shm, &ShmPool::destroy); connect(m_connection, &ConnectionThread::connectionDied, m_queue, &EventQueue::destroy); QVERIFY(s->isValid()); QSignalSpy connectionDiedSpy(m_connection, SIGNAL(connectionDied())); QVERIFY(connectionDiedSpy.isValid()); delete m_display; m_display = nullptr; m_compositorInterface = nullptr; QVERIFY(connectionDiedSpy.wait()); // now the Surface should be destroyed; QVERIFY(!s->isValid()); // calling destroy again should not fail s->destroy(); } void TestWaylandSurface::testUnmapOfNotMappedSurface() { // this test verifies that a surface which doesn't have a buffer attached doesn't trigger the unmapped signal using namespace KWayland::Client; using namespace KWayland::Server; // create surface QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(serverSurfaceCreated.isValid()); QScopedPointer s(m_compositor->createSurface()); QVERIFY(serverSurfaceCreated.wait()); SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); QSignalSpy unmappedSpy(serverSurface, &SurfaceInterface::unmapped); QVERIFY(unmappedSpy.isValid()); QSignalSpy scaleChanged(serverSurface, &SurfaceInterface::scaleChanged); // let's map a null buffer and change scale to trigger a signal we can wait for s->attachBuffer(Buffer::Ptr()); s->setScale(2); s->commit(Surface::CommitFlag::None); QVERIFY(scaleChanged.wait()); QVERIFY(unmappedSpy.isEmpty()); } void TestWaylandSurface::testDamageTracking() { // this tests the damage tracking feature using namespace KWayland::Client; using namespace KWayland::Server; // create surface QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(serverSurfaceCreated.isValid()); QScopedPointer s(m_compositor->createSurface()); QVERIFY(serverSurfaceCreated.wait()); SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); // before first commit, the tracked damage should be empty QVERIFY(serverSurface->trackedDamage().isEmpty()); // Now let's damage the surface QSignalSpy damagedSpy(serverSurface, &SurfaceInterface::damaged); QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied); image.fill(Qt::red); s->attachBuffer(m_shm->createBuffer(image)); s->damage(QRect(0, 0, 100, 100)); s->commit(Surface::CommitFlag::None); QVERIFY(damagedSpy.wait()); QCOMPARE(serverSurface->trackedDamage(), QRegion(0, 0, 100, 100)); QCOMPARE(serverSurface->damage(), QRegion(0, 0, 100, 100)); // resetting the tracked damage should empty it serverSurface->resetTrackedDamage(); QVERIFY(serverSurface->trackedDamage().isEmpty()); // but not affect the actual damage QCOMPARE(serverSurface->damage(), QRegion(0, 0, 100, 100)); // let's damage some parts of the surface QPainter p; p.begin(&image); p.fillRect(QRect(0, 0, 10, 10), Qt::blue); p.end(); s->attachBuffer(m_shm->createBuffer(image)); s->damage(QRect(0, 0, 10, 10)); s->commit(Surface::CommitFlag::None); QVERIFY(damagedSpy.wait()); QCOMPARE(serverSurface->trackedDamage(), QRegion(0, 0, 10, 10)); QCOMPARE(serverSurface->damage(), QRegion(0, 0, 10, 10)); // and damage some part completely not bounding to the current damage region p.begin(&image); p.fillRect(QRect(50, 40, 20, 30), Qt::blue); p.end(); s->attachBuffer(m_shm->createBuffer(image)); s->damage(QRect(50, 40, 20, 30)); s->commit(Surface::CommitFlag::None); QVERIFY(damagedSpy.wait()); QCOMPARE(serverSurface->trackedDamage(), QRegion(0, 0, 10, 10).united(QRegion(50, 40, 20, 30))); QCOMPARE(serverSurface->trackedDamage().rectCount(), 2); QCOMPARE(serverSurface->damage(), QRegion(50, 40, 20, 30)); // now let's reset the tracked damage again serverSurface->resetTrackedDamage(); QVERIFY(serverSurface->trackedDamage().isEmpty()); // but not affect the actual damage QCOMPARE(serverSurface->damage(), QRegion(50, 40, 20, 30)); } void TestWaylandSurface::testSurfaceAt() { // this test verifies that surfaceAt(const QPointF&) works as expected for the case of no children using namespace KWayland::Client; using namespace KWayland::Server; // create surface QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(serverSurfaceCreated.isValid()); QScopedPointer s(m_compositor->createSurface()); QVERIFY(serverSurfaceCreated.wait()); SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); // a newly created surface should not be mapped and not provide a surface at a position QVERIFY(!serverSurface->isMapped()); QVERIFY(!serverSurface->surfaceAt(QPointF(0, 0))); // let's damage this surface QSignalSpy sizeChangedSpy(serverSurface, &SurfaceInterface::sizeChanged); QVERIFY(sizeChangedSpy.isValid()); QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied); image.fill(Qt::red); s->attachBuffer(m_shm->createBuffer(image)); s->damage(QRect(0, 0, 100, 100)); s->commit(Surface::CommitFlag::None); QVERIFY(sizeChangedSpy.wait()); // now the surface is mapped and surfaceAt should give the surface QVERIFY(serverSurface->isMapped()); QCOMPARE(serverSurface->surfaceAt(QPointF(0, 0)), serverSurface); QCOMPARE(serverSurface->surfaceAt(QPointF(100, 100)), serverSurface); // outside the geometry it should not give a surface QVERIFY(!serverSurface->surfaceAt(QPointF(101, 101))); QVERIFY(!serverSurface->surfaceAt(QPointF(-1, -1))); } void TestWaylandSurface::testDestroyAttachedBuffer() { // this test verifies that destroying of a buffer attached to a surface works using namespace KWayland::Client; using namespace KWayland::Server; // create surface QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(serverSurfaceCreated.isValid()); QScopedPointer s(m_compositor->createSurface()); QVERIFY(serverSurfaceCreated.wait()); SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); // let's damage this surface QSignalSpy damagedSpy(serverSurface, &SurfaceInterface::damaged); QVERIFY(damagedSpy.isValid()); QImage image(QSize(100, 100), QImage::Format_ARGB32); image.fill(Qt::red); s->attachBuffer(m_shm->createBuffer(image)); s->damage(QRect(0, 0, 100, 100)); s->commit(Surface::CommitFlag::None); QVERIFY(damagedSpy.wait()); QVERIFY(serverSurface->buffer()); // attach another buffer image.fill(Qt::blue); s->attachBuffer(m_shm->createBuffer(image)); m_connection->flush(); // Let's try to destroy it QSignalSpy destroySpy(serverSurface->buffer(), &BufferInterface::aboutToBeDestroyed); QVERIFY(destroySpy.isValid()); delete m_shm; m_shm = nullptr; QVERIFY(destroySpy.wait()); // TODO: should this emit unmapped? QVERIFY(!serverSurface->buffer()); } +void TestWaylandSurface::testDisconnect() +{ + // this test verifies that the server side correctly tears down the resources when the client disconnects + using namespace KWayland::Client; + using namespace KWayland::Server; + QScopedPointer s(m_compositor->createSurface()); + QVERIFY(!s.isNull()); + QVERIFY(s->isValid()); + QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated); + QVERIFY(surfaceCreatedSpy.isValid()); + QVERIFY(surfaceCreatedSpy.wait()); + auto serverSurface = surfaceCreatedSpy.first().first().value(); + QVERIFY(serverSurface); + + // destroy client + QSignalSpy clientDisconnectedSpy(serverSurface->client(), &ClientConnection::disconnected); + QVERIFY(clientDisconnectedSpy.isValid()); + QSignalSpy surfaceDestroyedSpy(serverSurface, &QObject::destroyed); + QVERIFY(surfaceDestroyedSpy.isValid()); + if (m_connection) { + m_connection->deleteLater(); + m_connection = nullptr; + } + QVERIFY(clientDisconnectedSpy.wait()); + QCOMPARE(clientDisconnectedSpy.count(), 1); + QCOMPARE(surfaceDestroyedSpy.count(), 0); + QVERIFY(surfaceDestroyedSpy.wait()); + QCOMPARE(surfaceDestroyedSpy.count(), 1); + + s->destroy(); + m_shm->destroy(); + m_compositor->destroy(); + m_queue->destroy(); +} + QTEST_GUILESS_MAIN(TestWaylandSurface) #include "test_wayland_surface.moc" diff --git a/autotests/server/test_qt_surface_extension.cpp b/autotests/server/test_qt_surface_extension.cpp index 2de2cc0..69c69ba 100644 --- a/autotests/server/test_qt_surface_extension.cpp +++ b/autotests/server/test_qt_surface_extension.cpp @@ -1,97 +1,103 @@ /******************************************************************** Copyright 2016 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ // Qt #include #include // WaylandServer #include "../../src/server/compositor_interface.h" #include "../../src/server/display.h" #include "../../src/server/output_interface.h" #include "../../src/server/qtsurfaceextension_interface.h" #include "../../src/server/seat_interface.h" #include "../../src/server/shell_interface.h" using namespace KWayland::Server; class TestQtSurfaceExtension : public QObject { Q_OBJECT private Q_SLOTS: void testCloseWindow(); }; static const QString s_socketName = QStringLiteral("kwin-wayland-server-qt-surface-extension-0"); void TestQtSurfaceExtension::testCloseWindow() { // this test verifies that we can close windows through the Qt surface extension interface // for this we start a dummy server, launch a QtWayland powered application, wait for the // window it opens, close it and verify that the process terminates Display display; display.setSocketName(s_socketName); display.start(); display.createShm(); SeatInterface *seat = display.createSeat(); seat->setHasKeyboard(true); seat->setHasPointer(true); seat->setHasTouch(true); seat->create(); CompositorInterface *compositor = display.createCompositor(); compositor->create(); ShellInterface *shell = display.createShell(); shell->create(); OutputInterface *output = display.createOutput(); output->setManufacturer(QStringLiteral("org.kde")); output->setModel(QStringLiteral("QtSurfaceExtensionTestCase")); output->addMode(QSize(1280, 1024), OutputInterface::ModeFlag::Preferred | OutputInterface::ModeFlag::Current); output->setPhysicalSize(QSize(1280, 1024) / 3.8); output->create(); // surface extension QtSurfaceExtensionInterface *surfaceExtension = display.createQtSurfaceExtension(); surfaceExtension->create(); // create a signalspy for surfaceCreated QSignalSpy surfaceExtensionSpy(surfaceExtension, &QtSurfaceExtensionInterface::surfaceCreated); QVERIFY(surfaceExtensionSpy.isValid()); // now start our application QString binary = QFINDTESTDATA("surfaceExtensionHelper"); QVERIFY(!binary.isEmpty()); QProcess process; QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.insert(QStringLiteral("WAYLAND_DISPLAY"), s_socketName); process.setProcessEnvironment(env); process.start(binary); QVERIFY(surfaceExtensionSpy.wait()); QCOMPARE(surfaceExtensionSpy.count(), 1); auto *extension = surfaceExtensionSpy.first().first().value(); QVERIFY(extension); + QSignalSpy surfaceExtensionDestroyedSpy(extension, &QObject::destroyed); + QVERIFY(surfaceExtensionSpy.isValid()); QSignalSpy processStateChangedSpy(&process, &QProcess::stateChanged); QVERIFY(processStateChangedSpy.isValid()); extension->close(); extension->client()->flush(); QVERIFY(processStateChangedSpy.wait()); QCOMPARE(process.exitStatus(), QProcess::NormalExit); + if (surfaceExtensionDestroyedSpy.count() == 0) { + QVERIFY(surfaceExtensionDestroyedSpy.wait()); + } + QCOMPARE(surfaceExtensionSpy.count(), 1); } QTEST_GUILESS_MAIN(TestQtSurfaceExtension) #include "test_qt_surface_extension.moc" diff --git a/src/server/compositor_interface.cpp b/src/server/compositor_interface.cpp index 777262c..877f501 100644 --- a/src/server/compositor_interface.cpp +++ b/src/server/compositor_interface.cpp @@ -1,145 +1,129 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "compositor_interface.h" #include "display.h" #include "global_p.h" #include "surface_interface.h" // Wayland #include namespace KWayland { namespace Server { class CompositorInterface::Private : public Global::Private { public: Private(CompositorInterface *q, Display *d); private: void bind(wl_client *client, uint32_t version, uint32_t id) override; void createSurface(wl_client *client, wl_resource *resource, uint32_t id); void createRegion(wl_client *client, wl_resource *resource, uint32_t id); static void unbind(wl_resource *resource); static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id); static void createRegionCallback(wl_client *client, wl_resource *resource, uint32_t id); static Private *cast(wl_resource *r) { return reinterpret_cast(wl_resource_get_user_data(r)); } CompositorInterface *q; static const struct wl_compositor_interface s_interface; static const quint32 s_version; }; const quint32 CompositorInterface::Private::s_version = 3; CompositorInterface::Private::Private(CompositorInterface *q, Display *d) : Global::Private(d, &wl_compositor_interface, s_version) , q(q) { } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_compositor_interface CompositorInterface::Private::s_interface = { createSurfaceCallback, createRegionCallback }; #endif CompositorInterface::CompositorInterface(Display *display, QObject *parent) : Global(new Private(this, display), parent) { } CompositorInterface::~CompositorInterface() = default; void CompositorInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { auto c = display->getConnection(client); wl_resource *resource = c->createResource(&wl_compositor_interface, qMin(version, s_version), id); if (!resource) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(resource, &s_interface, this, unbind); // TODO: should we track? } void CompositorInterface::Private::unbind(wl_resource *resource) { Q_UNUSED(resource) // TODO: implement? } void CompositorInterface::Private::createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id) { cast(resource)->createSurface(client, resource, id); } void CompositorInterface::Private::createSurface(wl_client *client, wl_resource *resource, uint32_t id) { SurfaceInterface *surface = new SurfaceInterface(q, resource); surface->create(display->getConnection(client), wl_resource_get_version(resource), id); if (!surface->resource()) { wl_resource_post_no_memory(resource); delete surface; return; } - QObject::connect(surface->client(), &ClientConnection::disconnected, surface, - [surface] { - if (surface->resource()) { - wl_resource_destroy(surface->resource()); - delete surface; - } - } - ); emit q->surfaceCreated(surface); } void CompositorInterface::Private::createRegionCallback(wl_client *client, wl_resource *resource, uint32_t id) { cast(resource)->createRegion(client, resource, id); } void CompositorInterface::Private::createRegion(wl_client *client, wl_resource *resource, uint32_t id) { RegionInterface *region = new RegionInterface(q, resource); region->create(display->getConnection(client), wl_resource_get_version(resource), id); if (!region->resource()) { wl_resource_post_no_memory(resource); delete region; return; } - QObject::connect(region->client(), &ClientConnection::disconnected, region, - [region] { - if (region->resource()) { - wl_resource_destroy(region->resource()); - delete region; - } - } - ); emit q->regionCreated(region); } } } diff --git a/src/server/dataoffer_interface.cpp b/src/server/dataoffer_interface.cpp index 1b6fa3d..6573650 100644 --- a/src/server/dataoffer_interface.cpp +++ b/src/server/dataoffer_interface.cpp @@ -1,136 +1,136 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "dataoffer_interface.h" #include "datadevice_interface.h" #include "datasource_interface.h" #include "resource_p.h" // Qt #include // Wayland #include namespace KWayland { namespace Server { class DataOfferInterface::Private : public Resource::Private { public: Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource); ~Private(); DataSourceInterface *source; DataDeviceInterface *dataDevice; private: DataOfferInterface *q_func() { return reinterpret_cast(q); } void receive(const QString &mimeType, qint32 fd); static void acceptCallback(wl_client *client, wl_resource *resource, uint32_t serial, const char *mimeType); static void receiveCallback(wl_client *client, wl_resource *resource, const char *mimeType, int32_t fd); static void destroyCallback(wl_client *client, wl_resource *resource); static const struct wl_data_offer_interface s_interface; }; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_data_offer_interface DataOfferInterface::Private::s_interface = { acceptCallback, receiveCallback, destroyCallback }; #endif DataOfferInterface::Private::Private(DataSourceInterface *source, DataDeviceInterface *parentInterface, DataOfferInterface *q, wl_resource *parentResource) : Resource::Private(q, nullptr, parentResource, &wl_data_offer_interface, &s_interface) , source(source) , dataDevice(parentInterface) { // TODO: connect to new selections } DataOfferInterface::Private::~Private() = default; void DataOfferInterface::Private::acceptCallback(wl_client *client, wl_resource *resource, uint32_t serial, const char *mimeType) { Q_UNUSED(client) Q_UNUSED(serial) auto p = cast(resource); if (!p->source) { return; } p->source->accept(mimeType ? QString::fromUtf8(mimeType) : QString()); } void DataOfferInterface::Private::destroyCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) wl_resource_destroy(resource); } void DataOfferInterface::Private::receiveCallback(wl_client *client, wl_resource *resource, const char *mimeType, int32_t fd) { Q_UNUSED(client) cast(resource)->receive(QString::fromUtf8(mimeType), fd); } void DataOfferInterface::Private::receive(const QString &mimeType, qint32 fd) { source->requestData(mimeType, fd); } DataOfferInterface::DataOfferInterface(DataSourceInterface *source, DataDeviceInterface *parentInterface, wl_resource *parentResource) - : Resource(new Private(source, parentInterface, this, parentResource), parentInterface) + : Resource(new Private(source, parentInterface, this, parentResource)) { connect(source, &DataSourceInterface::mimeTypeOffered, this, [this](const QString &mimeType) { Q_D(); if (!d->resource) { return; } wl_data_offer_send_offer(d->resource, mimeType.toUtf8().constData()); } ); QObject::connect(source, &QObject::destroyed, this, [this] { Q_D(); d->source = nullptr; } ); } DataOfferInterface::~DataOfferInterface() = default; void DataOfferInterface::sendAllOffers() { Q_D(); for (const QString &mimeType : d->source->mimeTypes()) { wl_data_offer_send_offer(d->resource, mimeType.toUtf8().constData()); } } DataOfferInterface::Private *DataOfferInterface::d_func() const { return reinterpret_cast(d.data()); } } } diff --git a/src/server/dpms_interface.cpp b/src/server/dpms_interface.cpp index fb42bc2..c6d288e 100644 --- a/src/server/dpms_interface.cpp +++ b/src/server/dpms_interface.cpp @@ -1,184 +1,184 @@ /******************************************************************** Copyright 2015 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "dpms_interface_p.h" #include "display.h" #include "output_interface.h" namespace KWayland { namespace Server { const quint32 DpmsManagerInterface::Private::s_version = 1; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct org_kde_kwin_dpms_manager_interface DpmsManagerInterface::Private::s_interface = { getDpmsCallback }; #endif DpmsManagerInterface::Private::Private(DpmsManagerInterface *q, Display *d) : Global::Private(d, &org_kde_kwin_dpms_manager_interface, s_version) , q(q) { } void DpmsManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { auto c = display->getConnection(client); wl_resource *dpms = c->createResource(&org_kde_kwin_dpms_manager_interface, qMin(version, s_version), id); if (!dpms) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(dpms, &s_interface, this, nullptr); } void DpmsManagerInterface::Private::getDpmsCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *output) { auto p = Private::cast(resource); auto c = p->display->getConnection(client); OutputInterface *o = OutputInterface::get(output); DpmsInterface *dpms = new DpmsInterface(o, resource, p->q); dpms->create(c, wl_resource_get_version(resource), id); if (!dpms->resource()) { wl_resource_post_no_memory(resource); return; } dpms->sendSupported(); dpms->sendMode(); dpms->sendDone(); } DpmsManagerInterface::DpmsManagerInterface(Display *display, QObject *parent) : Global(new Private(this, display), parent) { } DpmsManagerInterface::~DpmsManagerInterface() = default; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct org_kde_kwin_dpms_interface DpmsInterface::Private::s_interface = { setCallback, releaseCallback }; #endif DpmsInterface::Private::Private(DpmsInterface *q, DpmsManagerInterface *g, wl_resource *parentResource, OutputInterface *output) : Resource::Private(q, g, parentResource, &org_kde_kwin_dpms_interface, &s_interface) , output(output) { } void DpmsInterface::Private::setCallback(wl_client *client, wl_resource *resource, uint32_t mode) { Q_UNUSED(client) OutputInterface::DpmsMode dpmsMode; switch (mode) { case ORG_KDE_KWIN_DPMS_MODE_ON: dpmsMode = OutputInterface::DpmsMode::On; break; case ORG_KDE_KWIN_DPMS_MODE_STANDBY: dpmsMode = OutputInterface::DpmsMode::Standby; break; case ORG_KDE_KWIN_DPMS_MODE_SUSPEND: dpmsMode = OutputInterface::DpmsMode::Suspend; break; case ORG_KDE_KWIN_DPMS_MODE_OFF: dpmsMode = OutputInterface::DpmsMode::Off; break; default: return; } emit cast(resource)->output->dpmsModeRequested(dpmsMode); } void DpmsInterface::Private::releaseCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) Private *p = reinterpret_cast(wl_resource_get_user_data(resource)); wl_resource_destroy(resource); p->q->deleteLater(); } DpmsInterface::DpmsInterface(OutputInterface *output, wl_resource *parentResource, DpmsManagerInterface *manager) - : Resource(new Private(this, manager, parentResource, output), manager) + : Resource(new Private(this, manager, parentResource, output)) { connect(output, &OutputInterface::dpmsSupportedChanged, this, [this] { sendSupported(); sendDone(); } ); connect(output, &OutputInterface::dpmsModeChanged, this, [this] { sendMode(); sendDone(); } ); } DpmsInterface::~DpmsInterface() = default; void DpmsInterface::sendSupported() { Q_D(); org_kde_kwin_dpms_send_supported(d->resource, d->output->isDpmsSupported() ? 1 : 0); } void DpmsInterface::sendMode() { Q_D(); const auto mode = d->output->dpmsMode(); org_kde_kwin_dpms_mode wlMode; switch (mode) { case OutputInterface::DpmsMode::On: wlMode = ORG_KDE_KWIN_DPMS_MODE_ON; break; case OutputInterface::DpmsMode::Standby: wlMode = ORG_KDE_KWIN_DPMS_MODE_STANDBY; break; case OutputInterface::DpmsMode::Suspend: wlMode = ORG_KDE_KWIN_DPMS_MODE_SUSPEND; break; case OutputInterface::DpmsMode::Off: wlMode = ORG_KDE_KWIN_DPMS_MODE_OFF; break; default: Q_UNREACHABLE(); } org_kde_kwin_dpms_send_mode(d->resource, wlMode); } void DpmsInterface::sendDone() { Q_D(); org_kde_kwin_dpms_send_done(d->resource); client()->flush(); } DpmsInterface::Private *DpmsInterface::d_func() const { return reinterpret_cast(d.data()); } } } diff --git a/src/server/keyboard_interface.cpp b/src/server/keyboard_interface.cpp index 1160516..88d88cf 100644 --- a/src/server/keyboard_interface.cpp +++ b/src/server/keyboard_interface.cpp @@ -1,197 +1,197 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "keyboard_interface.h" #include "keyboard_interface_p.h" #include "display.h" #include "seat_interface.h" #include "surface_interface.h" // Qt #include // System #include #include // Wayland #include namespace KWayland { namespace Server { KeyboardInterface::Private::Private(SeatInterface *s, wl_resource *parentResource, KeyboardInterface *q) : Resource::Private(q, s, parentResource, &wl_keyboard_interface, &s_interface) , seat(s) { } void KeyboardInterface::Private::focusChildSurface(const QPointer &childSurface, quint32 serial) { if (focusedChildSurface == childSurface) { return; } sendLeave(focusedChildSurface.data(), serial); focusedChildSurface = childSurface; sendEnter(focusedChildSurface.data(), serial); } void KeyboardInterface::Private::sendLeave(SurfaceInterface *surface, quint32 serial) { if (surface && resource && surface->resource()) { wl_keyboard_send_leave(resource, serial, surface->resource()); } } void KeyboardInterface::Private::sendEnter(SurfaceInterface *surface, quint32 serial) { wl_array keys; wl_array_init(&keys); const auto states = seat->pressedKeys(); for (auto it = states.begin(); it != states.end(); ++it) { uint32_t *k = reinterpret_cast(wl_array_add(&keys, sizeof(uint32_t))); *k = *it; } wl_keyboard_send_enter(resource, serial, surface->resource(), &keys); wl_array_release(&keys); sendModifiers(); } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_keyboard_interface KeyboardInterface::Private::s_interface { releaseCallback }; #endif KeyboardInterface::KeyboardInterface(SeatInterface *parent, wl_resource *parentResource) - : Resource(new Private(parent, parentResource, this), parent) + : Resource(new Private(parent, parentResource, this)) { } KeyboardInterface::~KeyboardInterface() = default; void KeyboardInterface::Private::releaseCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) unbind(resource); } void KeyboardInterface::setKeymap(int fd, quint32 size) { Q_D(); d->sendKeymap(fd, size); } void KeyboardInterface::Private::sendKeymap() { Q_ASSERT(resource); if (seat->isKeymapXkbCompatible()) { sendKeymap(seat->keymapFileDescriptor(), seat->keymapSize()); } else { int nullFd = open("/dev/null", O_RDONLY); // krazy:exclude=syscalls wl_keyboard_send_keymap(resource, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, nullFd, 0); close(nullFd); } } void KeyboardInterface::Private::sendKeymap(int fd, quint32 size) { Q_ASSERT(resource); wl_keyboard_send_keymap(resource, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, fd, size); } void KeyboardInterface::Private::sendModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group, quint32 serial) { Q_ASSERT(resource); wl_keyboard_send_modifiers(resource, serial, depressed, latched, locked, group); } void KeyboardInterface::Private::sendModifiers() { sendModifiers(seat->depressedModifiers(), seat->latchedModifiers(), seat->lockedModifiers(), seat->groupModifiers(), seat->lastModifiersSerial()); } void KeyboardInterface::setFocusedSurface(SurfaceInterface *surface, quint32 serial) { Q_D(); d->sendLeave(d->focusedChildSurface, serial); disconnect(d->destroyConnection); d->focusedChildSurface.clear(); d->focusedSurface = surface; if (!d->focusedSurface) { return; } d->destroyConnection = connect(d->focusedSurface, &QObject::destroyed, this, [this] { Q_D(); d->focusedSurface = nullptr; d->focusedChildSurface.clear(); } ); d->focusedChildSurface = QPointer(surface); d->sendEnter(d->focusedSurface, serial); d->client->flush(); } void KeyboardInterface::keyPressed(quint32 key, quint32 serial) { Q_D(); Q_ASSERT(d->focusedSurface); wl_keyboard_send_key(d->resource, serial, d->seat->timestamp(), key, WL_KEYBOARD_KEY_STATE_PRESSED); } void KeyboardInterface::keyReleased(quint32 key, quint32 serial) { Q_D(); Q_ASSERT(d->focusedSurface); wl_keyboard_send_key(d->resource, serial, d->seat->timestamp(), key, WL_KEYBOARD_KEY_STATE_RELEASED); } void KeyboardInterface::updateModifiers(quint32 depressed, quint32 latched, quint32 locked, quint32 group, quint32 serial) { Q_D(); Q_ASSERT(d->focusedSurface); d->sendModifiers(depressed, latched, locked, group, serial); } void KeyboardInterface::repeatInfo(qint32 charactersPerSecond, qint32 delay) { Q_D(); if (wl_resource_get_version(d->resource) < WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { // only supported since version 4 return; } wl_keyboard_send_repeat_info(d->resource, charactersPerSecond, delay); } SurfaceInterface *KeyboardInterface::focusedSurface() const { Q_D(); return d->focusedSurface; } KeyboardInterface::Private *KeyboardInterface::d_func() const { return reinterpret_cast(d.data()); } } } diff --git a/src/server/plasmashell_interface.cpp b/src/server/plasmashell_interface.cpp index f082534..18dc883 100644 --- a/src/server/plasmashell_interface.cpp +++ b/src/server/plasmashell_interface.cpp @@ -1,329 +1,329 @@ /******************************************************************** Copyright 2015 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "plasmashell_interface.h" #include "global_p.h" #include "resource_p.h" #include "display.h" #include "surface_interface.h" #include #include #include namespace KWayland { namespace Server { class PlasmaShellInterface::Private : public Global::Private { public: Private(PlasmaShellInterface *q, Display *d); QList surfaces; private: static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface); void bind(wl_client *client, uint32_t version, uint32_t id) override; void createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface, wl_resource *parentResource); PlasmaShellInterface *q; static const struct org_kde_plasma_shell_interface s_interface; static const quint32 s_version; }; const quint32 PlasmaShellInterface::Private::s_version = 2; PlasmaShellInterface::Private::Private(PlasmaShellInterface *q, Display *d) : Global::Private(d, &org_kde_plasma_shell_interface, s_version) , q(q) { } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct org_kde_plasma_shell_interface PlasmaShellInterface::Private::s_interface = { createSurfaceCallback }; #endif class PlasmaShellSurfaceInterface::Private : public Resource::Private { public: Private(PlasmaShellSurfaceInterface *q, PlasmaShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource); SurfaceInterface *surface; QPoint m_globalPos; Role m_role = Role::Normal; bool m_positionSet = false; PanelBehavior m_panelBehavior = PanelBehavior::AlwaysVisible; bool m_skipTaskbar = false; private: // interface callbacks static void destroyCallback(wl_client *client, wl_resource *resource); static void setOutputCallback(wl_client *client, wl_resource *resource, wl_resource *output); static void setPositionCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y); static void setRoleCallback(wl_client *client, wl_resource *resource, uint32_t role); static void setPanelBehaviorCallback(wl_client *client, wl_resource *resource, uint32_t flag); static void setSkipTaskbarCallback(wl_client *client, wl_resource *resource, uint32_t skip); void setPosition(const QPoint &globalPos); void setRole(uint32_t role); void setPanelBehavior(org_kde_plasma_surface_panel_behavior behavior); PlasmaShellSurfaceInterface *q_func() { return reinterpret_cast(q); } static const struct org_kde_plasma_surface_interface s_interface; }; PlasmaShellInterface::PlasmaShellInterface(Display *display, QObject *parent) : Global(new Private(this, display), parent) { } PlasmaShellInterface::~PlasmaShellInterface() = default; void PlasmaShellInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { auto c = display->getConnection(client); wl_resource *shell = c->createResource(&org_kde_plasma_shell_interface, qMin(version, s_version), id); if (!shell) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(shell, &s_interface, this, nullptr); } void PlasmaShellInterface::Private::createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface) { auto s = reinterpret_cast(wl_resource_get_user_data(resource)); s->createSurface(client, wl_resource_get_version(resource), id, SurfaceInterface::get(surface), resource); } void PlasmaShellInterface::Private::createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface, wl_resource *parentResource) { auto it = std::find_if(surfaces.constBegin(), surfaces.constEnd(), [surface](PlasmaShellSurfaceInterface *s) { return surface == s->surface(); } ); if (it != surfaces.constEnd()) { wl_resource_post_error(surface->resource(), WL_DISPLAY_ERROR_INVALID_OBJECT, "PlasmaShellSurface already created"); return; } PlasmaShellSurfaceInterface *shellSurface = new PlasmaShellSurfaceInterface(q, surface, parentResource); surfaces << shellSurface; QObject::connect(shellSurface, &PlasmaShellSurfaceInterface::destroyed, q, [this, shellSurface] { surfaces.removeAll(shellSurface); } ); shellSurface->d->create(display->getConnection(client), version, id); emit q->surfaceCreated(shellSurface); } /********************************* * ShellSurfaceInterface *********************************/ PlasmaShellSurfaceInterface::Private::Private(PlasmaShellSurfaceInterface *q, PlasmaShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource) : Resource::Private(q, shell, parentResource, &org_kde_plasma_surface_interface, &s_interface) , surface(surface) { } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct org_kde_plasma_surface_interface PlasmaShellSurfaceInterface::Private::s_interface = { destroyCallback, setOutputCallback, setPositionCallback, setRoleCallback, setPanelBehaviorCallback, setSkipTaskbarCallback }; #endif PlasmaShellSurfaceInterface::PlasmaShellSurfaceInterface(PlasmaShellInterface *shell, SurfaceInterface *parent, wl_resource *parentResource) - : Resource(new Private(this, shell, parent, parentResource), parent) + : Resource(new Private(this, shell, parent, parentResource)) { } PlasmaShellSurfaceInterface::~PlasmaShellSurfaceInterface() = default; SurfaceInterface *PlasmaShellSurfaceInterface::surface() const { Q_D(); return d->surface; } PlasmaShellInterface *PlasmaShellSurfaceInterface::shell() const { Q_D(); return reinterpret_cast(d->global); } PlasmaShellSurfaceInterface::Private *PlasmaShellSurfaceInterface::d_func() const { return reinterpret_cast(d.data()); } void PlasmaShellSurfaceInterface::Private::destroyCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) wl_resource_destroy(resource); } void PlasmaShellSurfaceInterface::Private::setOutputCallback(wl_client *client, wl_resource *resource, wl_resource *output) { Q_UNUSED(client) Q_UNUSED(resource) Q_UNUSED(output) // TODO: implement } void PlasmaShellSurfaceInterface::Private::setPositionCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y) { auto s = cast(resource); Q_ASSERT(client == *s->client); s->setPosition(QPoint(x, y)); } void PlasmaShellSurfaceInterface::Private::setPosition(const QPoint &globalPos) { if (m_globalPos == globalPos && m_positionSet) { return; } m_positionSet = true; m_globalPos = globalPos; Q_Q(PlasmaShellSurfaceInterface); emit q->positionChanged(); } void PlasmaShellSurfaceInterface::Private::setRoleCallback(wl_client *client, wl_resource *resource, uint32_t role) { auto s = cast(resource); Q_ASSERT(client == *s->client); s->setRole(role); } void PlasmaShellSurfaceInterface::Private::setRole(uint32_t role) { Role r = Role::Normal; switch (role) { case ORG_KDE_PLASMA_SURFACE_ROLE_DESKTOP: r = Role::Desktop; break; case ORG_KDE_PLASMA_SURFACE_ROLE_PANEL: r = Role::Panel; break; case ORG_KDE_PLASMA_SURFACE_ROLE_ONSCREENDISPLAY: r = Role::OnScreenDisplay; break; case ORG_KDE_PLASMA_SURFACE_ROLE_NORMAL: default: r = Role::Normal; break; } if (r == m_role) { return; } m_role = r; Q_Q(PlasmaShellSurfaceInterface); emit q->roleChanged(); } void PlasmaShellSurfaceInterface::Private::setPanelBehaviorCallback(wl_client *client, wl_resource *resource, uint32_t flag) { auto s = cast(resource); Q_ASSERT(client == *s->client); s->setPanelBehavior(org_kde_plasma_surface_panel_behavior(flag)); } void PlasmaShellSurfaceInterface::Private::setSkipTaskbarCallback(wl_client *client, wl_resource *resource, uint32_t skip) { auto s = cast(resource); Q_ASSERT(client == *s->client); s->m_skipTaskbar = (bool)skip; emit s->q_func()->skipTaskbarChanged(); } void PlasmaShellSurfaceInterface::Private::setPanelBehavior(org_kde_plasma_surface_panel_behavior behavior) { PanelBehavior newBehavior = PanelBehavior::AlwaysVisible; switch (behavior) { case ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_AUTO_HIDE: newBehavior = PanelBehavior::AutoHide; break; case ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_WINDOWS_CAN_COVER: newBehavior = PanelBehavior::WindowsCanCover; break; case ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_WINDOWS_GO_BELOW: newBehavior = PanelBehavior::WindowsGoBelow; break; case ORG_KDE_PLASMA_SURFACE_PANEL_BEHAVIOR_ALWAYS_VISIBLE: default: break; } if (m_panelBehavior == newBehavior) { return; } m_panelBehavior = newBehavior; Q_Q(PlasmaShellSurfaceInterface); emit q->panelBehaviorChanged(); } QPoint PlasmaShellSurfaceInterface::position() const { Q_D(); return d->m_globalPos; } PlasmaShellSurfaceInterface::Role PlasmaShellSurfaceInterface::role() const { Q_D(); return d->m_role; } bool PlasmaShellSurfaceInterface::isPositionSet() const { Q_D(); return d->m_positionSet; } PlasmaShellSurfaceInterface::PanelBehavior PlasmaShellSurfaceInterface::panelBehavior() const { Q_D(); return d->m_panelBehavior; } bool PlasmaShellSurfaceInterface::skipTaskbar() const { Q_D(); return d->m_skipTaskbar; } PlasmaShellSurfaceInterface *PlasmaShellSurfaceInterface::get(wl_resource *native) { return Private::get(native); } } } diff --git a/src/server/pointer_interface.cpp b/src/server/pointer_interface.cpp index ec2d64a..8a689c2 100644 --- a/src/server/pointer_interface.cpp +++ b/src/server/pointer_interface.cpp @@ -1,289 +1,289 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "pointer_interface.h" #include "pointer_interface_p.h" #include "resource_p.h" #include "seat_interface.h" #include "display.h" #include "subcompositor_interface.h" #include "surface_interface.h" // Wayland #include namespace KWayland { namespace Server { class Cursor::Private { public: Private(Cursor *q, PointerInterface *pointer); PointerInterface *pointer; quint32 enteredSerial = 0; QPoint hotspot; QPointer surface; void update(const QPointer &surface, quint32 serial, const QPoint &hotspot); private: Cursor *q; }; PointerInterface::Private::Private(SeatInterface *parent, wl_resource *parentResource, PointerInterface *q) : Resource::Private(q, parent, parentResource, &wl_pointer_interface, &s_interface) , seat(parent) { } void PointerInterface::Private::setCursor(quint32 serial, SurfaceInterface *surface, const QPoint &hotspot) { if (!cursor) { Q_Q(PointerInterface); cursor = new Cursor(q); cursor->d->update(QPointer(surface), serial, hotspot); QObject::connect(cursor, &Cursor::changed, q, &PointerInterface::cursorChanged); emit q->cursorChanged(); } else { cursor->d->update(QPointer(surface), serial, hotspot); } } void PointerInterface::Private::sendLeave(SurfaceInterface *surface, quint32 serial) { if (!surface) { return; } if (resource && surface->resource()) { wl_pointer_send_leave(resource, serial, surface->resource()); } } namespace { static QPointF surfacePosition(SurfaceInterface *surface) { if (surface && surface->subSurface()) { return surface->subSurface()->position() + surfacePosition(surface->subSurface()->parentSurface().data()); } return QPointF(); } } void PointerInterface::Private::sendEnter(SurfaceInterface *surface, const QPointF &parentSurfacePosition, quint32 serial) { if (!surface) { return; } const QPointF adjustedPos = parentSurfacePosition - surfacePosition(surface); wl_pointer_send_enter(resource, serial, surface->resource(), wl_fixed_from_double(adjustedPos.x()), wl_fixed_from_double(adjustedPos.y())); } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_pointer_interface PointerInterface::Private::s_interface = { setCursorCallback, releaseCallback }; #endif PointerInterface::PointerInterface(SeatInterface *parent, wl_resource *parentResource) - : Resource(new Private(parent, parentResource, this), parent) + : Resource(new Private(parent, parentResource, this)) { // TODO: handle touch connect(parent, &SeatInterface::pointerPosChanged, this, [this] { Q_D(); if (d->seat->isDragPointer()) { // handled by DataDevice return; } if (d->focusedSurface && d->resource) { const QPointF pos = d->seat->focusedPointerSurfaceTransformation().map(d->seat->pointerPos()); auto targetSurface = d->focusedSurface->surfaceAt(pos); if (!targetSurface) { targetSurface = d->focusedSurface; } if (targetSurface != d->focusedChildSurface.data()) { const quint32 serial = d->seat->display()->nextSerial(); d->sendLeave(d->focusedChildSurface.data(), serial); d->focusedChildSurface = QPointer(targetSurface); d->sendEnter(targetSurface, pos, serial); d->client->flush(); } else { const QPointF adjustedPos = pos - surfacePosition(d->focusedChildSurface); wl_pointer_send_motion(d->resource, d->seat->timestamp(), wl_fixed_from_double(adjustedPos.x()), wl_fixed_from_double(adjustedPos.y())); } } }); } PointerInterface::~PointerInterface() = default; void PointerInterface::setFocusedSurface(SurfaceInterface *surface, quint32 serial) { Q_D(); d->sendLeave(d->focusedChildSurface.data(), serial); disconnect(d->destroyConnection); if (!surface) { d->focusedSurface = nullptr; d->focusedChildSurface.clear(); return; } d->focusedSurface = surface; d->destroyConnection = connect(d->focusedSurface, &QObject::destroyed, this, [this] { Q_D(); d->focusedSurface = nullptr; d->focusedChildSurface.clear(); } ); const QPointF pos = d->seat->focusedPointerSurfaceTransformation().map(d->seat->pointerPos()); d->focusedChildSurface = QPointer(d->focusedSurface->surfaceAt(pos)); if (!d->focusedChildSurface) { d->focusedChildSurface = QPointer(d->focusedSurface); } d->sendEnter(d->focusedChildSurface.data(), pos, serial); d->client->flush(); } void PointerInterface::buttonPressed(quint32 button, quint32 serial) { Q_D(); Q_ASSERT(d->focusedSurface); if (!d->resource) { return; } wl_pointer_send_button(d->resource, serial, d->seat->timestamp(), button, WL_POINTER_BUTTON_STATE_PRESSED); } void PointerInterface::buttonReleased(quint32 button, quint32 serial) { Q_D(); Q_ASSERT(d->focusedSurface); if (!d->resource) { return; } wl_pointer_send_button(d->resource, serial, d->seat->timestamp(), button, WL_POINTER_BUTTON_STATE_RELEASED); } void PointerInterface::axis(Qt::Orientation orientation, quint32 delta) { Q_D(); Q_ASSERT(d->focusedSurface); if (!d->resource) { return; } wl_pointer_send_axis(d->resource, d->seat->timestamp(), (orientation == Qt::Vertical) ? WL_POINTER_AXIS_VERTICAL_SCROLL : WL_POINTER_AXIS_HORIZONTAL_SCROLL, wl_fixed_from_int(delta)); } void PointerInterface::Private::setCursorCallback(wl_client *client, wl_resource *resource, uint32_t serial, wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y) { auto p = cast(resource); Q_ASSERT(p->client->client() == client); p->setCursor(serial, SurfaceInterface::get(surface), QPoint(hotspot_x, hotspot_y)); } void PointerInterface::Private::releaseCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) unbind(resource); } Cursor *PointerInterface::cursor() const { Q_D(); return d->cursor; } PointerInterface::Private *PointerInterface::d_func() const { return reinterpret_cast(d.data()); } Cursor::Private::Private(Cursor *q, PointerInterface *pointer) : pointer(pointer) , q(q) { } void Cursor::Private::update(const QPointer< SurfaceInterface > &s, quint32 serial, const QPoint &p) { bool emitChanged = false; if (enteredSerial != serial) { enteredSerial = serial; emitChanged = true; emit q->enteredSerialChanged(); } if (hotspot != p) { hotspot = p; emitChanged = true; emit q->hotspotChanged(); } if (surface != s) { if (!surface.isNull()) { QObject::disconnect(surface.data(), &SurfaceInterface::damaged, q, &Cursor::changed); } surface = s; if (!surface.isNull()) { QObject::connect(surface.data(), &SurfaceInterface::damaged, q, &Cursor::changed); } emitChanged = true; emit q->surfaceChanged(); } if (emitChanged) { emit q->changed(); } } Cursor::Cursor(PointerInterface *parent) : QObject(parent) , d(new Private(this, parent)) { } Cursor::~Cursor() = default; quint32 Cursor::enteredSerial() const { return d->enteredSerial; } QPoint Cursor::hotspot() const { return d->hotspot; } PointerInterface *Cursor::pointer() const { return d->pointer; } QPointer< SurfaceInterface > Cursor::surface() const { return d->surface; } } } diff --git a/src/server/qtsurfaceextension_interface.cpp b/src/server/qtsurfaceextension_interface.cpp index 965748a..0f03c89 100644 --- a/src/server/qtsurfaceextension_interface.cpp +++ b/src/server/qtsurfaceextension_interface.cpp @@ -1,221 +1,221 @@ /******************************************************************** Copyright 2015 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "qtsurfaceextension_interface.h" #include "global_p.h" #include "resource_p.h" #include "display.h" #include "surface_interface.h" #include #include #include namespace KWayland { namespace Server { class QtSurfaceExtensionInterface::Private : public Global::Private { public: Private(QtSurfaceExtensionInterface *q, Display *d); QList surfaces; private: static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface); void bind(wl_client *client, uint32_t version, uint32_t id) override; void createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface, wl_resource *parentResource); QtSurfaceExtensionInterface *q; static const struct qt_surface_extension_interface s_interface; static const quint32 s_version; }; const quint32 QtSurfaceExtensionInterface::Private::s_version = 1; QtSurfaceExtensionInterface::Private::Private(QtSurfaceExtensionInterface *q, Display *d) : Global::Private(d, &qt_surface_extension_interface, s_version) , q(q) { } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct qt_surface_extension_interface QtSurfaceExtensionInterface::Private::s_interface = { createSurfaceCallback }; #endif class QtExtendedSurfaceInterface::Private : public Resource::Private { public: Private(QtExtendedSurfaceInterface *q, QtSurfaceExtensionInterface *shell, SurfaceInterface *surface, wl_resource *parentResource); SurfaceInterface *surface; private: // interface callbacks static void updateGenericPropertyCallback(wl_client *client, wl_resource *resource, const char *name, wl_array *value); static void setContentOrientationMaskCallback(wl_client *client, wl_resource *resource, int32_t orientation); static void setWindowFlagsCallback(wl_client *client, wl_resource *resource, int32_t flags); static void raiseCallback(wl_client *client, wl_resource *resource); static void lowerCallback(wl_client *client, wl_resource *resource); QtExtendedSurfaceInterface *q_func() { return reinterpret_cast(q); } static const struct qt_extended_surface_interface s_interface; }; QtSurfaceExtensionInterface::QtSurfaceExtensionInterface(Display *display, QObject *parent) : Global(new Private(this, display), parent) { } QtSurfaceExtensionInterface::~QtSurfaceExtensionInterface() = default; void QtSurfaceExtensionInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { auto c = display->getConnection(client); wl_resource *shell = c->createResource(&qt_surface_extension_interface, qMin(version, s_version), id); if (!shell) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(shell, &s_interface, this, nullptr); } void QtSurfaceExtensionInterface::Private::createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface) { auto s = reinterpret_cast(wl_resource_get_user_data(resource)); s->createSurface(client, wl_resource_get_version(resource), id, SurfaceInterface::get(surface), resource); } void QtSurfaceExtensionInterface::Private::createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface, wl_resource *parentResource) { auto it = std::find_if(surfaces.constBegin(), surfaces.constEnd(), [surface](QtExtendedSurfaceInterface *s) { return surface == s->surface(); } ); if (it != surfaces.constEnd()) { wl_resource_post_error(surface->resource(), WL_DISPLAY_ERROR_INVALID_OBJECT, "PlasmaShellSurface already created"); return; } QtExtendedSurfaceInterface *shellSurface = new QtExtendedSurfaceInterface(q, surface, parentResource); surfaces << shellSurface; QObject::connect(shellSurface, &QtExtendedSurfaceInterface::destroyed, q, [this, shellSurface] { surfaces.removeAll(shellSurface); } ); shellSurface->d->create(display->getConnection(client), version, id); emit q->surfaceCreated(shellSurface); } /********************************* * ShellSurfaceInterface *********************************/ QtExtendedSurfaceInterface::Private::Private(QtExtendedSurfaceInterface *q, QtSurfaceExtensionInterface *shell, SurfaceInterface *surface, wl_resource *parentResource) : Resource::Private(q, shell, parentResource, &qt_extended_surface_interface, &s_interface) , surface(surface) { } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct qt_extended_surface_interface QtExtendedSurfaceInterface::Private::s_interface = { updateGenericPropertyCallback, setContentOrientationMaskCallback, setWindowFlagsCallback, raiseCallback, lowerCallback }; #endif void QtExtendedSurfaceInterface::Private::lowerCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) emit cast(resource)->q_func()->lowerRequested(); } void QtExtendedSurfaceInterface::Private::raiseCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) emit cast(resource)->q_func()->raiseRequested(); } void QtExtendedSurfaceInterface::Private::setContentOrientationMaskCallback(wl_client *client, wl_resource *resource, int32_t orientation) { Q_UNUSED(client) Q_UNUSED(resource) Q_UNUSED(orientation) } void QtExtendedSurfaceInterface::Private::setWindowFlagsCallback(wl_client *client, wl_resource *resource, int32_t flags) { Q_UNUSED(client) Q_UNUSED(resource) Q_UNUSED(flags) } void QtExtendedSurfaceInterface::Private::updateGenericPropertyCallback(wl_client *client, wl_resource *resource, const char *name, wl_array *value) { Q_UNUSED(client) Q_UNUSED(resource) Q_UNUSED(name) Q_UNUSED(value) } QtExtendedSurfaceInterface::QtExtendedSurfaceInterface(QtSurfaceExtensionInterface *shell, SurfaceInterface *parent, wl_resource *parentResource) - : Resource(new Private(this, shell, parent, parentResource), parent) + : Resource(new Private(this, shell, parent, parentResource)) { } QtExtendedSurfaceInterface::~QtExtendedSurfaceInterface() = default; SurfaceInterface *QtExtendedSurfaceInterface::surface() const { Q_D(); return d->surface; } QtSurfaceExtensionInterface *QtExtendedSurfaceInterface::shell() const { Q_D(); return reinterpret_cast(d->global); } QtExtendedSurfaceInterface::Private *QtExtendedSurfaceInterface::d_func() const { return reinterpret_cast(d.data()); } void QtExtendedSurfaceInterface::close() { Q_D(); qt_extended_surface_send_close(d->resource); d->client->flush(); } } } diff --git a/src/server/region_interface.cpp b/src/server/region_interface.cpp index c525d50..a6cec33 100644 --- a/src/server/region_interface.cpp +++ b/src/server/region_interface.cpp @@ -1,126 +1,126 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "region_interface.h" #include "resource_p.h" #include "compositor_interface.h" // Wayland #include namespace KWayland { namespace Server { class RegionInterface::Private : public Resource::Private { public: Private(CompositorInterface *compositor, RegionInterface *q, wl_resource *parentResource); ~Private(); QRegion qtRegion; private: RegionInterface *q_func() { return reinterpret_cast(q); } void add(const QRect &rect); void subtract(const QRect &rect); static void destroyCallback(wl_client *client, wl_resource *r); static void addCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height); static void subtractCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height); static const struct wl_region_interface s_interface; }; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_region_interface RegionInterface::Private::s_interface = { destroyCallback, addCallback, subtractCallback }; #endif RegionInterface::Private::Private(CompositorInterface *compositor, RegionInterface *q, wl_resource *parentResource) : Resource::Private(q, compositor, parentResource, &wl_region_interface, &s_interface) { } RegionInterface::Private::~Private() = default; void RegionInterface::Private::add(const QRect &rect) { qtRegion = qtRegion.united(rect); Q_Q(RegionInterface); emit q->regionChanged(qtRegion); } void RegionInterface::Private::subtract(const QRect &rect) { if (qtRegion.isEmpty()) { return; } qtRegion = qtRegion.subtracted(rect); Q_Q(RegionInterface); emit q->regionChanged(qtRegion); } void RegionInterface::Private::addCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height) { Q_UNUSED(client) cast(r)->add(QRect(x, y, width, height)); } void RegionInterface::Private::subtractCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height) { Q_UNUSED(client) cast(r)->subtract(QRect(x, y, width, height)); } void RegionInterface::Private::destroyCallback(wl_client *client, wl_resource *r) { Q_UNUSED(client) wl_resource_destroy(r); } RegionInterface::RegionInterface(CompositorInterface *parent, wl_resource *parentResource) - : Resource(new Private(parent, this, parentResource), parent) + : Resource(new Private(parent, this, parentResource)) { } RegionInterface::~RegionInterface() = default; QRegion RegionInterface::region() const { Q_D(); return d->qtRegion; } RegionInterface *RegionInterface::get(wl_resource *native) { return Private::get(native); } RegionInterface::Private *RegionInterface::d_func() const { return reinterpret_cast(d.data()); } } } diff --git a/src/server/shell_interface.cpp b/src/server/shell_interface.cpp index 2988e22..a702290 100644 --- a/src/server/shell_interface.cpp +++ b/src/server/shell_interface.cpp @@ -1,492 +1,492 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "shell_interface.h" #include "global_p.h" #include "resource_p.h" #include "display.h" #include "surface_interface.h" #include #include namespace KWayland { namespace Server { class ShellInterface::Private : public Global::Private { public: Private(ShellInterface *q, Display *d); QList surfaces; private: static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface); void bind(wl_client *client, uint32_t version, uint32_t id) override; void createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface, wl_resource *parentResource); ShellInterface *q; static const struct wl_shell_interface s_interface; static const quint32 s_version; }; const quint32 ShellInterface::Private::s_version = 1; ShellInterface::Private::Private(ShellInterface *q, Display *d) : Global::Private(d, &wl_shell_interface, s_version) , q(q) { } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_shell_interface ShellInterface::Private::s_interface = { createSurfaceCallback }; #endif class ShellSurfaceInterface::Private : public Resource::Private { public: Private(ShellSurfaceInterface *q, ShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource); void ping(); SurfaceInterface *surface; QString title; QByteArray windowClass; QScopedPointer pingTimer; quint32 pingSerial = 0; enum class WindowMode { Fullscreen, Toplevel, Maximized, Popup }; WindowMode windowMode = WindowMode::Toplevel; QPoint transientOffset; QPointer transientFor; bool acceptsKeyboardFocus = true; void setWindowMode(WindowMode newWindowMode); private: // interface callbacks static void pongCallback(wl_client *client, wl_resource *resource, uint32_t serial); static void moveCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial); static void resizeCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial, uint32_t edges); static void setToplevelCallback(wl_client *client, wl_resource *resource); static void setTransientCallback(wl_client *client, wl_resource *resource, wl_resource *parent, int32_t x, int32_t y, uint32_t flags); static void setFullscreenCallback(wl_client *client, wl_resource *resource, uint32_t method, uint32_t framerate, wl_resource *output); static void setPopupCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial, wl_resource *parent, int32_t x, int32_t y, uint32_t flags); static void setMaximizedCallback(wl_client *client, wl_resource *resource, wl_resource *output); static void setTitleCallback(wl_client *client, wl_resource *resource, const char *title); static void setClassCallback(wl_client *client, wl_resource *resource, const char *class_); void setTitle(const QString &title); void setWindowClass(const QByteArray &windowClass); void pong(quint32 serial); void setAcceptsFocus(quint32 flags); ShellSurfaceInterface *q_func() { return reinterpret_cast(q); } static const struct wl_shell_surface_interface s_interface; }; ShellInterface::ShellInterface(Display *display, QObject *parent) : Global(new Private(this, display), parent) { } ShellInterface::~ShellInterface() = default; void ShellInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { auto c = display->getConnection(client); wl_resource *shell = c->createResource(&wl_shell_interface, qMin(version, s_version), id); if (!shell) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(shell, &s_interface, this, nullptr); } void ShellInterface::Private::createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface) { auto s = reinterpret_cast(wl_resource_get_user_data(resource)); s->createSurface(client, wl_resource_get_version(resource), id, SurfaceInterface::get(surface), resource); } void ShellInterface::Private::createSurface(wl_client *client, uint32_t version, uint32_t id, SurfaceInterface *surface, wl_resource *parentResource) { auto it = std::find_if(surfaces.constBegin(), surfaces.constEnd(), [surface](ShellSurfaceInterface *s) { return surface == s->surface(); } ); if (it != surfaces.constEnd()) { wl_resource_post_error(surface->resource(), WL_DISPLAY_ERROR_INVALID_OBJECT, "ShellSurface already created"); return; } ShellSurfaceInterface *shellSurface = new ShellSurfaceInterface(q, surface, parentResource); surfaces << shellSurface; QObject::connect(shellSurface, &ShellSurfaceInterface::destroyed, q, [this, shellSurface] { surfaces.removeAll(shellSurface); } ); shellSurface->d->create(display->getConnection(client), version, id); emit q->surfaceCreated(shellSurface); } /********************************* * ShellSurfaceInterface *********************************/ ShellSurfaceInterface::Private::Private(ShellSurfaceInterface *q, ShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource) : Resource::Private(q, shell, parentResource, &wl_shell_surface_interface, &s_interface) , surface(surface) , pingTimer(new QTimer) { pingTimer->setSingleShot(true); pingTimer->setInterval(1000); } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_shell_surface_interface ShellSurfaceInterface::Private::s_interface = { pongCallback, moveCallback, resizeCallback, setToplevelCallback, setTransientCallback, setFullscreenCallback, setPopupCallback, setMaximizedCallback, setTitleCallback, setClassCallback }; #endif ShellSurfaceInterface::ShellSurfaceInterface(ShellInterface *shell, SurfaceInterface *parent, wl_resource *parentResource) - : Resource(new Private(this, shell, parent, parentResource), parent) + : Resource(new Private(this, shell, parent, parentResource)) { Q_D(); connect(d->pingTimer.data(), &QTimer::timeout, this, &ShellSurfaceInterface::pingTimeout); } ShellSurfaceInterface::~ShellSurfaceInterface() = default; void ShellSurfaceInterface::Private::pongCallback(wl_client *client, wl_resource *resource, uint32_t serial) { auto s = cast(resource); Q_ASSERT(client == *s->client); s->pong(serial); } void ShellSurfaceInterface::Private::pong(quint32 serial) { if (pingTimer->isActive() && serial == pingSerial) { pingTimer->stop(); Q_Q(ShellSurfaceInterface); emit q->pongReceived(); } } void ShellSurfaceInterface::ping() { Q_D(); d->ping(); } void ShellSurfaceInterface::Private::ping() { if (pingTimer->isActive()) { return; } pingSerial = global->display()->nextSerial(); wl_shell_surface_send_ping(resource, pingSerial); client->flush(); pingTimer->start(); } void ShellSurfaceInterface::setPingTimeout(uint msec) { Q_D(); d->pingTimer->setInterval(msec); } bool ShellSurfaceInterface::isPinged() const { Q_D(); return d->pingTimer->isActive(); } void ShellSurfaceInterface::requestSize(const QSize &size) { Q_D(); // TODO: what about the edges? wl_shell_surface_send_configure(d->resource, 0, size.width(), size.height()); d->client->flush(); } void ShellSurfaceInterface::Private::moveCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial) { auto s = cast(resource); Q_ASSERT(client == *s->client); emit s->q_func()->moveRequested(SeatInterface::get(seat), serial); } void ShellSurfaceInterface::Private::resizeCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial, uint32_t edges) { auto s = cast(resource); Q_ASSERT(client == *s->client); Qt::Edges qtEdges; switch (edges) { case WL_SHELL_SURFACE_RESIZE_TOP: qtEdges = Qt::TopEdge; break; case WL_SHELL_SURFACE_RESIZE_BOTTOM: qtEdges = Qt::BottomEdge; break; case WL_SHELL_SURFACE_RESIZE_LEFT: qtEdges = Qt::LeftEdge; break; case WL_SHELL_SURFACE_RESIZE_TOP_LEFT: qtEdges = Qt::TopEdge | Qt::LeftEdge; break; case WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT: qtEdges = Qt::BottomEdge | Qt::LeftEdge; break; case WL_SHELL_SURFACE_RESIZE_RIGHT: qtEdges = Qt::RightEdge; break; case WL_SHELL_SURFACE_RESIZE_TOP_RIGHT: qtEdges = Qt::TopEdge | Qt::RightEdge; break; case WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT: qtEdges = Qt::BottomEdge | Qt::RightEdge; break; default: break; } emit s->q_func()->resizeRequested(SeatInterface::get(seat), serial, qtEdges); } void ShellSurfaceInterface::Private::setToplevelCallback(wl_client *client, wl_resource *resource) { auto s = cast(resource); Q_ASSERT(client == *s->client); s->setWindowMode(WindowMode::Toplevel); } void ShellSurfaceInterface::Private::setTransientCallback(wl_client *client, wl_resource *resource, wl_resource *parent, int32_t x, int32_t y, uint32_t flags) { Q_UNUSED(flags) auto s = cast(resource); Q_ASSERT(client == *s->client); s->transientFor = QPointer(SurfaceInterface::get(parent)); s->transientOffset = QPoint(x, y); emit s->q_func()->transientChanged(!s->transientFor.isNull()); emit s->q_func()->transientOffsetChanged(s->transientOffset); emit s->q_func()->transientForChanged(); s->setAcceptsFocus(flags); } void ShellSurfaceInterface::Private::setAcceptsFocus(quint32 flags) { const bool acceptsFocus = !(flags & WL_SHELL_SURFACE_TRANSIENT_INACTIVE); if (acceptsFocus != acceptsKeyboardFocus) { acceptsKeyboardFocus = acceptsFocus; Q_Q(ShellSurfaceInterface); emit q->acceptsKeyboardFocusChanged(); } } void ShellSurfaceInterface::Private::setFullscreenCallback(wl_client *client, wl_resource *resource, uint32_t method, uint32_t framerate, wl_resource *output) { Q_UNUSED(method) Q_UNUSED(framerate) Q_UNUSED(output) auto s = cast(resource); Q_ASSERT(client == *s->client); // TODO: add method, framerate and output s->setWindowMode(WindowMode::Fullscreen); } void ShellSurfaceInterface::Private::setWindowMode(WindowMode newWindowMode) { if (windowMode == newWindowMode) { return; } const WindowMode oldWindowMode = windowMode; windowMode = newWindowMode; Q_Q(ShellSurfaceInterface); if (oldWindowMode == WindowMode::Fullscreen || newWindowMode == WindowMode::Fullscreen) { emit q->fullscreenChanged(windowMode == WindowMode::Fullscreen); } if (oldWindowMode == WindowMode::Toplevel || newWindowMode == WindowMode::Toplevel) { emit q->toplevelChanged(windowMode == WindowMode::Toplevel); } if (oldWindowMode == WindowMode::Maximized || newWindowMode == WindowMode::Maximized) { emit q->maximizedChanged(windowMode == WindowMode::Maximized); } if (oldWindowMode == WindowMode::Popup || newWindowMode == WindowMode::Popup) { emit q->popupChanged(windowMode == WindowMode::Popup); } } void ShellSurfaceInterface::Private::setPopupCallback(wl_client *client, wl_resource *resource, wl_resource *seat, uint32_t serial, wl_resource *parent, int32_t x, int32_t y, uint32_t flags) { Q_UNUSED(seat) Q_UNUSED(serial) Q_UNUSED(flags) auto s = cast(resource); Q_ASSERT(client == *s->client); // TODO: what about seat and serial? s->transientFor = QPointer(SurfaceInterface::get(parent)); s->transientOffset = QPoint(x, y); s->setWindowMode(WindowMode::Popup); emit s->q_func()->transientChanged(!s->transientFor.isNull()); emit s->q_func()->transientOffsetChanged(s->transientOffset); emit s->q_func()->transientForChanged(); s->setAcceptsFocus(WL_SHELL_SURFACE_TRANSIENT_INACTIVE); } void ShellSurfaceInterface::Private::setMaximizedCallback(wl_client *client, wl_resource *resource, wl_resource *output) { Q_UNUSED(output) auto s = cast(resource); Q_ASSERT(client == *s->client); s->setWindowMode(WindowMode::Maximized); } void ShellSurfaceInterface::Private::setTitleCallback(wl_client *client, wl_resource *resource, const char *title) { auto s = cast(resource); Q_ASSERT(client == *s->client); s->setTitle(QString::fromUtf8(title)); } void ShellSurfaceInterface::Private::setTitle(const QString &t) { if (title == t) { return; } title = t; Q_Q(ShellSurfaceInterface); emit q->titleChanged(title); } void ShellSurfaceInterface::Private::setClassCallback(wl_client *client, wl_resource *resource, const char *class_) { auto s = cast(resource); Q_ASSERT(client == *s->client); s->setWindowClass(QByteArray(class_)); } void ShellSurfaceInterface::Private::setWindowClass(const QByteArray &wc) { if (windowClass == wc) { return; } windowClass = wc; Q_Q(ShellSurfaceInterface); emit q->windowClassChanged(windowClass); } SurfaceInterface *ShellSurfaceInterface::surface() const { Q_D(); return d->surface; } ShellInterface *ShellSurfaceInterface::shell() const { Q_D(); return reinterpret_cast(d->global); } QString ShellSurfaceInterface::title() const { Q_D(); return d->title; } QByteArray ShellSurfaceInterface::windowClass() const { Q_D(); return d->windowClass; } bool ShellSurfaceInterface::isFullscreen() const { Q_D(); return d->windowMode == Private::WindowMode::Fullscreen; } bool ShellSurfaceInterface::isToplevel() const { Q_D(); return d->windowMode == Private::WindowMode::Toplevel; } bool ShellSurfaceInterface::isMaximized() const { Q_D(); return d->windowMode == Private::WindowMode::Maximized; } bool ShellSurfaceInterface::isPopup() const { Q_D(); return d->windowMode == Private::WindowMode::Popup; } bool ShellSurfaceInterface::isTransient() const { Q_D(); return !d->transientFor.isNull(); } QPoint ShellSurfaceInterface::transientOffset() const { Q_D(); return d->transientOffset; } bool ShellSurfaceInterface::acceptsKeyboardFocus() const { Q_D(); return d->acceptsKeyboardFocus; } QPointer< SurfaceInterface > ShellSurfaceInterface::transientFor() const { Q_D(); return d->transientFor; } ShellSurfaceInterface::Private *ShellSurfaceInterface::d_func() const { return reinterpret_cast(d.data()); } } } diff --git a/src/server/touch_interface.cpp b/src/server/touch_interface.cpp index 9a2942d..b36aa5a 100644 --- a/src/server/touch_interface.cpp +++ b/src/server/touch_interface.cpp @@ -1,136 +1,136 @@ /******************************************************************** Copyright 2015 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "touch_interface.h" #include "resource_p.h" #include "seat_interface.h" #include "display.h" #include "surface_interface.h" // Wayland #include namespace KWayland { namespace Server { class TouchInterface::Private : public Resource::Private { public: Private(SeatInterface *parent, wl_resource *parentResource, TouchInterface *q); SeatInterface *seat; SurfaceInterface *focusedSurface = nullptr; QMetaObject::Connection destroyConnection; private: TouchInterface *q_func() { return reinterpret_cast(q); } // interface // since version 3 static void releaseCallback(wl_client *client, wl_resource *resource); static const struct wl_touch_interface s_interface; }; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_touch_interface TouchInterface::Private::s_interface = { releaseCallback }; #endif TouchInterface::Private::Private(SeatInterface *parent, wl_resource *parentResource, TouchInterface *q) : Resource::Private(q, parent, parentResource, &wl_touch_interface, &s_interface) , seat(parent) { } void TouchInterface::Private::releaseCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) unbind(resource); } TouchInterface::TouchInterface(SeatInterface *parent, wl_resource *parentResource) - : Resource(new Private(parent, parentResource, this), parent) + : Resource(new Private(parent, parentResource, this)) { } TouchInterface::~TouchInterface() = default; void TouchInterface::cancel() { Q_D(); if (!d->resource) { return; } wl_touch_send_cancel(d->resource); d->client->flush(); } void TouchInterface::frame() { Q_D(); if (!d->resource) { return; } wl_touch_send_frame(d->resource); d->client->flush(); } void TouchInterface::move(qint32 id, const QPointF &localPos) { Q_D(); if (!d->resource) { return; } wl_touch_send_motion(d->resource, d->seat->timestamp(), id, wl_fixed_from_double(localPos.x()), wl_fixed_from_double(localPos.y())); d->client->flush(); } void TouchInterface::up(qint32 id, quint32 serial) { Q_D(); if (!d->resource) { return; } wl_touch_send_up(d->resource, serial, d->seat->timestamp(), id); d->client->flush(); } void TouchInterface::down(qint32 id, quint32 serial, const QPointF &localPos) { Q_D(); if (!d->resource) { return; } wl_touch_send_down(d->resource, serial, d->seat->timestamp(), d->seat->focusedTouchSurface()->resource(), id, wl_fixed_from_double(localPos.x()), wl_fixed_from_double(localPos.y())); d->client->flush(); } TouchInterface::Private *TouchInterface::d_func() const { return reinterpret_cast(d.data()); } } }