diff --git a/autotests/client/test_wayland_windowmanagement.cpp b/autotests/client/test_wayland_windowmanagement.cpp index 7d51dff..fbd92bd 100644 --- a/autotests/client/test_wayland_windowmanagement.cpp +++ b/autotests/client/test_wayland_windowmanagement.cpp @@ -1,513 +1,547 @@ /******************************************************************** Copyright 2015 Marco Martin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ // Qt #include // KWin #include "../../src/client/compositor.h" #include "../../src/client/connection_thread.h" #include "../../src/client/event_queue.h" #include "../../src/client/region.h" #include "../../src/client/registry.h" #include "../../src/client/surface.h" #include "../../src/client/plasmawindowmanagement.h" #include "../../src/client/surface.h" #include "../../src/server/display.h" #include "../../src/server/compositor_interface.h" #include "../../src/server/region_interface.h" #include "../../src/server/plasmawindowmanagement_interface.h" #include "../../src/server/surface_interface.h" #include typedef void (KWayland::Server::PlasmaWindowInterface::*ServerWindowSignal)(); Q_DECLARE_METATYPE(ServerWindowSignal) typedef void (KWayland::Server::PlasmaWindowInterface::*ServerWindowBooleanSignal)(bool); Q_DECLARE_METATYPE(ServerWindowBooleanSignal) typedef void (KWayland::Client::PlasmaWindow::*ClientWindowVoidSetter)(); Q_DECLARE_METATYPE(ClientWindowVoidSetter) class TestWindowManagement : public QObject { Q_OBJECT public: explicit TestWindowManagement(QObject *parent = nullptr); private Q_SLOTS: void init(); void testWindowTitle(); void testMinimizedGeometry(); void testUseAfterUnmap(); void testServerDelete(); void testActiveWindowOnUnmapped(); void testDeleteActiveWindow(); void testCreateAfterUnmap(); void testRequests_data(); void testRequests(); void testRequestsBoolean_data(); void testRequestsBoolean(); void testShowingDesktop(); void testRequestShowingDesktop_data(); void testRequestShowingDesktop(); void testParentWindow(); + void testGeometry(); void cleanup(); private: KWayland::Server::Display *m_display; KWayland::Server::CompositorInterface *m_compositorInterface; KWayland::Server::PlasmaWindowManagementInterface *m_windowManagementInterface; KWayland::Server::PlasmaWindowInterface *m_windowInterface; KWayland::Server::SurfaceInterface *m_surfaceInterface = nullptr; KWayland::Client::Surface *m_surface = nullptr; KWayland::Client::ConnectionThread *m_connection; KWayland::Client::Compositor *m_compositor; KWayland::Client::EventQueue *m_queue; KWayland::Client::PlasmaWindowManagement *m_windowManagement; KWayland::Client::PlasmaWindow *m_window; QThread *m_thread; KWayland::Client::Registry *m_registry; }; static const QString s_socketName = QStringLiteral("kwayland-test-wayland-windowmanagement-0"); TestWindowManagement::TestWindowManagement(QObject *parent) : QObject(parent) , m_display(nullptr) , m_compositorInterface(nullptr) , m_connection(nullptr) , m_compositor(nullptr) , m_queue(nullptr) , m_thread(nullptr) { } void TestWindowManagement::init() { using namespace KWayland::Server; qRegisterMetaType("ShowingDesktopState"); delete m_display; m_display = new Display(this); m_display->setSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); // setup connection m_connection = new KWayland::Client::ConnectionThread; QSignalSpy connectedSpy(m_connection, SIGNAL(connected())); m_connection->setSocketName(s_socketName); m_thread = new QThread(this); m_connection->moveToThread(m_thread); m_thread->start(); m_connection->initConnection(); QVERIFY(connectedSpy.wait()); m_queue = new KWayland::Client::EventQueue(this); QVERIFY(!m_queue->isValid()); m_queue->setup(m_connection); QVERIFY(m_queue->isValid()); m_registry = new KWayland::Client::Registry(this); QSignalSpy compositorSpy(m_registry, SIGNAL(compositorAnnounced(quint32,quint32))); QVERIFY(compositorSpy.isValid()); QSignalSpy windowManagementSpy(m_registry, SIGNAL(plasmaWindowManagementAnnounced(quint32,quint32))); QVERIFY(windowManagementSpy.isValid()); QVERIFY(!m_registry->eventQueue()); m_registry->setEventQueue(m_queue); QCOMPARE(m_registry->eventQueue(), m_queue); m_registry->create(m_connection->display()); QVERIFY(m_registry->isValid()); m_registry->setup(); m_compositorInterface = m_display->createCompositor(m_display); m_compositorInterface->create(); QVERIFY(m_compositorInterface->isValid()); QVERIFY(compositorSpy.wait()); m_compositor = m_registry->createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); m_windowManagementInterface = m_display->createPlasmaWindowManagement(m_display); m_windowManagementInterface->create(); QVERIFY(m_windowManagementInterface->isValid()); QVERIFY(windowManagementSpy.wait()); m_windowManagement = m_registry->createPlasmaWindowManagement(windowManagementSpy.first().first().value(), windowManagementSpy.first().last().value(), this); QSignalSpy windowSpy(m_windowManagement, SIGNAL(windowCreated(KWayland::Client::PlasmaWindow *))); QVERIFY(windowSpy.isValid()); m_windowInterface = m_windowManagementInterface->createWindow(this); QVERIFY(windowSpy.wait()); m_window = windowSpy.first().first().value(); QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); m_surface = m_compositor->createSurface(this); QVERIFY(m_surface); QVERIFY(serverSurfaceCreated.wait()); m_surfaceInterface = serverSurfaceCreated.first().first().value(); QVERIFY(m_surfaceInterface); } void TestWindowManagement::testWindowTitle() { m_windowInterface->setTitle(QStringLiteral("Test Title")); QSignalSpy titleSpy(m_window, SIGNAL(titleChanged())); QVERIFY(titleSpy.isValid()); QVERIFY(titleSpy.wait()); QCOMPARE(m_window->title(), QString::fromUtf8("Test Title")); } void TestWindowManagement::testMinimizedGeometry() { m_window->setMinimizedGeometry(m_surface, QRect(5, 10, 100, 200)); QSignalSpy geometrySpy(m_windowInterface, SIGNAL(minimizedGeometriesChanged())); QVERIFY(geometrySpy.isValid()); QVERIFY(geometrySpy.wait()); QCOMPARE(m_windowInterface->minimizedGeometries().values().first(), QRect(5, 10, 100, 200)); m_window->unsetMinimizedGeometry(m_surface); QVERIFY(geometrySpy.wait()); QVERIFY(m_windowInterface->minimizedGeometries().isEmpty()); } void TestWindowManagement::cleanup() { if (m_surface) { delete m_surface; m_surface = nullptr; } if (m_compositor) { delete m_compositor; m_compositor = nullptr; } if (m_queue) { delete m_queue; m_queue = nullptr; } if (m_windowManagement) { delete m_windowManagement; m_windowManagement = nullptr; } if (m_registry) { delete m_registry; m_registry = nullptr; } if (m_thread) { if (m_connection) { m_connection->deleteLater(); } m_thread->quit(); m_thread->wait(); delete m_thread; m_thread = nullptr; } m_connection = nullptr; delete m_windowManagementInterface; m_windowManagementInterface = nullptr; delete m_windowInterface; m_windowInterface = nullptr; delete m_surfaceInterface; m_surfaceInterface = nullptr; delete m_display; m_display = nullptr; } void TestWindowManagement::testUseAfterUnmap() { // this test verifies that when the client uses a window after it's unmapped, things don't break QSignalSpy unmappedSpy(m_window, &KWayland::Client::PlasmaWindow::unmapped); QVERIFY(unmappedSpy.isValid()); QSignalSpy destroyedSpy(m_window, &QObject::destroyed); QVERIFY(destroyedSpy.isValid()); m_windowInterface->unmap(); m_window->requestClose(); QVERIFY(unmappedSpy.wait()); QVERIFY(destroyedSpy.wait()); m_window = nullptr; QSignalSpy serverDestroyedSpy(m_windowInterface, &QObject::destroyed); QVERIFY(serverDestroyedSpy.isValid()); QVERIFY(serverDestroyedSpy.wait()); m_windowInterface = nullptr; } void TestWindowManagement::testServerDelete() { QSignalSpy unmappedSpy(m_window, &KWayland::Client::PlasmaWindow::unmapped); QVERIFY(unmappedSpy.isValid()); QSignalSpy destroyedSpy(m_window, &QObject::destroyed); QVERIFY(destroyedSpy.isValid()); delete m_windowInterface; m_windowInterface = nullptr; QVERIFY(unmappedSpy.wait()); QVERIFY(destroyedSpy.wait()); m_window = nullptr; } void TestWindowManagement::testActiveWindowOnUnmapped() { // This test verifies that unmapping the active window changes the active window. // first make the window active QVERIFY(!m_windowManagement->activeWindow()); QVERIFY(!m_window->isActive()); QSignalSpy activeWindowChangedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::activeWindowChanged); QVERIFY(activeWindowChangedSpy.isValid()); m_windowInterface->setActive(true); QVERIFY(activeWindowChangedSpy.wait()); QCOMPARE(m_windowManagement->activeWindow(), m_window); QVERIFY(m_window->isActive()); // now unmap should change the active window QSignalSpy destroyedSpy(m_window, &QObject::destroyed); QVERIFY(destroyedSpy.isValid()); QSignalSpy serverDestroyedSpy(m_windowInterface, &QObject::destroyed); QVERIFY(serverDestroyedSpy.isValid()); m_windowManagementInterface->unmapWindow(m_windowInterface); QVERIFY(activeWindowChangedSpy.wait()); QVERIFY(!m_windowManagement->activeWindow()); QVERIFY(destroyedSpy.wait()); QCOMPARE(destroyedSpy.count(), 1); m_window = nullptr; QVERIFY(serverDestroyedSpy.wait()); m_windowInterface = nullptr; } void TestWindowManagement::testDeleteActiveWindow() { // This test verifies that deleting the active window on client side changes the active window // first make the window active QVERIFY(!m_windowManagement->activeWindow()); QVERIFY(!m_window->isActive()); QSignalSpy activeWindowChangedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::activeWindowChanged); QVERIFY(activeWindowChangedSpy.isValid()); m_windowInterface->setActive(true); QVERIFY(activeWindowChangedSpy.wait()); QCOMPARE(activeWindowChangedSpy.count(), 1); QCOMPARE(m_windowManagement->activeWindow(), m_window); QVERIFY(m_window->isActive()); // delete the client side window - that's semantically kind of wrong, but shouldn't make our code crash delete m_window; m_window = nullptr; QCOMPARE(activeWindowChangedSpy.count(), 2); QVERIFY(!m_windowManagement->activeWindow()); } void TestWindowManagement::testCreateAfterUnmap() { // this test verifies that we don't get a protocol error on client side when creating an already unmapped window. QCOMPARE(m_windowManagement->children().count(), 1); // create and unmap in one go // client will first handle the create, the unmap will be sent once the server side is bound auto serverWindow = m_windowManagementInterface->createWindow(this); serverWindow->unmap(); QCOMPARE(m_windowManagementInterface->children().count(), 0); QCoreApplication::instance()->processEvents(); QCoreApplication::instance()->processEvents(QEventLoop::WaitForMoreEvents); QTRY_COMPARE(m_windowManagement->children().count(), 2); auto window = dynamic_cast(m_windowManagement->children().last()); QVERIFY(window); // now this is not yet on the server, on the server it will be after next roundtrip // which we can trigger by waiting for destroy of the newly created window. // why destroy? Because we will get the unmap which triggers a destroy QSignalSpy clientDestroyedSpy(window, &QObject::destroyed); QVERIFY(clientDestroyedSpy.isValid()); QVERIFY(clientDestroyedSpy.wait()); QCOMPARE(m_windowManagement->children().count(), 1); // the server side created a helper PlasmaWindowInterface with PlasmaWindowManagementInterface as parent // it emitted unmapped so we can be sure it will be destroyed directly QCOMPARE(m_windowManagementInterface->children().count(), 1); auto helperWindow = qobject_cast(m_windowManagementInterface->children().first()); QVERIFY(helperWindow); QSignalSpy helperDestroyedSpy(helperWindow, &QObject::destroyed); QVERIFY(helperDestroyedSpy.isValid()); QVERIFY(helperDestroyedSpy.wait()); } void TestWindowManagement::testRequests_data() { using namespace KWayland::Server; using namespace KWayland::Client; QTest::addColumn("changedSignal"); QTest::addColumn("requester"); QTest::newRow("close") << &PlasmaWindowInterface::closeRequested << &PlasmaWindow::requestClose; QTest::newRow("move") << &PlasmaWindowInterface::moveRequested << &PlasmaWindow::requestMove; QTest::newRow("resize") << &PlasmaWindowInterface::resizeRequested << &PlasmaWindow::requestResize; } void TestWindowManagement::testRequests() { // this test case verifies all the different requests on a PlasmaWindow QFETCH(ServerWindowSignal, changedSignal); QSignalSpy requestSpy(m_windowInterface, changedSignal); QVERIFY(requestSpy.isValid()); QFETCH(ClientWindowVoidSetter, requester); (m_window->*(requester))(); QVERIFY(requestSpy.wait()); } void TestWindowManagement::testRequestsBoolean_data() { using namespace KWayland::Server; QTest::addColumn("changedSignal"); QTest::addColumn("flag"); QTest::newRow("activate") << &PlasmaWindowInterface::activeRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ACTIVE); QTest::newRow("minimized") << &PlasmaWindowInterface::minimizedRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZED); QTest::newRow("maximized") << &PlasmaWindowInterface::maximizedRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZED); QTest::newRow("fullscreen") << &PlasmaWindowInterface::fullscreenRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREEN); QTest::newRow("keepAbove") << &PlasmaWindowInterface::keepAboveRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_ABOVE); QTest::newRow("keepBelow") << &PlasmaWindowInterface::keepBelowRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_BELOW); QTest::newRow("demandsAttention") << &PlasmaWindowInterface::demandsAttentionRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_DEMANDS_ATTENTION); QTest::newRow("closeable") << &PlasmaWindowInterface::closeableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_CLOSEABLE); QTest::newRow("minimizable") << &PlasmaWindowInterface::minimizeableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZABLE); QTest::newRow("maximizable") << &PlasmaWindowInterface::maximizeableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZABLE); QTest::newRow("fullscreenable") << &PlasmaWindowInterface::fullscreenableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREENABLE); QTest::newRow("skiptaskbar") << &PlasmaWindowInterface::skipTaskbarRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPTASKBAR); QTest::newRow("shadeable") << &PlasmaWindowInterface::shadeableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADEABLE); QTest::newRow("shaded") << &PlasmaWindowInterface::shadedRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADED); QTest::newRow("movable") << &PlasmaWindowInterface::movableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MOVABLE); QTest::newRow("resizable") << &PlasmaWindowInterface::resizableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_RESIZABLE); QTest::newRow("virtualDesktopChangeable") << &PlasmaWindowInterface::virtualDesktopChangeableRequested << int(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_VIRTUAL_DESKTOP_CHANGEABLE); } void TestWindowManagement::testRequestsBoolean() { // this test case verifies all the different requests on a PlasmaWindow QFETCH(ServerWindowBooleanSignal, changedSignal); QSignalSpy requestSpy(m_windowInterface, changedSignal); QVERIFY(requestSpy.isValid()); QFETCH(int, flag); org_kde_plasma_window_set_state(*m_window, flag, flag); QVERIFY(requestSpy.wait()); QCOMPARE(requestSpy.count(), 1); QCOMPARE(requestSpy.first().first().toBool(), true); org_kde_plasma_window_set_state(*m_window, flag, 0); QVERIFY(requestSpy.wait()); QCOMPARE(requestSpy.count(), 2); QCOMPARE(requestSpy.last().first().toBool(), false); } void TestWindowManagement::testShowingDesktop() { using namespace KWayland::Server; // this test verifies setting the showing desktop state QVERIFY(!m_windowManagement->isShowingDesktop()); QSignalSpy showingDesktopChangedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::showingDesktopChanged); QVERIFY(showingDesktopChangedSpy.isValid()); m_windowManagementInterface->setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState::Enabled); QVERIFY(showingDesktopChangedSpy.wait()); QCOMPARE(showingDesktopChangedSpy.count(), 1); QCOMPARE(showingDesktopChangedSpy.first().first().toBool(), true); QVERIFY(m_windowManagement->isShowingDesktop()); // setting to same should not change m_windowManagementInterface->setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState::Enabled); QVERIFY(!showingDesktopChangedSpy.wait(100)); QCOMPARE(showingDesktopChangedSpy.count(), 1); // setting to other state should change m_windowManagementInterface->setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState::Disabled); QVERIFY(showingDesktopChangedSpy.wait()); QCOMPARE(showingDesktopChangedSpy.count(), 2); QCOMPARE(showingDesktopChangedSpy.first().first().toBool(), true); QCOMPARE(showingDesktopChangedSpy.last().first().toBool(), false); QVERIFY(!m_windowManagement->isShowingDesktop()); } void TestWindowManagement::testRequestShowingDesktop_data() { using namespace KWayland::Server; QTest::addColumn("value"); QTest::addColumn("expectedValue"); QTest::newRow("enable") << true << PlasmaWindowManagementInterface::ShowingDesktopState::Enabled; QTest::newRow("disable") << false << PlasmaWindowManagementInterface::ShowingDesktopState::Disabled; } void TestWindowManagement::testRequestShowingDesktop() { // this test verifies requesting show desktop state using namespace KWayland::Server; QSignalSpy requestSpy(m_windowManagementInterface, &PlasmaWindowManagementInterface::requestChangeShowingDesktop); QVERIFY(requestSpy.isValid()); QFETCH(bool, value); m_windowManagement->setShowingDesktop(value); QVERIFY(requestSpy.wait()); QCOMPARE(requestSpy.count(), 1); QTEST(requestSpy.first().first().value(), "expectedValue"); } void TestWindowManagement::testParentWindow() { using namespace KWayland::Client; // this test verifies the functionality of ParentWindows QCOMPARE(m_windowManagement->windows().count(), 1); auto parentWindow = m_windowManagement->windows().first(); QVERIFY(parentWindow); QVERIFY(parentWindow->parentWindow().isNull()); // now let's create a second window QSignalSpy windowAddedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated); QVERIFY(windowAddedSpy.isValid()); auto serverTransient = m_windowManagementInterface->createWindow(this); serverTransient->setParentWindow(m_windowInterface); QVERIFY(windowAddedSpy.wait()); auto transient = windowAddedSpy.first().first().value(); QCOMPARE(transient->parentWindow().data(), parentWindow); // let's unset the parent QSignalSpy parentWindowChangedSpy(transient, &PlasmaWindow::parentWindowChanged); QVERIFY(parentWindowChangedSpy.isValid()); serverTransient->setParentWindow(nullptr); QVERIFY(parentWindowChangedSpy.wait()); QVERIFY(transient->parentWindow().isNull()); // and set it again serverTransient->setParentWindow(m_windowInterface); QVERIFY(parentWindowChangedSpy.wait()); QCOMPARE(transient->parentWindow().data(), parentWindow); // now let's try to unmap the parent m_windowInterface->unmap(); m_window = nullptr; m_windowInterface = nullptr; QVERIFY(parentWindowChangedSpy.wait()); QVERIFY(transient->parentWindow().isNull()); } +void TestWindowManagement::testGeometry() +{ + using namespace KWayland::Client; + QVERIFY(m_window); + QCOMPARE(m_window->geometry(), QRect()); + QSignalSpy windowGeometryChangedSpy(m_window, &PlasmaWindow::geometryChanged); + QVERIFY(windowGeometryChangedSpy.isValid()); + m_windowInterface->setGeometry(QRect(20, -10, 30, 40)); + QVERIFY(windowGeometryChangedSpy.wait()); + QCOMPARE(m_window->geometry(), QRect(20, -10, 30, 40)); + // setting an empty geometry should not be sent to the client + m_windowInterface->setGeometry(QRect()); + QVERIFY(!windowGeometryChangedSpy.wait(10)); + // setting to the geometry which the client still has should not trigger signal + m_windowInterface->setGeometry(QRect(20, -10, 30, 40)); + QVERIFY(!windowGeometryChangedSpy.wait(10)); + // setting another geometry should work, though + m_windowInterface->setGeometry(QRect(0, 0, 35, 45)); + QVERIFY(windowGeometryChangedSpy.wait()); + QCOMPARE(windowGeometryChangedSpy.count(), 2); + QCOMPARE(m_window->geometry(), QRect(0, 0, 35, 45)); + + // let's bind a second PlasmaWindowManagement to verify the initial setting + QScopedPointer pm(m_registry->createPlasmaWindowManagement(m_registry->interface(Registry::Interface::PlasmaWindowManagement).name, + m_registry->interface(Registry::Interface::PlasmaWindowManagement).version)); + QVERIFY(!pm.isNull()); + QSignalSpy windowAddedSpy(pm.data(), &PlasmaWindowManagement::windowCreated); + QVERIFY(windowAddedSpy.isValid()); + QVERIFY(windowAddedSpy.wait()); + auto window = pm->windows().first(); + QCOMPARE(window->geometry(), QRect(0, 0, 35, 45)); +} + QTEST_GUILESS_MAIN(TestWindowManagement) #include "test_wayland_windowmanagement.moc" diff --git a/src/client/plasmawindowmanagement.cpp b/src/client/plasmawindowmanagement.cpp index a34ff5e..c7329ad 100644 --- a/src/client/plasmawindowmanagement.cpp +++ b/src/client/plasmawindowmanagement.cpp @@ -1,865 +1,885 @@ /******************************************************************** Copyright 2015 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "plasmawindowmanagement.h" #include "plasmawindowmodel.h" #include "event_queue.h" #include "output.h" #include "surface.h" #include "wayland_pointer_p.h" // Wayland #include #include namespace KWayland { namespace Client { class PlasmaWindowManagement::Private { public: Private(PlasmaWindowManagement *q); WaylandPointer wm; EventQueue *queue = nullptr; bool showingDesktop = false; QList windows; PlasmaWindow *activeWindow = nullptr; void setup(org_kde_plasma_window_management *wm); private: static void showDesktopCallback(void *data, org_kde_plasma_window_management *org_kde_plasma_window_management, uint32_t state); static void windowCallback(void *data, org_kde_plasma_window_management *org_kde_plasma_window_management, uint32_t id); void setShowDesktop(bool set); void windowCreated(org_kde_plasma_window *id, quint32 internalId); static struct org_kde_plasma_window_management_listener s_listener; PlasmaWindowManagement *q; }; class PlasmaWindow::Private { public: Private(org_kde_plasma_window *window, quint32 internalId, PlasmaWindow *q); WaylandPointer window; quint32 internalId; QString title; QString appId; quint32 desktop = 0; bool active = false; bool minimized = false; bool maximized = false; bool fullscreen = false; bool keepAbove = false; bool keepBelow = false; bool onAllDesktops = false; bool demandsAttention = false; bool closeable = false; bool minimizeable = false; bool maximizeable = false; bool fullscreenable = false; bool skipTaskbar = false; bool shadeable = false; bool shaded = false; bool movable = false; bool resizable = false; bool virtualDesktopChangeable = false; QIcon icon; PlasmaWindowManagement *wm = nullptr; bool unmapped = false; QPointer parentWindow; QMetaObject::Connection parentWindowUnmappedConnection; + QRect geometry; private: static void titleChangedCallback(void *data, org_kde_plasma_window *window, const char *title); static void appIdChangedCallback(void *data, org_kde_plasma_window *window, const char *app_id); static void stateChangedCallback(void *data, org_kde_plasma_window *window, uint32_t state); static void virtualDesktopChangedCallback(void *data, org_kde_plasma_window *window, int32_t number); static void themedIconNameChangedCallback(void *data, org_kde_plasma_window *window, const char *name); static void unmappedCallback(void *data, org_kde_plasma_window *window); static void initialStateCallback(void *data, org_kde_plasma_window *window); static void parentWindowCallback(void *data, org_kde_plasma_window *window, org_kde_plasma_window *parent); + static void windowGeometryCallback(void *data, org_kde_plasma_window *window, int32_t x, int32_t y, uint32_t width, uint32_t height); void setActive(bool set); void setMinimized(bool set); void setMaximized(bool set); void setFullscreen(bool set); void setKeepAbove(bool set); void setKeepBelow(bool set); void setOnAllDesktops(bool set); void setDemandsAttention(bool set); void setCloseable(bool set); void setMinimizeable(bool set); void setMaximizeable(bool set); void setFullscreenable(bool set); void setSkipTaskbar(bool skip); void setShadeable(bool set); void setShaded(bool set); void setMovable(bool set); void setResizable(bool set); void setVirtualDesktopChangeable(bool set); void setParentWindow(PlasmaWindow *parentWindow); static Private *cast(void *data) { return reinterpret_cast(data); } PlasmaWindow *q; static struct org_kde_plasma_window_listener s_listener; }; PlasmaWindowManagement::Private::Private(PlasmaWindowManagement *q) : q(q) { } org_kde_plasma_window_management_listener PlasmaWindowManagement::Private::s_listener = { showDesktopCallback, windowCallback }; void PlasmaWindowManagement::Private::setup(org_kde_plasma_window_management *windowManagement) { Q_ASSERT(!wm); Q_ASSERT(windowManagement); wm.setup(windowManagement); org_kde_plasma_window_management_add_listener(windowManagement, &s_listener, this); } void PlasmaWindowManagement::Private::showDesktopCallback(void *data, org_kde_plasma_window_management *org_kde_plasma_window_management, uint32_t state) { auto wm = reinterpret_cast(data); Q_ASSERT(wm->wm == org_kde_plasma_window_management); switch (state) { case ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_ENABLED: wm->setShowDesktop(true); break; case ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_DISABLED: wm->setShowDesktop(false); break; default: Q_UNREACHABLE(); break; } } void PlasmaWindowManagement::Private::setShowDesktop(bool set) { if (showingDesktop == set) { return; } showingDesktop = set; emit q->showingDesktopChanged(showingDesktop); } void PlasmaWindowManagement::Private::windowCallback(void *data, org_kde_plasma_window_management *interface, uint32_t id) { auto wm = reinterpret_cast(data); Q_ASSERT(wm->wm == interface); QTimer *timer = new QTimer(); timer->setSingleShot(true); timer->setInterval(0); QObject::connect(timer, &QTimer::timeout, wm->q, [timer, wm, id] { wm->windowCreated(org_kde_plasma_window_management_get_window(wm->wm, id), id); timer->deleteLater(); }, Qt::QueuedConnection ); timer->start(); } void PlasmaWindowManagement::Private::windowCreated(org_kde_plasma_window *id, quint32 internalId) { if (queue) { queue->addProxy(id); } PlasmaWindow *window = new PlasmaWindow(q, id, internalId); window->d->wm = q; windows << window; QObject::connect(window, &QObject::destroyed, q, [this, window] { windows.removeAll(window); if (activeWindow == window) { activeWindow = nullptr; emit q->activeWindowChanged(); } } ); QObject::connect(window, &PlasmaWindow::unmapped, q, [this, window] { if (activeWindow == window) { activeWindow = nullptr; emit q->activeWindowChanged(); } } ); QObject::connect(window, &PlasmaWindow::activeChanged, q, [this, window] { if (window->isActive()) { if (activeWindow == window) { return; } activeWindow = window; emit q->activeWindowChanged(); } else { if (activeWindow == window) { activeWindow = nullptr; emit q->activeWindowChanged(); } } } ); } PlasmaWindowManagement::PlasmaWindowManagement(QObject *parent) : QObject(parent) , d(new Private(this)) { } PlasmaWindowManagement::~PlasmaWindowManagement() { release(); } void PlasmaWindowManagement::destroy() { if (!d->wm) { return; } emit interfaceAboutToBeDestroyed(); d->wm.destroy(); } void PlasmaWindowManagement::release() { if (!d->wm) { return; } emit interfaceAboutToBeReleased(); d->wm.release(); } void PlasmaWindowManagement::setup(org_kde_plasma_window_management *wm) { d->setup(wm); } void PlasmaWindowManagement::setEventQueue(EventQueue *queue) { d->queue = queue; } EventQueue *PlasmaWindowManagement::eventQueue() { return d->queue; } bool PlasmaWindowManagement::isValid() const { return d->wm.isValid(); } PlasmaWindowManagement::operator org_kde_plasma_window_management*() { return d->wm; } PlasmaWindowManagement::operator org_kde_plasma_window_management*() const { return d->wm; } void PlasmaWindowManagement::hideDesktop() { setShowingDesktop(false); } void PlasmaWindowManagement::showDesktop() { setShowingDesktop(true); } void PlasmaWindowManagement::setShowingDesktop(bool show) { org_kde_plasma_window_management_show_desktop(d->wm, show ? ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_ENABLED : ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_DISABLED); } bool PlasmaWindowManagement::isShowingDesktop() const { return d->showingDesktop; } QList< PlasmaWindow* > PlasmaWindowManagement::windows() const { return d->windows; } PlasmaWindow *PlasmaWindowManagement::activeWindow() const { return d->activeWindow; } PlasmaWindowModel *PlasmaWindowManagement::createWindowModel() { return new PlasmaWindowModel(this); } org_kde_plasma_window_listener PlasmaWindow::Private::s_listener = { titleChangedCallback, appIdChangedCallback, stateChangedCallback, virtualDesktopChangedCallback, themedIconNameChangedCallback, unmappedCallback, initialStateCallback, - parentWindowCallback + parentWindowCallback, + windowGeometryCallback }; void PlasmaWindow::Private::parentWindowCallback(void *data, org_kde_plasma_window *window, org_kde_plasma_window *parent) { Q_UNUSED(window) Private *p = cast(data); const auto windows = p->wm->windows(); auto it = std::find_if(windows.begin(), windows.end(), [parent] (const PlasmaWindow *w) { return *w == parent; } ); p->setParentWindow(it != windows.end() ? *it : nullptr); } +void PlasmaWindow::Private::windowGeometryCallback(void *data, org_kde_plasma_window *window, int32_t x, int32_t y, uint32_t width, uint32_t height) +{ + Q_UNUSED(window) + Private *p = cast(data); + QRect geo(x, y, width, height); + if (geo == p->geometry) { + return; + } + p->geometry = geo; + emit p->q->geometryChanged(); +} + void PlasmaWindow::Private::setParentWindow(PlasmaWindow *parent) { const auto old = parentWindow; QObject::disconnect(parentWindowUnmappedConnection); if (parent && !parent->d->unmapped) { parentWindow = QPointer(parent); parentWindowUnmappedConnection = QObject::connect(parent, &PlasmaWindow::unmapped, q, [this] { setParentWindow(nullptr); } ); } else { parentWindow = QPointer(); parentWindowUnmappedConnection = QMetaObject::Connection(); } if (parentWindow.data() != old.data()) { emit q->parentWindowChanged(); } } void PlasmaWindow::Private::initialStateCallback(void *data, org_kde_plasma_window *window) { Q_UNUSED(window) Private *p = cast(data); if (!p->unmapped) { emit p->wm->windowCreated(p->q); } } void PlasmaWindow::Private::titleChangedCallback(void *data, org_kde_plasma_window *window, const char *title) { Q_UNUSED(window) Private *p = cast(data); const QString t = QString::fromUtf8(title); if (p->title == t) { return; } p->title = t; emit p->q->titleChanged(); } void PlasmaWindow::Private::appIdChangedCallback(void *data, org_kde_plasma_window *window, const char *appId) { Q_UNUSED(window) Private *p = cast(data); const QString s = QString::fromUtf8(appId); if (s == p->appId) { return; } p->appId = s; emit p->q->appIdChanged(); } void PlasmaWindow::Private::virtualDesktopChangedCallback(void *data, org_kde_plasma_window *window, int32_t number) { Q_UNUSED(window) Private *p = cast(data); if (p->desktop == static_cast(number)) { return; } p->desktop = number; emit p->q->virtualDesktopChanged(); } void PlasmaWindow::Private::unmappedCallback(void *data, org_kde_plasma_window *window) { auto p = cast(data); Q_UNUSED(window); p->unmapped = true; emit p->q->unmapped(); p->q->deleteLater(); } void PlasmaWindow::Private::stateChangedCallback(void *data, org_kde_plasma_window *window, uint32_t state) { auto p = cast(data); Q_UNUSED(window); p->setActive(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ACTIVE); p->setMinimized(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZED); p->setMaximized(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZED); p->setFullscreen(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREEN); p->setKeepAbove(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_ABOVE); p->setKeepBelow(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_BELOW); p->setOnAllDesktops(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ON_ALL_DESKTOPS); p->setDemandsAttention(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_DEMANDS_ATTENTION); p->setCloseable(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_CLOSEABLE); p->setFullscreenable(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREENABLE); p->setMaximizeable(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZABLE); p->setMinimizeable(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZABLE); p->setSkipTaskbar(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPTASKBAR); p->setShadeable(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADEABLE); p->setShaded(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADED); p->setMovable(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MOVABLE); p->setResizable(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_RESIZABLE); p->setVirtualDesktopChangeable(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_VIRTUAL_DESKTOP_CHANGEABLE); } void PlasmaWindow::Private::themedIconNameChangedCallback(void *data, org_kde_plasma_window *window, const char *name) { auto p = cast(data); Q_UNUSED(window); const QString themedName = QString::fromUtf8(name); if (!themedName.isEmpty()) { QIcon icon = QIcon::fromTheme(themedName); p->icon = icon; } else { p->icon = QIcon(); } emit p->q->iconChanged(); } void PlasmaWindow::Private::setActive(bool set) { if (active == set) { return; } active = set; emit q->activeChanged(); } void PlasmaWindow::Private::setFullscreen(bool set) { if (fullscreen == set) { return; } fullscreen = set; emit q->fullscreenChanged(); } void PlasmaWindow::Private::setKeepAbove(bool set) { if (keepAbove == set) { return; } keepAbove = set; emit q->keepAboveChanged(); } void PlasmaWindow::Private::setKeepBelow(bool set) { if (keepBelow == set) { return; } keepBelow = set; emit q->keepBelowChanged(); } void PlasmaWindow::Private::setMaximized(bool set) { if (maximized == set) { return; } maximized = set; emit q->maximizedChanged(); } void PlasmaWindow::Private::setMinimized(bool set) { if (minimized == set) { return; } minimized = set; emit q->minimizedChanged(); } void PlasmaWindow::Private::setOnAllDesktops(bool set) { if (onAllDesktops == set) { return; } onAllDesktops = set; emit q->onAllDesktopsChanged(); } void PlasmaWindow::Private::setDemandsAttention(bool set) { if (demandsAttention == set) { return; } demandsAttention = set; emit q->demandsAttentionChanged(); } void PlasmaWindow::Private::setCloseable(bool set) { if (closeable == set) { return; } closeable = set; emit q->closeableChanged(); } void PlasmaWindow::Private::setFullscreenable(bool set) { if (fullscreenable == set) { return; } fullscreenable = set; emit q->fullscreenableChanged(); } void PlasmaWindow::Private::setMaximizeable(bool set) { if (maximizeable == set) { return; } maximizeable = set; emit q->maximizeableChanged(); } void PlasmaWindow::Private::setMinimizeable(bool set) { if (minimizeable == set) { return; } minimizeable = set; emit q->minimizeableChanged(); } void PlasmaWindow::Private::setSkipTaskbar(bool skip) { if (skipTaskbar == skip) { return; } skipTaskbar = skip; emit q->skipTaskbarChanged(); } void PlasmaWindow::Private::setShadeable(bool set) { if (shadeable == set) { return; } shadeable = set; emit q->shadeableChanged(); } void PlasmaWindow::Private::setShaded(bool set) { if (shaded == set) { return; } shaded = set; emit q->shadedChanged(); } void PlasmaWindow::Private::setMovable(bool set) { if (movable == set) { return; } movable = set; emit q->movableChanged(); } void PlasmaWindow::Private::setResizable(bool set) { if (resizable == set) { return; } resizable = set; emit q->resizableChanged(); } void PlasmaWindow::Private::setVirtualDesktopChangeable(bool set) { if (virtualDesktopChangeable == set) { return; } virtualDesktopChangeable = set; emit q->virtualDesktopChangeableChanged(); } PlasmaWindow::Private::Private(org_kde_plasma_window *w, quint32 internalId, PlasmaWindow *q) : internalId(internalId) , q(q) { window.setup(w); org_kde_plasma_window_add_listener(w, &s_listener, this); } PlasmaWindow::PlasmaWindow(PlasmaWindowManagement *parent, org_kde_plasma_window *window, quint32 internalId) : QObject(parent) , d(new Private(window, internalId, this)) { } PlasmaWindow::~PlasmaWindow() { release(); } void PlasmaWindow::destroy() { d->window.destroy(); } void PlasmaWindow::release() { d->window.release(); } bool PlasmaWindow::isValid() const { return d->window.isValid(); } PlasmaWindow::operator org_kde_plasma_window*() const { return d->window; } PlasmaWindow::operator org_kde_plasma_window*() { return d->window; } QString PlasmaWindow::appId() const { return d->appId; } QString PlasmaWindow::title() const { return d->title; } quint32 PlasmaWindow::virtualDesktop() const { return d->desktop; } bool PlasmaWindow::isActive() const { return d->active; } bool PlasmaWindow::isFullscreen() const { return d->fullscreen; } bool PlasmaWindow::isKeepAbove() const { return d->keepAbove; } bool PlasmaWindow::isKeepBelow() const { return d->keepBelow; } bool PlasmaWindow::isMaximized() const { return d->maximized; } bool PlasmaWindow::isMinimized() const { return d->minimized; } bool PlasmaWindow::isOnAllDesktops() const { return d->onAllDesktops; } bool PlasmaWindow::isDemandingAttention() const { return d->demandsAttention; } bool PlasmaWindow::isCloseable() const { return d->closeable; } bool PlasmaWindow::isFullscreenable() const { return d->fullscreenable; } bool PlasmaWindow::isMaximizeable() const { return d->maximizeable; } bool PlasmaWindow::isMinimizeable() const { return d->minimizeable; } bool PlasmaWindow::skipTaskbar() const { return d->skipTaskbar; } QIcon PlasmaWindow::icon() const { return d->icon; } bool PlasmaWindow::isShadeable() const { return d->shadeable; } bool PlasmaWindow::isShaded() const { return d->shaded; } bool PlasmaWindow::isResizable() const { return d->resizable; } bool PlasmaWindow::isMovable() const { return d->movable; } bool PlasmaWindow::isVirtualDesktopChangeable() const { return d->virtualDesktopChangeable; } void PlasmaWindow::requestActivate() { org_kde_plasma_window_set_state(d->window, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ACTIVE, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ACTIVE); } void PlasmaWindow::requestClose() { org_kde_plasma_window_close(d->window); } void PlasmaWindow::requestMove() { org_kde_plasma_window_request_move(d->window); } void PlasmaWindow::requestResize() { org_kde_plasma_window_request_resize(d->window); } void PlasmaWindow::requestVirtualDesktop(quint32 desktop) { org_kde_plasma_window_set_virtual_desktop(d->window, desktop); } void PlasmaWindow::requestToggleMinimized() { if (d->minimized) { org_kde_plasma_window_set_state(d->window, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZED, 0); } else { org_kde_plasma_window_set_state(d->window, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZED, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZED); } } void PlasmaWindow::requestToggleMaximized() { if (d->maximized) { org_kde_plasma_window_set_state(d->window, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZED, 0); } else { org_kde_plasma_window_set_state(d->window, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZED, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZED); } } void PlasmaWindow::setMinimizedGeometry(Surface *panel, const QRect &geom) { org_kde_plasma_window_set_minimized_geometry(d->window, *panel, geom.x(), geom.y(), geom.width(), geom.height()); } void PlasmaWindow::unsetMinimizedGeometry(Surface *panel) { org_kde_plasma_window_unset_minimized_geometry(d->window, *panel); } void PlasmaWindow::requestToggleShaded() { if (d->shaded) { org_kde_plasma_window_set_state(d->window, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADED, 0); } else { org_kde_plasma_window_set_state(d->window, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADED, ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADED); } } quint32 PlasmaWindow::internalId() const { return d->internalId; } QPointer PlasmaWindow::parentWindow() const { return d->parentWindow; } +QRect PlasmaWindow::geometry() const +{ + return d->geometry; +} + } } diff --git a/src/client/plasmawindowmanagement.h b/src/client/plasmawindowmanagement.h index d3faac6..0d7d5d8 100644 --- a/src/client/plasmawindowmanagement.h +++ b/src/client/plasmawindowmanagement.h @@ -1,595 +1,608 @@ /******************************************************************** Copyright 2015 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #ifndef WAYLAND_PLASMAWINDOWMANAGEMENT_H #define WAYLAND_PLASMAWINDOWMANAGEMENT_H #include #include #include #include struct org_kde_plasma_window_management; struct org_kde_plasma_window; namespace KWayland { namespace Client { class EventQueue; class PlasmaWindow; class PlasmaWindowModel; class Surface; /** * @short Wrapper for the org_kde_plasma_window_management interface. * * PlasmaWindowManagement is a privileged interface. A Wayland compositor is allowed to ignore * any requests. The PlasmaWindowManagement allows to get information about the overall windowing * system. It allows to see which windows are currently available and thus is the base to implement * e.g. a task manager. * * This class provides a convenient wrapper for the org_kde_plasma_window_management interface. * It's main purpose is to create a PlasmaWindowManagementSurface. * * To use this class one needs to interact with the Registry. There are two * possible ways to create the Shell interface: * @code * PlasmaWindowManagement *s = registry->createPlasmaWindowManagement(name, version); * @endcode * * This creates the PlasmaWindowManagement and sets it up directly. As an alternative this * can also be done in a more low level way: * @code * PlasmaWindowManagement *s = new PlasmaWindowManagement; * s->setup(registry->bindPlasmaWindowManagement(name, version)); * @endcode * * The PlasmaWindowManagement can be used as a drop-in replacement for any org_kde_plasma_window_management * pointer as it provides matching cast operators. * * @see Registry * @see PlasmaWindowManagementSurface **/ class KWAYLANDCLIENT_EXPORT PlasmaWindowManagement : public QObject { Q_OBJECT public: explicit PlasmaWindowManagement(QObject *parent = nullptr); virtual ~PlasmaWindowManagement(); /** * @returns @c true if managing a org_kde_plasma_window_management. **/ bool isValid() const; /** * Releases the org_kde_plasma_window_management interface. * After the interface has been released the PlasmaWindowManagement instance is no * longer valid and can be setup with another org_kde_plasma_window_management interface. * * Right before the interface is released the signal interfaceAboutToBeReleased is emitted. * @see interfaceAboutToBeReleased **/ void release(); /** * Destroys the data held by this PlasmaWindowManagement. * 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 org_kde_plasma_window_management interface * once there is a new connection available. * * It is suggested to connect this method to ConnectionThread::connectionDied: * @code * connect(connection, &ConnectionThread::connectionDied, shell, &PlasmaWindowManagement::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(org_kde_plasma_window_management *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(); operator org_kde_plasma_window_management*(); operator org_kde_plasma_window_management*() const; /** * Whether the system is currently showing the desktop. * This means that the system focuses on the desktop and hides other windows. * @see setShowingDesktop * @see showDesktop * @see hideDesktop * @see showingDesktopChanged **/ bool isShowingDesktop() const; /** * Requests to change the showing desktop state to @p show. * @see isShowingDesktop * @see showDesktop * @see hideDesktop **/ void setShowingDesktop(bool show); /** * Same as calling setShowingDesktop with @c true. * @see setShowingDesktop **/ void showDesktop(); /** * Same as calling setShowingDesktop with @c false. * @see setShowingDesktop **/ void hideDesktop(); /** * @returns All windows currently known to the PlasmaWindowManagement * @see windowCreated **/ QList windows() const; /** * @returns The currently active PlasmaWindow, the PlasmaWindow which * returns @c true in @link{PlasmaWindow::isActive} or @c nullptr in case * there is no active window. **/ PlasmaWindow *activeWindow() const; /** * Factory method to create a PlasmaWindowModel. * @returns a new created PlasmaWindowModel **/ PlasmaWindowModel *createWindowModel(); 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 showing desktop state changed. * @see isShowingDesktop **/ void showingDesktopChanged(bool); /** * A new @p window got created. * @see windows **/ void windowCreated(KWayland::Client::PlasmaWindow *window); /** * The active window changed. * @see activeWindow **/ void activeWindowChanged(); /** * The corresponding global for this interface on the Registry got removed. * * This signal gets only emitted if the Compositor got created by * Registry::createPlasmaWindowManagement * * @since 5.5 **/ void removed(); private: class Private; QScopedPointer d; }; /** * @short Wrapper for the org_kde_plasma_window interface. * * A PlasmaWindow gets created by the PlasmaWindowManagement and announced through * the @link{PlasmaWindowManagement::windowCreated} signal. The PlasmaWindow encapsulates * state about a window managed by the Wayland server and allows to request state changes. * * The PlasmaWindow will be automatically deleted when the PlasmaWindow gets unmapped. * * This class is a convenient wrapper for the org_kde_plasma_window interface. * The PlasmaWindow gets created by PlasmaWindowManagement. * * @see PlasmaWindowManager **/ class KWAYLANDCLIENT_EXPORT PlasmaWindow : public QObject { Q_OBJECT public: virtual ~PlasmaWindow(); /** * Releases the org_kde_plasma_window interface. * After the interface has been released the PlasmaWindow instance is no * longer valid and can be setup with another org_kde_plasma_window interface. **/ void release(); /** * Destroys the data held by this PlasmaWindow. * 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 org_kde_plasma_window interface * once there is a new connection available. * * It is suggested to connect this method to ConnectionThread::connectionDied: * @code * connect(connection, &ConnectionThread::connectionDied, source, &PlasmaWindow::destroy); * @endcode * * @see release **/ void destroy(); /** * @returns @c true if managing a org_kde_plasma_window. **/ bool isValid() const; operator org_kde_plasma_window*(); operator org_kde_plasma_window*() const; /** * @returns the window title. * @see titleChanged **/ QString title() const; /** * @returns the application id which should reflect the name of a desktop file. * @see appIdChanged **/ QString appId() const; /** * @returns the id of the virtual desktop this PlasmaWindow is on * @see virtualDesktopChanged **/ quint32 virtualDesktop() const; /** * @returns Whether the window is currently the active Window. * @see activeChanged **/ bool isActive() const; /** * @returns Whether the window is fullscreen * @see fullscreenChanged **/ bool isFullscreen() const; /** * @returns Whether the window is kept above other windows. * @see keepAboveChanged **/ bool isKeepAbove() const; /** * @returns Whether the window is kept below other window * @see keepBelowChanged **/ bool isKeepBelow() const; /** * @returns Whether the window is currently minimized * @see minimizedChanged **/ bool isMinimized() const; /** * @returns Whether the window is maximized. * @see maximizedChanged **/ bool isMaximized() const; /** * @returns Whether the window is shown on all desktops. * @see virtualDesktop * @see onAllDesktopsChanged **/ bool isOnAllDesktops() const; /** * @returns Whether the window is demanding attention. * @see demandsAttentionChanged **/ bool isDemandingAttention() const; /** * @returns Whether the window can be closed. * @see closeableChanged **/ bool isCloseable() const; /** * @returns Whether the window can be maximized. * @see maximizeableChanged **/ bool isMaximizeable() const; /** * @returns Whether the window can be minimized. * @see minimizeableChanged **/ bool isMinimizeable() const; /** * @returns Whether the window can be set to fullscreen. * @see fullscreenableChanged **/ bool isFullscreenable() const; /** * @returns Whether the window should be ignored by a task bar. * @see skipTaskbarChanged **/ bool skipTaskbar() const; /** * @returns The icon of the window. * @see iconChanged **/ QIcon icon() const; /** * @returns Whether the window can be set to the shaded state. * @see isShaded * @see shadeableChanged * @since 5.22 */ bool isShadeable() const; /** * @returns Whether the window is shaded, that is reduced to the window decoration * @see shadedChanged * @since 5.22 */ bool isShaded() const; /** * @returns Whether the window can be moved. * @see movableChanged * @since 5.22 */ bool isMovable() const; /** * @returns Whether the window can be resized. * @see resizableChanged * @since 5.22 */ bool isResizable() const; /** * @returns Whether the virtual desktop can be changed. * @see virtualDesktopChangeableChanged * @since 5.22 */ bool isVirtualDesktopChangeable() const; /** * Requests to activate the window. **/ void requestActivate(); /** * Requests to close the window. **/ void requestClose(); /** * Requests to start an interactive window move operation. * @since 5.22 */ void requestMove(); /** * Requests to start an interactive resize operation. * @since 5.22 */ void requestResize(); /** * Requests to send the window to virtual @p desktop. **/ void requestVirtualDesktop(quint32 desktop); /** * Requests the window at this model row index have its minimized state toggled. */ void requestToggleMinimized(); /** * Requests the window at this model row index have its maximized state toggled. */ void requestToggleMaximized(); /** * Sets the geometry of the taskbar entry for this window * relative to a panel in particular * @since 5.5 */ void setMinimizedGeometry(Surface *panel, const QRect &geom); /** * Remove the task geometry information for a particular panel * @since 5.5 */ void unsetMinimizedGeometry(Surface *panel); /** * Requests the window at this model row index have its shaded state toggled. * @since 5.22 */ void requestToggleShaded(); /** * An internal window identifier. * This is not a global window identifier. * This identifier does not correspond to QWindow::winId in any way. **/ quint32 internalId() const; /** * The parent window of this PlasmaWindow. * * If there is a parent window, this window is a transient window for the * parent window. If this method returns a null PlasmaWindow it means this * window is a top level window and is not a transient window. * * @see parentWindowChanged * @since 5.24 **/ QPointer parentWindow() const; + /** + * @returns The window geometry in absolute coordinates. + * @see geometryChanged + * @since 5.25 + **/ + QRect geometry() const; + Q_SIGNALS: /** * The window title changed. * @see title **/ void titleChanged(); /** * The application id changed. * @see appId **/ void appIdChanged(); /** * The virtual desktop changed. * @see virtualDesktop **/ void virtualDesktopChanged(); /** * The window became active or inactive. * @see isActive **/ void activeChanged(); /** * The fullscreen state changed. * @see isFullscreen **/ void fullscreenChanged(); /** * The keep above state changed. * @see isKeepAbove **/ void keepAboveChanged(); /** * The keep below state changed. * @see isKeepBelow **/ void keepBelowChanged(); /** * The minimized state changed. * @see isMinimized **/ void minimizedChanged(); /** * The maximized state changed. * @see isMaximized **/ void maximizedChanged(); /** * The on all desktops state changed. * @see isOnAllDesktops **/ void onAllDesktopsChanged(); /** * The demands attention state changed. * @see isDemandingAttention **/ void demandsAttentionChanged(); /** * The closeable state changed. * @see isCloseable **/ void closeableChanged(); /** * The minimizeable state changed. * @see isMinimizeable **/ void minimizeableChanged(); /** * The maximizeable state changed. * @see isMaximizeable **/ void maximizeableChanged(); /** * The fullscreenable state changed. * @see isFullscreenable **/ void fullscreenableChanged(); /** * The skip taskbar state changed. * @see skipTaskbar **/ void skipTaskbarChanged(); /** * The window icon changed. * @see icon **/ void iconChanged(); /** * The shadeable state changed. * @see isShadeable * @since 5.22 */ void shadeableChanged(); /** * The shaded state changed. * @see isShaded * @since 5.22 */ void shadedChanged(); /** * The movable state changed. * @see isMovable * @since 5.22 */ void movableChanged(); /** * The resizable state changed. * @see isResizable * @since 5.22 */ void resizableChanged(); /** * The virtual desktop changeable state changed. * @see virtualDesktopChangeable * @since 5.22 */ void virtualDesktopChangeableChanged(); /** * The window got unmapped and is no longer available to the Wayland server. * This instance will be automatically deleted and one should connect to this * signal to perform cleanup. **/ void unmapped(); /** * This signal is emitted whenever the parent window changes. * @see parentWindow * @since 5.24 **/ void parentWindowChanged(); + /** + * This signal is emitted whenever the window geometry changes. + * @see geometry + * @since 5.25 + **/ + void geometryChanged(); private: friend class PlasmaWindowManagement; explicit PlasmaWindow(PlasmaWindowManagement *parent, org_kde_plasma_window *dataOffer, quint32 internalId); class Private; QScopedPointer d; }; } } Q_DECLARE_METATYPE(KWayland::Client::PlasmaWindow*) #endif diff --git a/src/client/protocols/plasma-window-management.xml b/src/client/protocols/plasma-window-management.xml index 8959fb1..8b50c77 100644 --- a/src/client/protocols/plasma-window-management.xml +++ b/src/client/protocols/plasma-window-management.xml @@ -1,233 +1,244 @@ . ]]> - + This interface manages application windows. It provides requests to show and hide the desktop and emits an event every time a window is created so that the client can use it to manage the window. Only one client can bind this interface at a time. Tell the compositor to show/hide the desktop. This event will be sent whenever the show desktop mode changes. E.g. when it is entered or left. On binding the interface the current state is sent. This event will be sent immediately after a window is mapped. - + Manages and control an application window. Only one client can bind this interface at a time. Set window state. Values for state argument are described by org_kde_plasma_window_management.state and can be used together in a bitfield. The flags bitfield describes which flags are supposed to be set, the state bitfield the value for the set flags Maps the window to a different virtual desktop. To show the window on all virtual desktops, call the org_kde_plasma_window.set_state request and specify a on_all_desktops state in the bitfield. Sets the geometry of the taskbar entry for this window. The geometry is relative to a panel in particular. Remove the task geometry information for a particular panel. Close this window. Request an interactive move for this window. Request an interactive resize for this window. Removes the resource bound for this org_kde_plasma_window. This event will be sent as soon as the window title is changed. This event will be sent as soon as the application identifier is changed. This event will be sent as soon as the window state changes. Values for state argument are described by org_kde_plasma_window_management.state. This event will be sent when a window is moved to another virtual desktop. It is not sent if it becomes visible on all virtual desktops though. This event will be sent whenever the themed icon name changes. May be null. This event will be sent immediately after the window is closed and its surface is unmapped. This event will be sent immediately after all initial state been sent to the client. If the Plasma window is already unmapped, the unmapped event will be sent before the initial_state event. This event will be sent whenever the parent window of this org_kde_plasma_window changes. The passed parent is another org_kde_plasma_window and this org_kde_plasma_window is a transient window to the parent window. If the parent argument is null, this org_kde_plasma_window does not have a parent window. + + + + This event will be sent whenever the window geometry of this org_kde_plasma_window changes. + The coordinages are in absolute coordinates of the windowing system. + + + + + + diff --git a/src/client/registry.cpp b/src/client/registry.cpp index ed358fe..01b3d6f 100644 --- a/src/client/registry.cpp +++ b/src/client/registry.cpp @@ -1,680 +1,680 @@ /******************************************************************** 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 "registry.h" #include "compositor.h" #include "connection_thread.h" #include "datadevicemanager.h" #include "dpms.h" #include "event_queue.h" #include "fakeinput.h" #include "fullscreen_shell.h" #include "idle.h" #include "logging_p.h" #include "outputconfiguration.h" #include "outputmanagement.h" #include "outputdevice.h" #include "output.h" #include "plasmashell.h" #include "plasmawindowmanagement.h" #include "seat.h" #include "shadow.h" #include "blur.h" #include "contrast.h" #include "server_decoration.h" #include "slide.h" #include "shell.h" #include "shm_pool.h" #include "subcompositor.h" #include "textinput_p.h" #include "xdgshell.h" #include "xdgshell_p.h" #include "wayland_pointer_p.h" // Qt #include // wayland #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /***** * How to add another interface: * * define a new enum value in Registry::Interface * * define the bind method * * define the create method * * define the Announced signal * * define the Removed signal * * add a block to s_interfaces * * add the BIND macro for the new bind * * add the CREATE macro for the new create * * extend registry unit test to verify that it works ****/ namespace KWayland { namespace Client { namespace { struct SuppertedInterfaceData { quint32 maxVersion; QByteArray name; const wl_interface *interface; void (Registry::*announcedSignal)(quint32, quint32); void (Registry::*removedSignal)(quint32); }; static const QMap s_interfaces = { {Registry::Interface::Compositor, { 3, QByteArrayLiteral("wl_compositor"), &wl_compositor_interface, &Registry::compositorAnnounced, &Registry::compositorRemoved }}, {Registry::Interface::DataDeviceManager, { 2, QByteArrayLiteral("wl_data_device_manager"), &wl_data_device_manager_interface, &Registry::dataDeviceManagerAnnounced, &Registry::dataDeviceManagerRemoved }}, {Registry::Interface::Output, { 2, QByteArrayLiteral("wl_output"), &wl_output_interface, &Registry::outputAnnounced, &Registry::outputRemoved }}, {Registry::Interface::Shm, { 1, QByteArrayLiteral("wl_shm"), &wl_shm_interface, &Registry::shmAnnounced, &Registry::shmRemoved }}, {Registry::Interface::Seat, { 4, QByteArrayLiteral("wl_seat"), &wl_seat_interface, &Registry::seatAnnounced, &Registry::seatRemoved }}, {Registry::Interface::Shell, { 1, QByteArrayLiteral("wl_shell"), &wl_shell_interface, &Registry::shellAnnounced, &Registry::shellRemoved }}, {Registry::Interface::SubCompositor, { 1, QByteArrayLiteral("wl_subcompositor"), &wl_subcompositor_interface, &Registry::subCompositorAnnounced, &Registry::subCompositorRemoved }}, {Registry::Interface::PlasmaShell, { 3, QByteArrayLiteral("org_kde_plasma_shell"), &org_kde_plasma_shell_interface, &Registry::plasmaShellAnnounced, &Registry::plasmaShellRemoved }}, {Registry::Interface::PlasmaWindowManagement, { - 5, + 6, QByteArrayLiteral("org_kde_plasma_window_management"), &org_kde_plasma_window_management_interface, &Registry::plasmaWindowManagementAnnounced, &Registry::plasmaWindowManagementRemoved }}, {Registry::Interface::Idle, { 1, QByteArrayLiteral("org_kde_kwin_idle"), &org_kde_kwin_idle_interface, &Registry::idleAnnounced, &Registry::idleRemoved }}, {Registry::Interface::FakeInput, { 2, QByteArrayLiteral("org_kde_kwin_fake_input"), &org_kde_kwin_fake_input_interface, &Registry::fakeInputAnnounced, &Registry::fakeInputRemoved }}, {Registry::Interface::OutputManagement, { 1, QByteArrayLiteral("org_kde_kwin_outputmanagement"), &org_kde_kwin_outputmanagement_interface, &Registry::outputManagementAnnounced, &Registry::outputManagementRemoved }}, {Registry::Interface::OutputDevice, { 1, QByteArrayLiteral("org_kde_kwin_outputdevice"), &org_kde_kwin_outputdevice_interface, &Registry::outputDeviceAnnounced, &Registry::outputDeviceRemoved }}, {Registry::Interface::Shadow, { 2, QByteArrayLiteral("org_kde_kwin_shadow_manager"), &org_kde_kwin_shadow_manager_interface, &Registry::shadowAnnounced, &Registry::shadowRemoved }}, {Registry::Interface::Blur, { 1, QByteArrayLiteral("org_kde_kwin_blur_manager"), &org_kde_kwin_blur_manager_interface, &Registry::blurAnnounced, &Registry::blurRemoved }}, {Registry::Interface::Contrast, { 1, QByteArrayLiteral("org_kde_kwin_contrast_manager"), &org_kde_kwin_contrast_manager_interface, &Registry::contrastAnnounced, &Registry::contrastRemoved }}, {Registry::Interface::Slide, { 1, QByteArrayLiteral("org_kde_kwin_slide_manager"), &org_kde_kwin_slide_manager_interface, &Registry::slideAnnounced, &Registry::slideRemoved }}, {Registry::Interface::FullscreenShell, { 1, QByteArrayLiteral("_wl_fullscreen_shell"), &_wl_fullscreen_shell_interface, &Registry::fullscreenShellAnnounced, &Registry::fullscreenShellRemoved }}, {Registry::Interface::Dpms, { 1, QByteArrayLiteral("org_kde_kwin_dpms_manager"), &org_kde_kwin_dpms_manager_interface, &Registry::dpmsAnnounced, &Registry::dpmsRemoved }}, {Registry::Interface::ServerSideDecorationManager, { 1, QByteArrayLiteral("org_kde_kwin_server_decoration_manager"), &org_kde_kwin_server_decoration_manager_interface, &Registry::serverSideDecorationManagerAnnounced, &Registry::serverSideDecorationManagerRemoved }}, {Registry::Interface::TextInputManagerUnstableV0, { 1, QByteArrayLiteral("wl_text_input_manager"), &wl_text_input_manager_interface, &Registry::textInputManagerUnstableV0Announced, &Registry::textInputManagerUnstableV0Removed }}, {Registry::Interface::TextInputManagerUnstableV2, { 1, QByteArrayLiteral("zwp_text_input_manager_v2"), &zwp_text_input_manager_v2_interface, &Registry::textInputManagerUnstableV2Announced, &Registry::textInputManagerUnstableV2Removed }}, {Registry::Interface::XdgShellUnstableV5, { 1, QByteArrayLiteral("xdg_shell"), &xdg_shell_interface, &Registry::xdgShellUnstableV5Announced, &Registry::xdgShellUnstableV5Removed }} }; static quint32 maxVersion(const Registry::Interface &interface) { auto it = s_interfaces.find(interface); if (it != s_interfaces.end()) { return it.value().maxVersion; } return 0; } } class Registry::Private { public: Private(Registry *q); void setup(); bool hasInterface(Interface interface) const; AnnouncedInterface interface(Interface interface) const; QVector interfaces(Interface interface) const; Interface interfaceForName(quint32 name) const; template T *bind(Interface interface, uint32_t name, uint32_t version) const; template T *create(quint32 name, quint32 version, QObject *parent, WL *(Registry::*bindMethod)(uint32_t, uint32_t) const); WaylandPointer registry; static const struct wl_callback_listener s_callbackListener; WaylandPointer callback; EventQueue *queue = nullptr; private: void handleAnnounce(uint32_t name, const char *interface, uint32_t version); void handleRemove(uint32_t name); void handleGlobalSync(); static void globalAnnounce(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); static void globalRemove(void *data, struct wl_registry *registry, uint32_t name); static void globalSync(void *data, struct wl_callback *callback, uint32_t serial); Registry *q; struct InterfaceData { Interface interface; uint32_t name; uint32_t version; }; QList m_interfaces; static const struct wl_registry_listener s_registryListener; }; Registry::Private::Private(Registry *q) : q(q) { } void Registry::Private::setup() { wl_registry_add_listener(registry, &s_registryListener, this); wl_callback_add_listener(callback, &s_callbackListener, this); } Registry::Registry(QObject *parent) : QObject(parent) , d(new Private(this)) { } Registry::~Registry() { release(); } void Registry::release() { d->registry.release(); d->callback.release(); } void Registry::destroy() { d->registry.destroy(); d->callback.destroy(); } void Registry::create(wl_display *display) { Q_ASSERT(display); Q_ASSERT(!isValid()); d->registry.setup(wl_display_get_registry(display)); d->callback.setup(wl_display_sync(display)); if (d->queue) { d->queue->addProxy(d->registry); d->queue->addProxy(d->callback); } } void Registry::create(ConnectionThread *connection) { create(connection->display()); } void Registry::setup() { Q_ASSERT(isValid()); d->setup(); } void Registry::setEventQueue(EventQueue *queue) { d->queue = queue; if (!queue) { return; } if (d->registry) { d->queue->addProxy(d->registry); } if (d->callback) { d->queue->addProxy(d->callback); } } EventQueue *Registry::eventQueue() { return d->queue; } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_registry_listener Registry::Private::s_registryListener = { globalAnnounce, globalRemove }; const struct wl_callback_listener Registry::Private::s_callbackListener = { globalSync }; #endif void Registry::Private::globalAnnounce(void *data, wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { auto r = reinterpret_cast(data); Q_ASSERT(registry == r->registry); r->handleAnnounce(name, interface, version); } void Registry::Private::globalRemove(void *data, wl_registry *registry, uint32_t name) { auto r = reinterpret_cast(data); Q_ASSERT(registry == r->registry); r->handleRemove(name); } void Registry::Private::globalSync(void* data, wl_callback* callback, uint32_t serial) { Q_UNUSED(serial) auto r = reinterpret_cast(data); Q_ASSERT(r->callback == callback); r->handleGlobalSync(); r->callback.destroy(); } void Registry::Private::handleGlobalSync() { emit q->interfacesAnnounced(); } namespace { static Registry::Interface nameToInterface(const char *interface) { for (auto it = s_interfaces.begin(); it != s_interfaces.end(); ++it) { if (qstrcmp(interface, it.value().name) == 0) { return it.key(); } } return Registry::Interface::Unknown; } } void Registry::Private::handleAnnounce(uint32_t name, const char *interface, uint32_t version) { Interface i = nameToInterface(interface); emit q->interfaceAnnounced(QByteArray(interface), name, version); if (i == Interface::Unknown) { qCDebug(KWAYLAND_CLIENT) << "Unknown interface announced: " << interface << "/" << name << "/" << version; return; } qCDebug(KWAYLAND_CLIENT) << "Wayland Interface: " << interface << "/" << name << "/" << version; m_interfaces.append({i, name, version}); auto it = s_interfaces.constFind(i); if (it != s_interfaces.end()) { emit (q->*it.value().announcedSignal)(name, version); } } void Registry::Private::handleRemove(uint32_t name) { auto it = std::find_if(m_interfaces.begin(), m_interfaces.end(), [name](const InterfaceData &data) { return data.name == name; } ); if (it != m_interfaces.end()) { InterfaceData data = *(it); m_interfaces.erase(it); auto sit = s_interfaces.find(data.interface); if (sit != s_interfaces.end()) { emit (q->*sit.value().removedSignal)(data.name); } } emit q->interfaceRemoved(name); } bool Registry::Private::hasInterface(Registry::Interface interface) const { auto it = std::find_if(m_interfaces.begin(), m_interfaces.end(), [interface](const InterfaceData &data) { return data.interface == interface; } ); return it != m_interfaces.end(); } QVector Registry::Private::interfaces(Interface interface) const { QVector retVal; for (auto it = m_interfaces.constBegin(); it != m_interfaces.constEnd(); ++it) { const auto &data = *it; if (data.interface == interface) { retVal << AnnouncedInterface{data.name, data.version}; } } return retVal; } Registry::AnnouncedInterface Registry::Private::interface(Interface interface) const { const auto all = interfaces(interface); if (!all.isEmpty()) { return all.last(); } return AnnouncedInterface{0, 0}; } Registry::Interface Registry::Private::interfaceForName(quint32 name) const { auto it = std::find_if(m_interfaces.constBegin(), m_interfaces.constEnd(), [name] (const InterfaceData &data) { return data.name == name; }); if (it == m_interfaces.constEnd()) { return Interface::Unknown; } return (*it).interface; } bool Registry::hasInterface(Registry::Interface interface) const { return d->hasInterface(interface); } QVector Registry::interfaces(Interface interface) const { return d->interfaces(interface); } Registry::AnnouncedInterface Registry::interface(Interface interface) const { return d->interface(interface); } #define BIND2(__NAME__, __INAME__, __WL__) \ __WL__ *Registry::bind##__NAME__(uint32_t name, uint32_t version) const \ { \ return d->bind<__WL__>(Interface::__INAME__, name, qMin(maxVersion(Interface::__INAME__), version)); \ } #define BIND(__NAME__, __WL__) BIND2(__NAME__, __NAME__, __WL__) BIND(Compositor, wl_compositor) BIND(Output, wl_output) BIND(Seat, wl_seat) BIND(Shell, wl_shell) BIND(Shm, wl_shm) BIND(SubCompositor, wl_subcompositor) BIND(FullscreenShell, _wl_fullscreen_shell) BIND(DataDeviceManager, wl_data_device_manager) BIND(PlasmaShell, org_kde_plasma_shell) BIND(PlasmaWindowManagement, org_kde_plasma_window_management) BIND(Idle, org_kde_kwin_idle) BIND(FakeInput, org_kde_kwin_fake_input) BIND(OutputManagement, org_kde_kwin_outputmanagement) BIND(OutputDevice, org_kde_kwin_outputdevice) BIND(ServerSideDecorationManager, org_kde_kwin_server_decoration_manager) BIND(TextInputManagerUnstableV0, wl_text_input_manager) BIND(TextInputManagerUnstableV2, zwp_text_input_manager_v2) BIND(XdgShellUnstableV5, xdg_shell) BIND2(ShadowManager, Shadow, org_kde_kwin_shadow_manager) BIND2(BlurManager, Blur, org_kde_kwin_blur_manager) BIND2(ContrastManager, Contrast, org_kde_kwin_contrast_manager) BIND2(SlideManager, Slide, org_kde_kwin_slide_manager) BIND2(DpmsManager, Dpms, org_kde_kwin_dpms_manager) #undef BIND #undef BIND2 template T *Registry::Private::create(quint32 name, quint32 version, QObject *parent, WL *(Registry::*bindMethod)(uint32_t, uint32_t) const) { T *t = new T(parent); t->setEventQueue(queue); t->setup((q->*bindMethod)(name, version)); QObject::connect(q, &Registry::interfaceRemoved, t, [t, name] (quint32 removed) { if (name == removed) { emit t->removed(); } } ); return t; } #define CREATE2(__NAME__, __BINDNAME__) \ __NAME__ *Registry::create##__NAME__(quint32 name, quint32 version, QObject *parent) \ { \ return d->create<__NAME__>(name, version, parent, &Registry::bind##__BINDNAME__); \ } #define CREATE(__NAME__) CREATE2(__NAME__, __NAME__) CREATE(Compositor) CREATE(Seat) CREATE(Shell) CREATE(SubCompositor) CREATE(FullscreenShell) CREATE(Output) CREATE(DataDeviceManager) CREATE(PlasmaShell) CREATE(PlasmaWindowManagement) CREATE(Idle) CREATE(FakeInput) CREATE(OutputManagement) CREATE(OutputDevice) CREATE(ShadowManager) CREATE(BlurManager) CREATE(ContrastManager) CREATE(SlideManager) CREATE(DpmsManager) CREATE(ServerSideDecorationManager) CREATE2(ShmPool, Shm) #undef CREATE #undef CREATE2 TextInputManager *Registry::createTextInputManager(quint32 name, quint32 version, QObject *parent) { switch (d->interfaceForName(name)) { case Interface::TextInputManagerUnstableV0: return d->create(name, version, parent, &Registry::bindTextInputManagerUnstableV0); case Interface::TextInputManagerUnstableV2: return d->create(name, version, parent, &Registry::bindTextInputManagerUnstableV2); default: return nullptr; } } XdgShell *Registry::createXdgShell(quint32 name, quint32 version, QObject *parent) { switch (d->interfaceForName(name)) { case Interface::XdgShellUnstableV5: return d->create(name, version, parent, &Registry::bindXdgShellUnstableV5); default: return nullptr; } } namespace { static const wl_interface *wlInterface(Registry::Interface interface) { auto it = s_interfaces.find(interface); if (it != s_interfaces.end()) { return it.value().interface; } return nullptr; } } template T *Registry::Private::bind(Registry::Interface interface, uint32_t name, uint32_t version) const { auto it = std::find_if(m_interfaces.begin(), m_interfaces.end(), [=](const InterfaceData &data) { return data.interface == interface && data.name == name && data.version >= version; }); if (it == m_interfaces.end()) { qCDebug(KWAYLAND_CLIENT) << "Don't have interface " << int(interface) << "with name " << name << "and minimum version" << version; return nullptr; } auto t = reinterpret_cast(wl_registry_bind(registry, name, wlInterface(interface), version)); if (queue) { queue->addProxy(t); } return t; } bool Registry::isValid() const { return d->registry.isValid(); } wl_registry *Registry::registry() { return d->registry; } Registry::operator wl_registry*() const { return d->registry; } Registry::operator wl_registry*() { return d->registry; } } } diff --git a/src/server/plasmawindowmanagement_interface.cpp b/src/server/plasmawindowmanagement_interface.cpp index 17084c4..35f961e 100644 --- a/src/server/plasmawindowmanagement_interface.cpp +++ b/src/server/plasmawindowmanagement_interface.cpp @@ -1,714 +1,743 @@ /******************************************************************** Copyright 2015 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "plasmawindowmanagement_interface.h" #include "global_p.h" #include "resource_p.h" #include "display.h" #include "surface_interface.h" #include #include #include #include #include #include namespace KWayland { namespace Server { class PlasmaWindowManagementInterface::Private : public Global::Private { public: Private(PlasmaWindowManagementInterface *q, Display *d); void sendShowingDesktopState(); ShowingDesktopState state = ShowingDesktopState::Disabled; QVector resources; QList windows; quint32 windowIdCounter = 0; private: static void unbind(wl_resource *resource); static void showDesktopCallback(wl_client *client, wl_resource *resource, uint32_t state); static void getWindowCallback(wl_client *client, wl_resource *resource, uint32_t id, uint32_t internalWindowId); void bind(wl_client *client, uint32_t version, uint32_t id) override; void sendShowingDesktopState(wl_resource *r); PlasmaWindowManagementInterface *q; static const struct org_kde_plasma_window_management_interface s_interface; static const quint32 s_version; }; class PlasmaWindowInterface::Private { public: Private(PlasmaWindowManagementInterface *wm, PlasmaWindowInterface *q); ~Private(); void createResource(wl_resource *parent, uint32_t id); void setTitle(const QString &title); void setAppId(const QString &appId); void setThemedIconName(const QString &iconName); void setVirtualDesktop(quint32 desktop); void unmap(); void setState(org_kde_plasma_window_management_state flag, bool set); void setParentWindow(PlasmaWindowInterface *parent); + void setGeometry(const QRect &geometry); wl_resource *resourceForParent(PlasmaWindowInterface *parent, wl_resource *child) const; QVector resources; quint32 windowId = 0; QHash minimizedGeometries; PlasmaWindowManagementInterface *wm; bool unmapped = false; PlasmaWindowInterface *parentWindow = nullptr; QMetaObject::Connection parentWindowDestroyConnection; + QRect geometry; private: static void unbind(wl_resource *resource); static void setStateCallback(wl_client *client, wl_resource *resource, uint32_t flags, uint32_t state); static void setVirtualDesktopCallback(wl_client *client, wl_resource *resource, uint32_t number); static void closeCallback(wl_client *client, wl_resource *resource); static void requestMoveCallback(wl_client *client, wl_resource *resource); static void requestResizeCallback(wl_client *client, wl_resource *resource); static void setMinimizedGeometryCallback(wl_client *client, wl_resource *resource, wl_resource *panel, uint32_t x, uint32_t y, uint32_t width, uint32_t height); static void unsetMinimizedGeometryCallback(wl_client *client, wl_resource *resource, wl_resource *panel); static void destroyCallback(wl_client *client, wl_resource *resource); static Private *cast(wl_resource *resource) { return reinterpret_cast(wl_resource_get_user_data(resource)); } PlasmaWindowInterface *q; QString m_title; QString m_appId; QString m_themedIconName; quint32 m_virtualDesktop = 0; quint32 m_state = 0; wl_listener listener; static const struct org_kde_plasma_window_interface s_interface; }; -const quint32 PlasmaWindowManagementInterface::Private::s_version = 5; +const quint32 PlasmaWindowManagementInterface::Private::s_version = 6; PlasmaWindowManagementInterface::Private::Private(PlasmaWindowManagementInterface *q, Display *d) : Global::Private(d, &org_kde_plasma_window_management_interface, s_version) , q(q) { } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct org_kde_plasma_window_management_interface PlasmaWindowManagementInterface::Private::s_interface = { showDesktopCallback, getWindowCallback }; #endif void PlasmaWindowManagementInterface::Private::sendShowingDesktopState() { for (wl_resource *r : resources) { sendShowingDesktopState(r); } } void PlasmaWindowManagementInterface::Private::sendShowingDesktopState(wl_resource *r) { uint32_t s = 0; switch (state) { case ShowingDesktopState::Enabled: s = ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_ENABLED; break; case ShowingDesktopState::Disabled: s = ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_DISABLED; break; default: Q_UNREACHABLE(); break; } org_kde_plasma_window_management_send_show_desktop_changed(r, s); } void PlasmaWindowManagementInterface::Private::showDesktopCallback(wl_client *client, wl_resource *resource, uint32_t state) { Q_UNUSED(client) ShowingDesktopState s = ShowingDesktopState::Disabled; switch (state) { case ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_ENABLED: s = ShowingDesktopState::Enabled; break; case ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_DISABLED: default: s = ShowingDesktopState::Disabled; break; } emit reinterpret_cast(wl_resource_get_user_data(resource))->q->requestChangeShowingDesktop(s); } void PlasmaWindowManagementInterface::Private::getWindowCallback(wl_client *client, wl_resource *resource, uint32_t id, uint32_t internalWindowId) { Q_UNUSED(client) auto p = reinterpret_cast(wl_resource_get_user_data(resource)); auto it = std::find_if(p->windows.constBegin(), p->windows.constEnd(), [internalWindowId] (PlasmaWindowInterface *window) { return window->d->windowId == internalWindowId; } ); if (it == p->windows.constEnd()) { // create a temp window just for the resource and directly send an unmapped PlasmaWindowInterface *window = new PlasmaWindowInterface(p->q, p->q); window->d->unmapped = true; window->d->createResource(resource, id); return; } (*it)->d->createResource(resource, id); } PlasmaWindowManagementInterface::PlasmaWindowManagementInterface(Display *display, QObject *parent) : Global(new Private(this, display), parent) { } PlasmaWindowManagementInterface::~PlasmaWindowManagementInterface() = default; void PlasmaWindowManagementInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { auto c = display->getConnection(client); wl_resource *shell = c->createResource(&org_kde_plasma_window_management_interface, qMin(version, s_version), id); if (!shell) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(shell, &s_interface, this, unbind); resources << shell; for (auto it = windows.constBegin(); it != windows.constEnd(); ++it) { org_kde_plasma_window_management_send_window(shell, (*it)->d->windowId); } } void PlasmaWindowManagementInterface::Private::unbind(wl_resource *resource) { auto wm = reinterpret_cast(wl_resource_get_user_data(resource)); wm->resources.removeAll(resource); } void PlasmaWindowManagementInterface::setShowingDesktopState(PlasmaWindowManagementInterface::ShowingDesktopState state) { Q_D(); if (d->state == state) { return; } d->state = state; d->sendShowingDesktopState(); } PlasmaWindowManagementInterface::Private *PlasmaWindowManagementInterface::d_func() const { return reinterpret_cast(d.data()); } PlasmaWindowInterface *PlasmaWindowManagementInterface::createWindow(QObject *parent) { Q_D(); PlasmaWindowInterface *window = new PlasmaWindowInterface(this, parent); // TODO: improve window ids so that it cannot wrap around window->d->windowId = ++d->windowIdCounter; for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) { org_kde_plasma_window_management_send_window(*it, window->d->windowId); } d->windows << window; connect(window, &QObject::destroyed, this, [this, window] { Q_D(); d->windows.removeAll(window); } ); return window; } void PlasmaWindowManagementInterface::unmapWindow(PlasmaWindowInterface *window) { if (!window) { return; } Q_D(); d->windows.removeOne(window); Q_ASSERT(!d->windows.contains(window)); window->d->unmap(); } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct org_kde_plasma_window_interface PlasmaWindowInterface::Private::s_interface = { setStateCallback, setVirtualDesktopCallback, setMinimizedGeometryCallback, unsetMinimizedGeometryCallback, closeCallback, requestMoveCallback, requestResizeCallback, destroyCallback }; #endif PlasmaWindowInterface::Private::Private(PlasmaWindowManagementInterface *wm, PlasmaWindowInterface *q) : wm(wm) , q(q) { } PlasmaWindowInterface::Private::~Private() { // need to copy, as destroy goes through the destroy listener and modifies the list as we iterate const auto c = resources; for (const auto &r : c) { auto client = wl_resource_get_client(r); org_kde_plasma_window_send_unmapped(r); wl_resource_destroy(r); wl_client_flush(client); } } void PlasmaWindowInterface::Private::destroyCallback(wl_client *, wl_resource *r) { Private *p = cast(r); p->resources.removeAll(r); wl_resource_destroy(r); if (p->unmapped && p->resources.isEmpty()) { p->q->deleteLater(); } } void PlasmaWindowInterface::Private::unbind(wl_resource *resource) { Private *p = reinterpret_cast(wl_resource_get_user_data(resource)); p->resources.removeAll(resource); if (p->unmapped && p->resources.isEmpty()) { p->q->deleteLater(); } } void PlasmaWindowInterface::Private::createResource(wl_resource *parent, uint32_t id) { ClientConnection *c = wm->display()->getConnection(wl_resource_get_client(parent)); wl_resource *resource = c->createResource(&org_kde_plasma_window_interface, wl_resource_get_version(parent), id); if (!resource) { return; } wl_resource_set_implementation(resource, &s_interface, this, unbind); resources << resource; org_kde_plasma_window_send_virtual_desktop_changed(resource, m_virtualDesktop); if (!m_appId.isEmpty()) { org_kde_plasma_window_send_app_id_changed(resource, m_appId.toUtf8().constData()); } if (!m_title.isEmpty()) { org_kde_plasma_window_send_title_changed(resource, m_title.toUtf8().constData()); } org_kde_plasma_window_send_state_changed(resource, m_state); org_kde_plasma_window_send_themed_icon_name_changed(resource, m_themedIconName.toUtf8().constData()); org_kde_plasma_window_send_parent_window(resource, resourceForParent(parentWindow, resource)); if (unmapped) { org_kde_plasma_window_send_unmapped(resource); } + if (geometry.isValid() && wl_resource_get_version(resource) >= ORG_KDE_PLASMA_WINDOW_GEOMETRY_SINCE_VERSION) { + org_kde_plasma_window_send_geometry(resource, geometry.x(), geometry.y(), geometry.width(), geometry.height()); + } + if (wl_resource_get_version(resource) >= ORG_KDE_PLASMA_WINDOW_INITIAL_STATE_SINCE_VERSION) { org_kde_plasma_window_send_initial_state(resource); } c->flush(); } void PlasmaWindowInterface::Private::setAppId(const QString &appId) { if (m_appId == appId) { return; } m_appId = appId; const QByteArray utf8 = m_appId.toUtf8(); for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { org_kde_plasma_window_send_app_id_changed(*it, utf8.constData()); } } void PlasmaWindowInterface::Private::setThemedIconName(const QString &iconName) { if (m_themedIconName == iconName) { return; } m_themedIconName = iconName; const QByteArray utf8 = m_themedIconName.toUtf8(); for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { org_kde_plasma_window_send_themed_icon_name_changed(*it, utf8.constData()); } } void PlasmaWindowInterface::Private::setTitle(const QString &title) { if (m_title == title) { return; } m_title = title; const QByteArray utf8 = m_title.toUtf8(); for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { org_kde_plasma_window_send_title_changed(*it, utf8.constData()); } } void PlasmaWindowInterface::Private::setVirtualDesktop(quint32 desktop) { if (m_virtualDesktop == desktop) { return; } m_virtualDesktop = desktop; for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { org_kde_plasma_window_send_virtual_desktop_changed(*it, m_virtualDesktop); } } void PlasmaWindowInterface::Private::unmap() { unmapped = true; for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { org_kde_plasma_window_send_unmapped(*it); } if (resources.isEmpty()) { q->deleteLater(); } } void PlasmaWindowInterface::Private::setState(org_kde_plasma_window_management_state flag, bool set) { quint32 newState = m_state; if (set) { newState |= flag; } else { newState &= ~flag; } if (newState == m_state) { return; } m_state = newState; for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { org_kde_plasma_window_send_state_changed(*it, m_state); } } wl_resource *PlasmaWindowInterface::Private::resourceForParent(PlasmaWindowInterface *parent, wl_resource *child) const { if (!parent) { return nullptr; } auto it = std::find_if(parent->d->resources.begin(), parent->d->resources.end(), [child] (wl_resource *parentResource) { return wl_resource_get_client(child) == wl_resource_get_client(parentResource); } ); if (it != parent->d->resources.end()) { return *it; } return nullptr; } void PlasmaWindowInterface::Private::setParentWindow(PlasmaWindowInterface *window) { if (parentWindow == window) { return; } QObject::disconnect(parentWindowDestroyConnection); parentWindowDestroyConnection = QMetaObject::Connection(); parentWindow = window; if (parentWindow) { parentWindowDestroyConnection = QObject::connect(window, &QObject::destroyed, q, [this] { parentWindow = nullptr; parentWindowDestroyConnection = QMetaObject::Connection(); for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { org_kde_plasma_window_send_parent_window(*it, nullptr); } } ); } for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { org_kde_plasma_window_send_parent_window(*it, resourceForParent(window, *it)); } } +void PlasmaWindowInterface::Private::setGeometry(const QRect &geo) +{ + if (geometry == geo) { + return; + } + geometry = geo; + if (!geometry.isValid()) { + return; + } + for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { + auto resource = *it; + if (wl_resource_get_version(resource) < ORG_KDE_PLASMA_WINDOW_GEOMETRY_SINCE_VERSION) { + continue; + } + org_kde_plasma_window_send_geometry(resource, geometry.x(), geometry.y(), geometry.width(), geometry.height()); + } +} + void PlasmaWindowInterface::Private::closeCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) Private *p = cast(resource); emit p->q->closeRequested(); } void PlasmaWindowInterface::Private::requestMoveCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) Private *p = cast(resource); emit p->q->moveRequested(); } void PlasmaWindowInterface::Private::requestResizeCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) Private *p = cast(resource); emit p->q->resizeRequested(); } void PlasmaWindowInterface::Private::setVirtualDesktopCallback(wl_client *client, wl_resource *resource, uint32_t number) { Q_UNUSED(client) Private *p = cast(resource); emit p->q->virtualDesktopRequested(number); } void PlasmaWindowInterface::Private::setStateCallback(wl_client *client, wl_resource *resource, uint32_t flags, uint32_t state) { Q_UNUSED(client) Private *p = cast(resource); if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ACTIVE) { emit p->q->activeRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ACTIVE); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZED) { emit p->q->minimizedRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZED); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZED) { emit p->q->maximizedRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZED); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREEN) { emit p->q->fullscreenRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREEN); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_ABOVE) { emit p->q->keepAboveRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_ABOVE); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_BELOW) { emit p->q->keepBelowRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_BELOW); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_DEMANDS_ATTENTION) { emit p->q->demandsAttentionRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_DEMANDS_ATTENTION); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_CLOSEABLE) { emit p->q->closeableRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_CLOSEABLE); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZABLE) { emit p->q->minimizeableRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZABLE); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZABLE) { emit p->q->maximizeableRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZABLE); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREENABLE) { emit p->q->fullscreenableRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREENABLE); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPTASKBAR) { emit p->q->skipTaskbarRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPTASKBAR); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADEABLE) { emit p->q->shadeableRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADEABLE); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADED) { emit p->q->shadedRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADED); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MOVABLE) { emit p->q->movableRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MOVABLE); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_RESIZABLE) { emit p->q->resizableRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_RESIZABLE); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_VIRTUAL_DESKTOP_CHANGEABLE) { emit p->q->virtualDesktopChangeableRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_VIRTUAL_DESKTOP_CHANGEABLE); } } void PlasmaWindowInterface::Private::setMinimizedGeometryCallback(wl_client *client, wl_resource *resource, wl_resource *panel, uint32_t x, uint32_t y, uint32_t width, uint32_t height) { Q_UNUSED(client) Private *p = cast(resource); SurfaceInterface *panelSurface = SurfaceInterface::get(panel); if (!panelSurface) { return; } if (p->minimizedGeometries.value(panelSurface) == QRect(x, y, width, height)) { return; } p->minimizedGeometries[panelSurface] = QRect(x, y, width, height); emit p->q->minimizedGeometriesChanged(); connect(panelSurface, &QObject::destroyed, p->q, [p, panelSurface] () { if (p->minimizedGeometries.remove(panelSurface)) { emit p->q->minimizedGeometriesChanged(); } }); } void PlasmaWindowInterface::Private::unsetMinimizedGeometryCallback(wl_client *client, wl_resource *resource, wl_resource *panel) { Q_UNUSED(client) Private *p = cast(resource); SurfaceInterface *panelSurface = SurfaceInterface::get(panel); if (!panelSurface) { return; } if (!p->minimizedGeometries.contains(panelSurface)) { return; } p->minimizedGeometries.remove(panelSurface); emit p->q->minimizedGeometriesChanged(); } PlasmaWindowInterface::PlasmaWindowInterface(PlasmaWindowManagementInterface *wm, QObject *parent) : QObject(parent) , d(new Private(wm, this)) { } PlasmaWindowInterface::~PlasmaWindowInterface() = default; void PlasmaWindowInterface::setAppId(const QString &appId) { d->setAppId(appId); } void PlasmaWindowInterface::setTitle(const QString &title) { d->setTitle(title); } void PlasmaWindowInterface::setVirtualDesktop(quint32 desktop) { d->setVirtualDesktop(desktop); } void PlasmaWindowInterface::unmap() { d->wm->unmapWindow(this); } QHash PlasmaWindowInterface::minimizedGeometries() const { return d->minimizedGeometries; } void PlasmaWindowInterface::setActive(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ACTIVE, set); } void PlasmaWindowInterface::setFullscreen(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREEN, set); } void PlasmaWindowInterface::setKeepAbove(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_ABOVE, set); } void PlasmaWindowInterface::setKeepBelow(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_BELOW, set); } void PlasmaWindowInterface::setMaximized(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZED, set); } void PlasmaWindowInterface::setMinimized(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZED, set); } void PlasmaWindowInterface::setOnAllDesktops(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ON_ALL_DESKTOPS, set); } void PlasmaWindowInterface::setDemandsAttention(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_DEMANDS_ATTENTION, set); } void PlasmaWindowInterface::setCloseable(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_CLOSEABLE, set); } void PlasmaWindowInterface::setFullscreenable(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_FULLSCREENABLE, set); } void PlasmaWindowInterface::setMaximizeable(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MAXIMIZABLE, set); } void PlasmaWindowInterface::setMinimizeable(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MINIMIZABLE, set); } void PlasmaWindowInterface::setSkipTaskbar(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPTASKBAR, set); } void PlasmaWindowInterface::setThemedIconName(const QString &iconName) { d->setThemedIconName(iconName); } void PlasmaWindowInterface::setShadeable(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADEABLE, set); } void PlasmaWindowInterface::setShaded(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADED, set); } void PlasmaWindowInterface::setMovable(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_MOVABLE, set); } void PlasmaWindowInterface::setResizable(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_RESIZABLE, set); } void PlasmaWindowInterface::setVirtualDesktopChangeable(bool set) { d->setState(ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_VIRTUAL_DESKTOP_CHANGEABLE, set); } void PlasmaWindowInterface::setParentWindow(PlasmaWindowInterface *parentWindow) { d->setParentWindow(parentWindow); } +void PlasmaWindowInterface::setGeometry(const QRect &geometry) +{ + d->setGeometry(geometry); +} + } } diff --git a/src/server/plasmawindowmanagement_interface.h b/src/server/plasmawindowmanagement_interface.h index 76f9950..6b12bb3 100644 --- a/src/server/plasmawindowmanagement_interface.h +++ b/src/server/plasmawindowmanagement_interface.h @@ -1,208 +1,216 @@ /******************************************************************** Copyright 2015 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #ifndef WAYLAND_SERVER_PLASMA_WINDOW_MANAGEMENT_INTERFACE_H #define WAYLAND_SERVER_PLASMA_WINDOW_MANAGEMENT_INTERFACE_H #include #include #include "global.h" #include "resource.h" class QSize; namespace KWayland { namespace Server { class Display; class PlasmaWindowInterface; class SurfaceInterface; class KWAYLANDSERVER_EXPORT PlasmaWindowManagementInterface : public Global { Q_OBJECT public: virtual ~PlasmaWindowManagementInterface(); enum class ShowingDesktopState { Disabled, Enabled }; void setShowingDesktopState(ShowingDesktopState state); PlasmaWindowInterface *createWindow(QObject *parent); QList windows() const; /** * Unmaps the @p window previously created with @link{createWindow}. * The window will be unmapped and removed from the list of @link{windows}. * * Unmapping a @p window indicates to the client that it should destroy the * resource created for the window. Once all resources for the @p window are * destroyed, the @p window will get deleted automatically. There is no need * to manually delete the @p window. A manual delete will trigger the unmap * and resource destroy at the same time and can result in protocol errors on * client side if it still accesses the resource before receiving the unmap event. * * @see createWindow * @see windows * @since 5.23 **/ void unmapWindow(PlasmaWindowInterface *window); Q_SIGNALS: void requestChangeShowingDesktop(ShowingDesktopState requestedState); private: friend class Display; explicit PlasmaWindowManagementInterface(Display *display, QObject *parent); class Private; Private *d_func() const; }; class KWAYLANDSERVER_EXPORT PlasmaWindowInterface : public QObject { Q_OBJECT public: virtual ~PlasmaWindowInterface(); void setTitle(const QString &title); void setAppId(const QString &appId); void setVirtualDesktop(quint32 desktop); void setActive(bool set); void setMinimized(bool set); void setMaximized(bool set); void setFullscreen(bool set); void setKeepAbove(bool set); void setKeepBelow(bool set); void setOnAllDesktops(bool set); void setDemandsAttention(bool set); void setCloseable(bool set); void setMinimizeable(bool set); void setMaximizeable(bool set); void setFullscreenable(bool set); void setSkipTaskbar(bool skip); void setThemedIconName(const QString &iconName); /** * @since 5.22 */ void setShadeable(bool set); /** * @since 5.22 */ void setShaded(bool set); /** * @since 5.22 */ void setMovable(bool set); /** * @since 5.22 */ void setResizable(bool set); /** * @since 5.22 */ void setVirtualDesktopChangeable(bool set); /** * This method removes the Window and the Client is supposed to release the resource * bound for this Window. Once all resources are released the Window gets deleted. * * Prefer using @link{PlasmaWindowManagementInterface::unmapWindow}. * @see PlasmaWindowManagementInterface::unmapWindow **/ void unmap(); /** * @returns Geometries of the taskbar entries, indicized by the * surface of the panels * @since 5.5 */ QHash minimizedGeometries() const; /** * Sets this PlasmaWindowInterface as a transient window to @p parentWindow. * If @p parentWindow is @c nullptr, the PlasmaWindowInterface is a toplevel * window and does not have a parent window. * @since 5.24 **/ void setParentWindow(PlasmaWindowInterface *parentWindow); + /** + * Sets the window @p geometry of this PlasmaWindow. + * + * @param geometry The geometry in absolute coordinates + * @since 5.25 + **/ + void setGeometry(const QRect &geometry); + Q_SIGNALS: void closeRequested(); /** * @since 5.22 */ void moveRequested(); /** * @since 5.22 */ void resizeRequested(); void virtualDesktopRequested(quint32 desktop); void activeRequested(bool set); void minimizedRequested(bool set); void maximizedRequested(bool set); void fullscreenRequested(bool set); void keepAboveRequested(bool set); void keepBelowRequested(bool set); void demandsAttentionRequested(bool set); void closeableRequested(bool set); void minimizeableRequested(bool set); void maximizeableRequested(bool set); void fullscreenableRequested(bool set); void skipTaskbarRequested(bool set); QRect minimizedGeometriesChanged(); /** * @since 5.22 */ void shadeableRequested(bool set); /** * @since 5.22 */ void shadedRequested(bool set); /** * @since 5.22 */ void movableRequested(bool set); /** * @since 5.22 */ void resizableRequested(bool set); /** * @since 5.22 */ void virtualDesktopChangeableRequested(bool set); private: friend class PlasmaWindowManagementInterface; explicit PlasmaWindowInterface(PlasmaWindowManagementInterface *wm, QObject *parent); class Private; const QScopedPointer d; }; } } Q_DECLARE_METATYPE(KWayland::Server::PlasmaWindowManagementInterface::ShowingDesktopState) #endif