diff --git a/autotests/client/test_wayland_shell.cpp b/autotests/client/test_wayland_shell.cpp index f5dbac6..177ce35 100644 --- a/autotests/client/test_wayland_shell.cpp +++ b/autotests/client/test_wayland_shell.cpp @@ -1,851 +1,855 @@ /******************************************************************** 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(); void testWhileDestroying(); void testClientDisconnecting(); 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(!ShellSurface::get(nullptr)); + QCOMPARE(ShellSurface::get(*(surface1.data())), surface1.data()); QVERIFY(serverSurfaceSpy.wait()); QCOMPARE(serverSurfaceSpy.count(), 1); QScopedPointer surface2(m_shell->createSurface(s2.data())); QVERIFY(!surface2.isNull()); QVERIFY(surface2->isValid()); + QCOMPARE(ShellSurface::get(*(surface2.data())), surface2.data()); 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()); + QCOMPARE(ShellSurface::get(*(surface3.data())), surface3.data()); 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()); QCOMPARE(serverSurface->shell(), m_shellInterface); QSignalSpy fullscreenSpy(serverSurface, SIGNAL(fullscreenChanged(bool))); QVERIFY(fullscreenSpy.isValid()); QVERIFY(!serverSurface->isFullscreen()); surface->setFullscreen(); QVERIFY(fullscreenSpy.wait()); QCOMPARE(fullscreenSpy.count(), 1); QVERIFY(fullscreenSpy.first().first().toBool()); QVERIFY(serverSurface->isFullscreen()); 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()); QVERIFY(!serverSurface->isFullscreen()); } 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()); QVERIFY(!serverSurface->isMaximized()); surface->setMaximized(); QVERIFY(maximizedSpy.wait()); QCOMPARE(maximizedSpy.count(), 1); QVERIFY(maximizedSpy.first().first().toBool()); QVERIFY(serverSurface->isMaximized()); 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()); QVERIFY(!serverSurface->isMaximized()); } 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); QVERIFY(!serverSurface->isPinged()); QSignalSpy pingTimeoutSpy(serverSurface, SIGNAL(pingTimeout())); QVERIFY(pingTimeoutSpy.isValid()); QSignalSpy pongSpy(serverSurface, SIGNAL(pongReceived())); QVERIFY(pongSpy.isValid()); serverSurface->ping(); QVERIFY(serverSurface->isPinged()); 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); // try setting it to same should not trigger the signal wl_shell_surface_set_class(*surface, testClass.constData()); QVERIFY(!windowClassSpy.wait(100)); } 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); // it's already unbound, but the shell surface is not yet destroyed QVERIFY(!serverSurface->resource()); // ensure we don't crash when accessing it in this state serverSurface->ping(); serverSurface->requestSize(QSize(1, 2)); 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(); } void TestWaylandShell::testWhileDestroying() { // this test tries to hit a condition that a Surface gets created with an ID which was already // used for a previous Surface. For each Surface we try to create a ShellSurface. // Even if there was a Surface in the past with the same ID, it should create the ShellSurface using namespace KWayland::Client; using namespace KWayland::Server; QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated); QVERIFY(surfaceCreatedSpy.isValid()); QScopedPointer s(m_compositor->createSurface()); QVERIFY(surfaceCreatedSpy.wait()); auto serverSurface = surfaceCreatedSpy.first().first().value(); QVERIFY(serverSurface); // create ShellSurface QSignalSpy shellSurfaceCreatedSpy(m_shellInterface, &ShellInterface::surfaceCreated); QVERIFY(shellSurfaceCreatedSpy.isValid()); QScopedPointer ps(m_shell->createSurface(s.data())); QVERIFY(shellSurfaceCreatedSpy.wait()); // now try to create more surfaces QSignalSpy clientErrorSpy(m_connection, &ConnectionThread::errorOccurred); QVERIFY(clientErrorSpy.isValid()); for (int i = 0; i < 100; i++) { s.reset(); ps.reset(); s.reset(m_compositor->createSurface()); ps.reset(m_shell->createSurface(s.data())); QVERIFY(surfaceCreatedSpy.wait()); } QVERIFY(clientErrorSpy.isEmpty()); QVERIFY(!clientErrorSpy.wait(100)); QVERIFY(clientErrorSpy.isEmpty()); } void TestWaylandShell::testClientDisconnecting() { // this test tries to request a new surface size while the client is actually already destroyed // see BUG: 370232 using namespace KWayland::Client; using namespace KWayland::Server; // create ShellSurface QScopedPointer s(m_compositor->createSurface()); QSignalSpy shellSurfaceCreatedSpy(m_shellInterface, &ShellInterface::surfaceCreated); QVERIFY(shellSurfaceCreatedSpy.isValid()); QScopedPointer ps(m_shell->createSurface(s.data())); QVERIFY(shellSurfaceCreatedSpy.wait()); auto serverShellSurface = shellSurfaceCreatedSpy.first().first().value(); QVERIFY(serverShellSurface); QSignalSpy shellSurfaceUnboundSpy(serverShellSurface, &Resource::unbound); QVERIFY(shellSurfaceUnboundSpy.isValid()); QScopedPointer s2(m_compositor->createSurface()); QScopedPointer ps2(m_shell->createSurface(s2.data())); QVERIFY(shellSurfaceCreatedSpy.wait()); auto serverShellSurface2 = shellSurfaceCreatedSpy.last().first().value(); QVERIFY(serverShellSurface2); connect(serverShellSurface, &Resource::unbound, this, [serverShellSurface, serverShellSurface2] { serverShellSurface2->requestSize(QSize(100, 200)); } ); m_connection->deleteLater(); m_connection = nullptr; m_thread->quit(); m_thread->wait(); delete m_thread; m_thread = nullptr; QVERIFY(shellSurfaceUnboundSpy.wait()); ps->destroy(); s->destroy(); ps2->destroy(); s2->destroy(); m_pointer->destroy(); m_seat->destroy(); m_shell->destroy(); m_compositor->destroy(); m_queue->destroy(); } QTEST_GUILESS_MAIN(TestWaylandShell) #include "test_wayland_shell.moc" diff --git a/src/client/shell.cpp b/src/client/shell.cpp index 8abc83e..113c929 100644 --- a/src/client/shell.cpp +++ b/src/client/shell.cpp @@ -1,313 +1,378 @@ /******************************************************************** 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.h" #include "event_queue.h" #include "output.h" #include "seat.h" #include "surface.h" #include "wayland_pointer_p.h" +// Qt +#include +#include +#include +#include // Wayland #include namespace KWayland { namespace Client { class Shell::Private { public: WaylandPointer shell; EventQueue *queue = nullptr; }; Shell::Shell(QObject *parent) : QObject(parent) , d(new Private) { } Shell::~Shell() { release(); } void Shell::destroy() { if (!d->shell) { return; } emit interfaceAboutToBeDestroyed(); d->shell.destroy(); } void Shell::release() { if (!d->shell) { return; } emit interfaceAboutToBeReleased(); d->shell.release(); } void Shell::setup(wl_shell *shell) { Q_ASSERT(!d->shell); Q_ASSERT(shell); d->shell.setup(shell); } void Shell::setEventQueue(EventQueue *queue) { d->queue = queue; } EventQueue *Shell::eventQueue() { return d->queue; } ShellSurface *Shell::createSurface(wl_surface *surface, QObject *parent) { Q_ASSERT(isValid()); ShellSurface *s = new ShellSurface(parent); connect(this, &Shell::interfaceAboutToBeReleased, s, &ShellSurface::release); connect(this, &Shell::interfaceAboutToBeDestroyed, s, &ShellSurface::destroy); auto w = wl_shell_get_shell_surface(d->shell, surface); if (d->queue) { d->queue->addProxy(w); } s->setup(w); return s; } ShellSurface *Shell::createSurface(Surface *surface, QObject *parent) { Q_ASSERT(surface); return createSurface(*surface, parent); } bool Shell::isValid() const { return d->shell.isValid(); } Shell::operator wl_shell*() { return d->shell; } Shell::operator wl_shell*() const { return d->shell; } class ShellSurface::Private { public: Private(ShellSurface *q); void setup(wl_shell_surface *surface); WaylandPointer surface; QSize size; + static QVector s_surfaces; private: void ping(uint32_t serial); static void pingCallback(void *data, struct wl_shell_surface *shellSurface, uint32_t serial); static void configureCallback(void *data, struct wl_shell_surface *shellSurface, uint32_t edges, int32_t width, int32_t height); static void popupDoneCallback(void *data, struct wl_shell_surface *shellSurface); ShellSurface *q; static const struct wl_shell_surface_listener s_listener; }; +QVector ShellSurface::Private::s_surfaces = QVector(); + ShellSurface::Private::Private(ShellSurface *q) : q(q) { } void ShellSurface::Private::setup(wl_shell_surface *s) { Q_ASSERT(s); Q_ASSERT(!surface); surface.setup(s); wl_shell_surface_add_listener(surface, &s_listener, this); } +ShellSurface *ShellSurface::fromWindow(QWindow *window) +{ + if (!window) { + return nullptr; + } + if (!QGuiApplication::platformName().contains(QStringLiteral("wayland"), Qt::CaseInsensitive)) { + return nullptr; + } + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) { + return nullptr; + } + window->create(); + wl_shell_surface *s = reinterpret_cast(native->nativeResourceForWindow(QByteArrayLiteral("wl_shell_surface"), window)); + if (!s) { + return nullptr; + } + if (auto surface = get(s)) { + return surface; + } + ShellSurface *surface = new ShellSurface(window); + surface->d->surface.setup(s, true); + return surface; +} + +ShellSurface *ShellSurface::fromQtWinId(WId wid) +{ + QWindow *window = nullptr; + + for (auto win : qApp->allWindows()) { + if (win->winId() == wid) { + window = win; + break; + } + } + + if (!window) { + return nullptr; + } + return fromWindow(window); +} + +ShellSurface *ShellSurface::get(wl_shell_surface *native) +{ + auto it = std::find_if(Private::s_surfaces.constBegin(), Private::s_surfaces.constEnd(), + [native](ShellSurface *s) { + return s->d->surface == native; + } + ); + if (it != Private::s_surfaces.constEnd()) { + return *(it); + } + return nullptr; +} + ShellSurface::ShellSurface(QObject *parent) : QObject(parent) , d(new Private(this)) { + Private::s_surfaces << this; } ShellSurface::~ShellSurface() { + Private::s_surfaces.removeOne(this); release(); } void ShellSurface::release() { d->surface.release(); } void ShellSurface::destroy() { d->surface.destroy(); } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_shell_surface_listener ShellSurface::Private::s_listener = { pingCallback, configureCallback, popupDoneCallback }; #endif void ShellSurface::Private::configureCallback(void *data, wl_shell_surface *shellSurface, uint32_t edges, int32_t width, int32_t height) { Q_UNUSED(edges) auto s = reinterpret_cast(data); Q_ASSERT(s->surface == shellSurface); s->q->setSize(QSize(width, height)); } void ShellSurface::Private::pingCallback(void *data, wl_shell_surface *shellSurface, uint32_t serial) { auto s = reinterpret_cast(data); Q_ASSERT(s->surface == shellSurface); s->ping(serial); } void ShellSurface::Private::popupDoneCallback(void *data, wl_shell_surface *shellSurface) { // not needed, we don't have popups Q_UNUSED(data) Q_UNUSED(shellSurface) } void ShellSurface::setup(wl_shell_surface *surface) { d->setup(surface); } void ShellSurface::Private::ping(uint32_t serial) { wl_shell_surface_pong(surface, serial); emit q->pinged(); } void ShellSurface::setSize(const QSize &size) { if (d->size == size) { return; } d->size = size; emit sizeChanged(size); } void ShellSurface::setFullscreen(Output *output) { Q_ASSERT(isValid()); wl_shell_surface_set_fullscreen(d->surface, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, output ? output->output() : nullptr); } void ShellSurface::setMaximized(Output *output) { Q_ASSERT(isValid()); wl_shell_surface_set_maximized(d->surface, output ? output->output() : nullptr); } void ShellSurface::setToplevel() { Q_ASSERT(isValid()); wl_shell_surface_set_toplevel(d->surface); } void ShellSurface::setTransient(Surface *parent, const QPoint &offset, TransientFlags flags) { Q_ASSERT(isValid()); uint32_t wlFlags = 0; if (flags.testFlag(TransientFlag::NoFocus)) { wlFlags |= WL_SHELL_SURFACE_TRANSIENT_INACTIVE; } wl_shell_surface_set_transient(d->surface, *parent, offset.x(), offset.y(), wlFlags); } void ShellSurface::requestMove(Seat *seat, quint32 serial) { Q_ASSERT(isValid()); Q_ASSERT(seat); wl_shell_surface_move(d->surface, *seat, serial); } void ShellSurface::requestResize(Seat *seat, quint32 serial, Qt::Edges edges) { Q_ASSERT(isValid()); Q_ASSERT(seat); uint wlEdge = WL_SHELL_SURFACE_RESIZE_NONE; if (edges.testFlag(Qt::TopEdge)) { if (edges.testFlag(Qt::LeftEdge) && ((edges & ~Qt::LeftEdge) == Qt::TopEdge)) { wlEdge = WL_SHELL_SURFACE_RESIZE_TOP_LEFT; } else if (edges.testFlag(Qt::RightEdge) && ((edges & ~Qt::RightEdge) == Qt::TopEdge)) { wlEdge = WL_SHELL_SURFACE_RESIZE_TOP_RIGHT; } else if ((edges & ~Qt::TopEdge) == Qt::Edges()) { wlEdge = WL_SHELL_SURFACE_RESIZE_TOP; } } else if (edges.testFlag(Qt::BottomEdge)) { if (edges.testFlag(Qt::LeftEdge) && ((edges & ~Qt::LeftEdge) == Qt::BottomEdge)) { wlEdge = WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT; } else if (edges.testFlag(Qt::RightEdge) && ((edges & ~Qt::RightEdge) == Qt::BottomEdge)) { wlEdge = WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT; } else if ((edges & ~Qt::BottomEdge) == Qt::Edges()) { wlEdge = WL_SHELL_SURFACE_RESIZE_BOTTOM; } } else if (edges.testFlag(Qt::RightEdge) && ((edges & ~Qt::RightEdge) == Qt::Edges())) { wlEdge = WL_SHELL_SURFACE_RESIZE_RIGHT; } else if (edges.testFlag(Qt::LeftEdge) && ((edges & ~Qt::LeftEdge) == Qt::Edges())) { wlEdge = WL_SHELL_SURFACE_RESIZE_LEFT; } wl_shell_surface_resize(d->surface, *seat, serial, wlEdge); } QSize ShellSurface::size() const { return d->size; } bool ShellSurface::isValid() const { return d->surface.isValid(); } ShellSurface::operator wl_shell_surface*() { return d->surface; } ShellSurface::operator wl_shell_surface*() const { return d->surface; } } } diff --git a/src/client/shell.h b/src/client/shell.h index 2e04fb7..edd6c21 100644 --- a/src/client/shell.h +++ b/src/client/shell.h @@ -1,292 +1,322 @@ /******************************************************************** 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 . *********************************************************************/ #ifndef WAYLAND_SHELL_H #define WAYLAND_SHELL_H #include #include #include +#include #include struct wl_surface; struct wl_shell; struct wl_shell_surface; namespace KWayland { namespace Client { class EventQueue; class ShellSurface; class Output; class Seat; class Surface; /** * @short Wrapper for the wl_shell interface. * * This class provides a convenient wrapper for the wl_shell interface. * It's main purpose is to create a ShellSurface. * * To use this class one needs to interact with the Registry. There are two * possible ways to create the Shell interface: * @code * Shell *s = registry->createShell(name, version); * @endcode * * This creates the Shell and sets it up directly. As an alternative this * can also be done in a more low level way: * @code * Shell *s = new Shell; * s->setup(registry->bindShell(name, version)); * @endcode * * The Shell can be used as a drop-in replacement for any wl_shell * pointer as it provides matching cast operators. * * @see Registry * @see ShellSurface **/ class KWAYLANDCLIENT_EXPORT Shell : public QObject { Q_OBJECT public: explicit Shell(QObject *parent = nullptr); virtual ~Shell(); /** * @returns @c true if managing a wl_shell. **/ bool isValid() const; /** * Releases the wl_shell interface. * After the interface has been released the Shell instance is no * longer valid and can be setup with another wl_shell interface. * * Right before the interface is released the signal interfaceAboutToBeReleased is emitted. * @see interfaceAboutToBeReleased **/ void release(); /** * Destroys the data held by this Shell. * This method is supposed to be used when the connection to the Wayland * server goes away. Once the connection becomes invalid, it's not * possible to call release anymore as that calls into the Wayland * connection and the call would fail. This method cleans up the data, so * that the instance can be deleted or set up to a new wl_shell interface * once there is a new connection available. * * It is suggested to connect this method to ConnectionThread::connectionDied: * @code * connect(connection, &ConnectionThread::connectionDied, shell, &Shell::destroy); * @endcode * * Right before the data is destroyed, the signal interfaceAboutToBeDestroyed is emitted. * * @see release * @see interfaceAboutToBeDestroyed **/ void destroy(); /** * Setup this Shell to manage the @p shell. * When using Registry::createShell there is no need to call this * method. **/ void setup(wl_shell *shell); /** * Sets the @p queue to use for creating a Surface. **/ void setEventQueue(EventQueue *queue); /** * @returns The event queue to use for creating a Surface. **/ EventQueue *eventQueue(); /** * Creates a ShellSurface for the given @p surface and sets it up. * * @param surface The native surface to create the ShellSurface for * @param parent The parent to use for the ShellSurface * @returns created ShellSurface **/ ShellSurface *createSurface(wl_surface *surface, QObject *parent = nullptr); /** * Creates a ShellSurface for the given @p surface and sets it up. * * @param surface The Surface to create the ShellSurface for * @param parent The parent to use for the ShellSurface * @returns created ShellSurface **/ ShellSurface *createSurface(Surface *surface, QObject *parent = nullptr); operator wl_shell*(); operator wl_shell*() const; Q_SIGNALS: /** * This signal is emitted right before the interface is released. **/ void interfaceAboutToBeReleased(); /** * This signal is emitted right before the data is destroyed. **/ void interfaceAboutToBeDestroyed(); /** * The corresponding global for this interface on the Registry got removed. * * This signal gets only emitted if the Compositor got created by * Registry::createShell * * @since 5.5 **/ void removed(); private: class Private; QScopedPointer d; }; /** * @short Wrapper for the wl_shell_surface interface. * * This class is a convenient wrapper for the wl_shell_surface interface. * * To create an instance use Shell::createSurface. * * @see Shell * @see Surface **/ class KWAYLANDCLIENT_EXPORT ShellSurface : public QObject { Q_OBJECT /** * The size of the ShellSurface. **/ Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged) public: explicit ShellSurface(QObject *parent); virtual ~ShellSurface(); /** * Releases the wl_shell_surface interface. * After the interface has been released the ShellSurface instance is no * longer valid and can be setup with another wl_shell_surface interface. * * This method is automatically invoked when the Shell which created this * ShellSurface gets released. **/ void release(); /** * Destroys the data held by this ShellSurface. * This method is supposed to be used when the connection to the Wayland * server goes away. If the connection is not valid anymore, it's not * possible to call release anymore as that calls into the Wayland * connection and the call would fail. This method cleans up the data, so * that the instance can be deleted or set up to a new wl_shell_surface interface * once there is a new connection available. * * This method is automatically invoked when the Shell which created this * ShellSurface gets destroyed. * * @see release **/ void destroy(); /** * Setup this ShellSurface to manage the @p surface. * There is normally no need to call this method as it's invoked by * Shell::createSurface. **/ void setup(wl_shell_surface *surface); QSize size() const; void setSize(const QSize &size); /** * Sets the ShellSurface fullscreen on @p output. **/ void setFullscreen(Output *output = nullptr); void setMaximized(Output *output = nullptr); void setToplevel(); /** * Flags which can be passed to a transient surface. * @see setTransient * @since 5.5 **/ enum class TransientFlag { Default = 0x0, ///< Default: transient surface accepts keyboard focus NoFocus = 0x1 ///< Transient surface does not accept keyboard focus }; Q_DECLARE_FLAGS(TransientFlags, TransientFlag) /** * Sets this Surface as a transient for @p parent. * * @param parent The parent Surface of this surface * @param offset The offset of this Surface in the parent coordinate system * @param flags The flags for the transient * @since 5.5 **/ void setTransient(Surface *parent, const QPoint &offset = QPoint(), TransientFlags flags = TransientFlag::Default); bool isValid() const; /** * Requests a move on the given @p seat after the pointer button press with the given @p serial. * * @param seat The seat on which to move the window * @param serial The serial of the pointer button press which should trigger the move * @since 5.5 **/ void requestMove(Seat *seat, quint32 serial); /** * Requests a resize on the given @p seat after the pointer button press with the given @p serial. * * @param seat The seat on which to resize the window * @param serial The serial of the pointer button press which should trigger the resize * @param edges A hint for the compositor to set e.g. an appropriate cursor image * @since 5.5 **/ void requestResize(Seat *seat, quint32 serial, Qt::Edges edges); + /** + * Creates a ShellSurface for the given @p window. + * This is an integration feature for QtWayland. On non-wayland platforms this method returns + * @c nullptr as well as for not created QWindows. + * + * The returned ShellSurface will be fully setup, but won't be released. It gets automatically + * destroyed together with the @p window. + * @since 5.28 + **/ + static ShellSurface *fromWindow(QWindow *window); + + /** + * Creates a ShellSurface for the given @p winId. + * This is an integration feature for QtWayland. On non-wayland platforms this method returns + * @c nullptr as well as for not created QWindows. + * + * The returned ShellSurface will be fully setup, but won't be released. It gets automatically + * destroyed together with the QWindow corresponding + * the @p wid. + * @since 5.28 + **/ + static ShellSurface *fromQtWinId(WId wid); + + /** + * @returns The Surface referencing the @p native wl_surface or @c null if there is no such Surface. + * @since 5.28 + **/ + static ShellSurface *get(wl_shell_surface *native); + operator wl_shell_surface*(); operator wl_shell_surface*() const; Q_SIGNALS: /** * Signal is emitted when the ShellSurface received a ping request. * The ShellSurface automatically responds to the ping. **/ void pinged(); void sizeChanged(const QSize &); private: class Private; QScopedPointer d; }; } } Q_DECLARE_METATYPE(KWayland::Client::ShellSurface::TransientFlag) Q_DECLARE_METATYPE(KWayland::Client::ShellSurface::TransientFlags) #endif