diff --git a/autotests/client/test_wayland_shell.cpp b/autotests/client/test_wayland_shell.cpp index 177ce35..508d574 100644 --- a/autotests/client/test_wayland_shell.cpp +++ b/autotests/client/test_wayland_shell.cpp @@ -1,855 +1,922 @@ /******************************************************************** 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 testTransientPopup(); 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::testTransientPopup() +{ + 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); + QCOMPARE(serverSurface->isToplevel(), true); + QCOMPARE(serverSurface->isPopup(), false); + QCOMPARE(serverSurface->isTransient(), false); + QCOMPARE(serverSurface->transientFor(), QPointer()); + QCOMPARE(serverSurface->transientOffset(), QPoint()); + QVERIFY(serverSurface->acceptsKeyboardFocus()); + + 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()); + + // TODO: proper serial checking + surface->setTransientPopup(s2.data(), m_seat, 1, QPoint(10, 20)); + 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(), false); + QCOMPARE(serverSurface->isPopup(), true); + QCOMPARE(serverSurface->isTransient(), true); + QCOMPARE(serverSurface->transientFor(), QPointer(serverSurface2->surface())); + QCOMPARE(serverSurface->transientOffset(), QPoint(10, 20)); + // TODO: honor the flag + QCOMPARE(serverSurface->acceptsKeyboardFocus(), false); + + QCOMPARE(serverSurface2->isToplevel(), true); + QCOMPARE(serverSurface2->isPopup(), false); + QCOMPARE(serverSurface2->isTransient(), false); + QCOMPARE(serverSurface2->transientFor(), QPointer()); + QCOMPARE(serverSurface2->transientOffset(), QPoint()); + + // send popup done + QSignalSpy popupDoneSpy(surface, &ShellSurface::popupDone); + QVERIFY(popupDoneSpy.isValid()); + serverSurface->popupDone(); + QVERIFY(popupDoneSpy.wait()); +} + 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 113c929..f2a7dcc 100644 --- a/src/client/shell.cpp +++ b/src/client/shell.cpp @@ -1,378 +1,390 @@ /******************************************************************** 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) + auto s = reinterpret_cast(data); + Q_ASSERT(s->surface == shellSurface); + emit s->q->popupDone(); } 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::setTransientPopup(Surface *parent, Seat *grabbedSeat, quint32 grabSerial, const QPoint &offset, TransientFlags flags) +{ + Q_ASSERT(isValid()); + Q_ASSERT(parent); + Q_ASSERT(grabbedSeat); + uint32_t wlFlags = 0; + if (flags.testFlag(TransientFlag::NoFocus)) { + wlFlags |= WL_SHELL_SURFACE_TRANSIENT_INACTIVE; + } + wl_shell_surface_set_popup(d->surface, *grabbedSeat, grabSerial, *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 edd6c21..6caffdf 100644 --- a/src/client/shell.h +++ b/src/client/shell.h @@ -1,322 +1,351 @@ /******************************************************************** 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); + /** + * Sets this Surface as a popup transient for @p parent. + * + * A popup is a transient with an added pointer grab on the @p grabbedSeat. + * + * The popup grab can be created if the client has an implicit grab (e.g. button press) + * on the @p grabbedSeat. It needs to pass the @p grabSerial indicating the implicit grab + * to the request for setting the surface. The implicit grab is turned into a popup grab + * which will persist after the implicit grab ends. The popup grab ends when the ShellSurface + * gets destroyed or when the compositor breaks the grab through the @link{popupDone} signal. + * + * @param parent The parent Surface of this ShellSurface + * @param grabbedSeat The Seat on which an implicit grab exists + * @param grabSerial The serial of the implicit grab + * @param offset The offset of this Surface in the parent coordinate system + * @param flags The flags for the transient + * @since 5.33 + **/ + void setTransientPopup(Surface *parent, Seat *grabbedSeat, quint32 grabSerial, 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 &); + /** + * The popupDone signal is sent out when a popup grab is broken, that is, + * when the user clicks a surface that doesn't belong to the client owning + * the popup surface. + * @see setTransientPopup + * @since 5.33 + **/ + void popupDone(); + private: class Private; QScopedPointer d; }; } } Q_DECLARE_METATYPE(KWayland::Client::ShellSurface::TransientFlag) Q_DECLARE_METATYPE(KWayland::Client::ShellSurface::TransientFlags) #endif diff --git a/src/server/shell_interface.cpp b/src/server/shell_interface.cpp index 1fa414a..91a792c 100644 --- a/src/server/shell_interface.cpp +++ b/src/server/shell_interface.cpp @@ -1,464 +1,475 @@ /******************************************************************** 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 "generic_shell_surface_p.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 GenericShellSurface { public: Private(ShellSurfaceInterface *q, ShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource); void ping(); 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); ShellSurfaceInterface *q_func() { return reinterpret_cast(q); } private: // interface callbacks static void pongCallback(wl_client *client, wl_resource *resource, uint32_t serial); 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); void pong(quint32 serial); void setAcceptsFocus(quint32 flags); 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_SHELL_ERROR_ROLE, "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) , GenericShellSurface(q, 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, setAppIdCallback }; #endif ShellSurfaceInterface::ShellSurfaceInterface(ShellInterface *shell, SurfaceInterface *parent, wl_resource *parentResource) : Resource(new Private(this, shell, parent, parentResource)) { Q_D(); connect(d->pingTimer.data(), &QTimer::timeout, this, &ShellSurfaceInterface::pingTimeout); auto unsetSurface = [this] { Q_D(); d->surface = nullptr; }; connect(parent, &Resource::unbound, this, unsetSurface); connect(parent, &QObject::destroyed, this, unsetSurface); } 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(); if (!d->resource) { return; } 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(); if (!d->resource) { return; } // TODO: what about the edges? wl_shell_surface_send_configure(d->resource, 0, size.width(), size.height()); d->client->flush(); } namespace { template <> Qt::Edges edgesToQtEdges(wl_shell_surface_resize edges) { 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; case WL_SHELL_SURFACE_RESIZE_NONE: break; default: Q_UNREACHABLE(); break; } return 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); auto surface = SurfaceInterface::get(parent); if (surface && s->surface == surface) { wl_resource_post_error(surface->resource(), WL_SHELL_ERROR_ROLE, "Cannot be a transient to itself"); return; } s->transientFor = QPointer(surface); 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(); + // we ignore the flags as Qt requests keyboard focus for popups + // if we would honor the flag this could break compositors + // compare QtWayland (5.6), file qwaylandwlshellsurface.cpp:208 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); } 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; } +void ShellSurfaceInterface::popupDone() +{ + Q_D(); + if (isPopup() && d->resource) { + wl_shell_surface_send_popup_done(d->resource); + } +} + 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/shell_interface.h b/src/server/shell_interface.h index 95a0aca..542e273 100644 --- a/src/server/shell_interface.h +++ b/src/server/shell_interface.h @@ -1,306 +1,318 @@ /******************************************************************** 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_SERVER_SHELL_INTERFACE_H #define WAYLAND_SERVER_SHELL_INTERFACE_H #include #include #include "seat_interface.h" #include "global.h" #include "resource.h" class QSize; struct wl_resource; namespace KWayland { namespace Server { class Display; class SeatInterface; class SurfaceInterface; class ShellSurfaceInterface; template class GenericShellSurface; /** * @brief Global for the wl_shell interface. * * @see ShellSurfaceInterface * @see SurfaceInterface **/ class KWAYLANDSERVER_EXPORT ShellInterface : public Global { Q_OBJECT public: virtual ~ShellInterface(); Q_SIGNALS: /** * Emitted whenever a new ShellSurfaceInterface gets created for a SurfaceInterface. **/ void surfaceCreated(KWayland::Server::ShellSurfaceInterface*); private: friend class Display; explicit ShellInterface(Display *display, QObject *parent); class Private; }; /** * @brief Resource for a wl_shell_surface. * * The ShellSurfaceInterface represents a "normal window". It gets created for a * SurfaceInterface, thus has visible content. Through the ShellSurfaceInterface the * client can specify further meta-information about how the SurfaceInterface should be * represented. * * @see SurfaceInterface * @see ShellInterface **/ class KWAYLANDSERVER_EXPORT ShellSurfaceInterface : public Resource { Q_OBJECT /** * The window title **/ Q_PROPERTY(QString title READ title NOTIFY titleChanged) /** * The window class, representing the desktop file name. **/ Q_PROPERTY(QByteArray windowClass READ windowClass NOTIFY windowClassChanged) /** * Whether the window is fullscren. **/ Q_PROPERTY(bool fullscreen READ isFullscreen NOTIFY fullscreenChanged) /** * Whether the window is a normal toplevel window (not a child). **/ Q_PROPERTY(bool toplevel READ isToplevel NOTIFY toplevelChanged) /** * Whether the window is maximized. **/ Q_PROPERTY(bool maximized READ isMaximized NOTIFY maximizedChanged) /** * Whether the ShellSurfaceInterface is a popup for another SurfaceInterface. * * Popup implies transient. * @since 5.5 **/ Q_PROPERTY(bool popup READ isPopup NOTIFY popupChanged) /** * Whether the ShellSurfaceInterface is a transient for another SurfaceInterface. * * Popup implies transient. * @since 5.5 **/ Q_PROPERTY(bool transient READ isTransient NOTIFY transientChanged) /** * Offset of the upper left corner in the parent SurfaceInterface's coordinate system. * @since 5.5 **/ Q_PROPERTY(QPoint transientOffset READ transientOffset NOTIFY transientOffsetChanged) /** * Whether the ShellSurfaceInterface can accept keyboard focus. * * By default ShellSurfaceInterface accepts keyboard focus, only transient surfaces * might not want keyboard focus. * * @since 5.5 **/ Q_PROPERTY(bool acceptsKeyboardFocus READ acceptsKeyboardFocus NOTIFY acceptsKeyboardFocusChanged) public: virtual ~ShellSurfaceInterface(); /** * Pings the client. * The client is required to send a pong. If that is not received in the times tamp * set through setPingTimeout the signal @link pingTimeout @endlink will be emitted. * If a pong is received the signal @link pongReceived @endlink will be emitted. * * @see setPingTimeout * @see pingTimeout * @see pongReceived * @see isPinged **/ void ping(); /** * Sets the ping time out for @link ping @endlink requests to @p msec. * * @param msec The time out in msec * @see ping * @see isPinged **/ void setPingTimeout(uint msec); /** * @returns whether the ShellSurfaceInterface got pinged, but no pong received. * @see ping **/ bool isPinged() const; /** * Requests that the ShellSurfaceInterface resizes the SurfaceInterface to @p size. **/ void requestSize(const QSize &size); /** * @return The SurfaceInterface this ShellSurfaceInterface got created for. **/ SurfaceInterface *surface() const; /** * @returns The ShellInterface which created this ShellSurfaceInterface. **/ ShellInterface *shell() const; QString title() const; QByteArray windowClass() const; bool isFullscreen() const; bool isToplevel() const; bool isMaximized() const; /** * @returns @c true if the ShellSurfaceInterface is a popup. * @see isTransient * @see transientOffset * @see transientFor * @since 5.5 **/ bool isPopup() const; /** * @returns @c true if the ShellSurfaceInterface is a transient or popup for another SurfaceInterface. * @see isPopup * @see transientOffset * @see transientFor * @since 5.5 **/ bool isTransient() const; /** * In case the ShellSurfaceInterface is a transient this is the offset of the ShellSurfaceInterface * in the coordinate system of the SurfaceInterface this surface is a transient for. * * @returns offset in parent coordinate system. * @see isTransient * @see transientFor * @since 5.5 **/ QPoint transientOffset() const; /** * The SurfaceInterface for which this ShellSurfaceInterface is a transient. * This is only relevant if the ShellSurfaceInterface is either a transient or a * popup. * * The transientOffset is in the local coordinate system of the SurfaceInterface * returned by this method. * * @returns The SurfaceInterface for which this Surface is a transient * @see isTransient * @see isPopup * @see transientOffset * @since 5.5 **/ QPointer transientFor() const; /** * Whether the ShellSurfaceInterface can accept keyboard focus. * * This is only relevant for transient and popup windows. By default all ShellSurfaces * accept keyboard focus. * * @returns Whether the ShellSurfaceInterface can accept keyboard focus. * @see isTransient() * @see acceptsKeyboardFocusChanged * @since 5.5 **/ bool acceptsKeyboardFocus() const; + /** + * Sends a popup done event to the shell surface. + * This is only relevant for popup windows. It indicates that the popup grab + * got canceled. This happens when e.g. the user clicks outside of any surface + * of the same client as this ShellSurfaceInterface. It is the task of the + * compositor to send the popupDone event appropriately. + * + * @see isPopup + * @since 5.33 + **/ + void popupDone(); + Q_SIGNALS: /** * Emitted whenever the title changes. **/ void titleChanged(const QString&); /** * Emitted whenever the window class changes. **/ void windowClassChanged(const QByteArray&); /** * Emitted when the ping timed out. * @see ping * @see pingTimeout * @see isPinged **/ void pingTimeout(); /** * Emitted when the server received a pong for this ShellSurfaceInterface. **/ void pongReceived(); void fullscreenChanged(bool); void toplevelChanged(bool); void maximizedChanged(bool); /** * @since 5.5 **/ void popupChanged(bool); /** * @since 5.5 **/ void transientChanged(bool); /** * @since 5.5 **/ void transientOffsetChanged(const QPoint&); /** * @since 5.5 **/ void transientForChanged(); /** * @since 5.5 **/ void acceptsKeyboardFocusChanged(); /** * The surface requested a window move. * * @param seat The SeatInterface on which the surface requested the move * @param serial The serial of the implicit mouse grab which triggered the move * @since 5.5 **/ void moveRequested(KWayland::Server::SeatInterface *seat, quint32 serial); /** * The surface requested a window resize. * * @param seat The SeatInterface on which the surface requested the resize * @param serial The serial of the implicit mouse grab which triggered the resize * @param edges A hint which edges are involved in the resize * @since 5.5 **/ void resizeRequested(KWayland::Server::SeatInterface *seat, quint32 serial, Qt::Edges edges); private: friend class ShellInterface; explicit ShellSurfaceInterface(ShellInterface *shell, SurfaceInterface *parent, wl_resource *parentResource); friend class GenericShellSurface; class Private; Private *d_func() const; }; } } #endif