diff --git a/src/wayland/CMakeLists.txt b/src/wayland/CMakeLists.txt index 170f000bbc..159b6a594f 100644 --- a/src/wayland/CMakeLists.txt +++ b/src/wayland/CMakeLists.txt @@ -102,7 +102,7 @@ ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS BASENAME org-kde-plasma-virtual-desktop ) -ecm_add_wayland_server_protocol(SERVER_LIB_SRCS +ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/plasma-window-management.xml BASENAME plasma-window-management ) diff --git a/src/wayland/autotests/client/test_plasma_virtual_desktop.cpp b/src/wayland/autotests/client/test_plasma_virtual_desktop.cpp index 125a2046d0..5f583b3112 100644 --- a/src/wayland/autotests/client/test_plasma_virtual_desktop.cpp +++ b/src/wayland/autotests/client/test_plasma_virtual_desktop.cpp @@ -126,8 +126,6 @@ void TestVirtualDesktop::init() m_plasmaVirtualDesktopManagement = registry.createPlasmaVirtualDesktopManagement(plasmaVirtualDesktopManagementSpy.first().first().value(), plasmaVirtualDesktopManagementSpy.first().last().value(), this); m_windowManagementInterface = m_display->createPlasmaWindowManagement(m_display); - m_windowManagementInterface->create(); - QVERIFY(m_windowManagementInterface->isValid()); m_windowManagementInterface->setPlasmaVirtualDesktopManagementInterface(m_plasmaVirtualDesktopManagementInterface); QVERIFY(windowManagementSpy.wait()); diff --git a/src/wayland/autotests/client/test_plasma_window_model.cpp b/src/wayland/autotests/client/test_plasma_window_model.cpp index f61c778f6d..22df12bb55 100644 --- a/src/wayland/autotests/client/test_plasma_window_model.cpp +++ b/src/wayland/autotests/client/test_plasma_window_model.cpp @@ -101,7 +101,6 @@ void PlasmaWindowModelTest::init() QVERIFY(m_display->isRunning()); m_display->createShm(); m_pwInterface = m_display->createPlasmaWindowManagement(); - m_pwInterface->create(); m_plasmaVirtualDesktopManagementInterface = m_display->createPlasmaVirtualDesktopManagement(m_display); m_plasmaVirtualDesktopManagementInterface->createDesktop("desktop1"); m_plasmaVirtualDesktopManagementInterface->createDesktop("desktop2"); @@ -870,7 +869,7 @@ void PlasmaWindowModelTest::testChangeWindowAfterModelDestroy_data() #if KWAYLANDSERVER_ENABLE_DEPRECATED_SINCE(5, 28) QTest::newRow("iconname" ) << &PlasmaWindow::iconChanged << QVariant::fromValue(&PlasmaWindowInterface::setThemedIconName) << QVariant(QStringLiteral("foo")); #endif - QTest::newRow("icon" ) << &PlasmaWindow::iconChanged << QVariant::fromValue(&PlasmaWindowInterface::setIcon) << QVariant::fromValue(QIcon::fromTheme(QStringLiteral("foo"))); + QTest::newRow("icon" ) << &PlasmaWindow::iconChanged << QVariant::fromValue(&PlasmaWindowInterface::setIcon) << QVariant(QIcon::fromTheme(QStringLiteral("foo"))); QTest::newRow("vd") << &PlasmaWindow::virtualDesktopChanged << QVariant::fromValue(&PlasmaWindowInterface::setVirtualDesktop) << QVariant(2u); QTest::newRow("unmapped") << &PlasmaWindow::unmapped << QVariant::fromValue(&PlasmaWindowInterface::unmap) << QVariant(); } @@ -901,6 +900,8 @@ void PlasmaWindowModelTest::testChangeWindowAfterModelDestroy() (w->*(setter.value()))(value.toString()); } else if (QMetaType::Type(value.type()) == QMetaType::UInt) { (w->*(setter.value()))(value.toUInt()); + } else if (QMetaType::Type(value.type()) == QMetaType::QIcon) { + (w->*(setter.value()))(value.value()); } else if (!value.isValid()) { (w->*(setter.value()))(); } diff --git a/src/wayland/autotests/client/test_wayland_windowmanagement.cpp b/src/wayland/autotests/client/test_wayland_windowmanagement.cpp index 1d9075b457..0bdc8d7576 100644 --- a/src/wayland/autotests/client/test_wayland_windowmanagement.cpp +++ b/src/wayland/autotests/client/test_wayland_windowmanagement.cpp @@ -137,8 +137,6 @@ void TestWindowManagement::init() 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); diff --git a/src/wayland/plasmawindowmanagement_interface.cpp b/src/wayland/plasmawindowmanagement_interface.cpp index 001c0c7892..5b2123a8d4 100644 --- a/src/wayland/plasmawindowmanagement_interface.cpp +++ b/src/wayland/plasmawindowmanagement_interface.cpp @@ -4,8 +4,6 @@ SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "plasmawindowmanagement_interface.h" -#include "global_p.h" -#include "resource_p.h" #include "display.h" #include "surface_interface.h" #include "plasmavirtualdesktop_interface.h" @@ -19,49 +17,42 @@ #include #include -#include -#include +#include namespace KWaylandServer { -class PlasmaWindowManagementInterface::Private : public Global::Private +class PlasmaWindowManagementInterfacePrivate : public QtWaylandServer::org_kde_plasma_window_management { public: - Private(PlasmaWindowManagementInterface *q, Display *d); + PlasmaWindowManagementInterfacePrivate(PlasmaWindowManagementInterface *_q, Display *display); void sendShowingDesktopState(); void sendStackingOrderChanged(); + void sendShowingDesktopState(wl_resource *resource); + void sendStackingOrderChanged(wl_resource *resource); - ShowingDesktopState state = ShowingDesktopState::Disabled; - QVector resources; + PlasmaWindowManagementInterface::ShowingDesktopState state = PlasmaWindowManagementInterface::ShowingDesktopState::Disabled; QList windows; QPointer plasmaVirtualDesktopManagementInterface = nullptr; quint32 windowIdCounter = 0; QVector stackingOrder; - QVector stackingOrderUuids; - -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); - static void getWindowByUuidCallback(wl_client *client, wl_resource *resource, uint32_t id, const char* uuid); - - void bind(wl_client *client, uint32_t version, uint32_t id) override; - void sendShowingDesktopState(wl_resource *r); - void sendStackingOrderChanged(wl_resource *r); - + QVector stackingOrderUuids; PlasmaWindowManagementInterface *q; - static const struct org_kde_plasma_window_management_interface s_interface; static const quint32 s_version; + +protected: + void org_kde_plasma_window_management_bind_resource(Resource *resource) override; + void org_kde_plasma_window_management_show_desktop(Resource *resource, uint32_t state) override; + void org_kde_plasma_window_management_get_window(Resource *resource, uint32_t id, uint32_t internal_window_id) override; + void org_kde_plasma_window_management_get_window_by_uuid(Resource *resource, uint32_t id, const QString &internal_window_uuid) override; }; -class PlasmaWindowInterface::Private +class PlasmaWindowInterfacePrivate : public QtWaylandServer::org_kde_plasma_window { public: - Private(PlasmaWindowManagementInterface *wm, PlasmaWindowInterface *q); - ~Private(); + PlasmaWindowInterfacePrivate(PlasmaWindowManagementInterface *wm, PlasmaWindowInterface *q); + ~PlasmaWindowInterfacePrivate(); - void createResource(wl_resource *parent, uint32_t id); void setTitle(const QString &title); void setAppId(const QString &appId); void setPid(quint32 pid); @@ -73,38 +64,18 @@ public: void setParentWindow(PlasmaWindowInterface *parent); void setGeometry(const QRect &geometry); void setApplicationMenuPaths(const QString &service, const QString &object); - wl_resource *resourceForParent(PlasmaWindowInterface *parent, wl_resource *child) const; + wl_resource *resourceForParent(PlasmaWindowInterface *parent, Resource *child) const; - QVector resources; quint32 windowId = 0; QHash minimizedGeometries; PlasmaWindowManagementInterface *wm; bool unmapped = false; + bool destroyed = false; PlasmaWindowInterface *parentWindow = nullptr; QMetaObject::Connection parentWindowDestroyConnection; QStringList plasmaVirtualDesktops; QRect geometry; - QByteArray uuid; - -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 void getIconCallback(wl_client *client, wl_resource *resource, int32_t fd); - static void requestEnterVirtualDesktopCallback(wl_client *client, wl_resource *resource, const char *id); - static void requestEnterNewVirtualDesktopCallback(wl_client *client, wl_resource *resource); - static void requestLeaveVirtualDesktopCallback(wl_client *client, wl_resource *resource, const char *id); - static Private *cast(wl_resource *resource) { - return reinterpret_cast(wl_resource_get_user_data(resource)); - } - PlasmaWindowInterface *q; QString m_title; QString m_appId; @@ -115,172 +86,153 @@ private: QIcon m_icon; quint32 m_virtualDesktop = 0; quint32 m_state = 0; - static const struct org_kde_plasma_window_interface s_interface; + QString uuid; + +protected: + void org_kde_plasma_window_bind_resource(Resource *resource) override; + void org_kde_plasma_window_destroy_resource(Resource *resource) override; + void org_kde_plasma_window_set_state(Resource *resource, uint32_t flags, uint32_t state) override; + void org_kde_plasma_window_set_virtual_desktop(Resource *resource, uint32_t number) override; + void org_kde_plasma_window_set_minimized_geometry(Resource *resource, wl_resource *panel, uint32_t x, uint32_t y, uint32_t width, uint32_t height) override; + void org_kde_plasma_window_unset_minimized_geometry(Resource *resource, wl_resource *panel) override; + void org_kde_plasma_window_close(Resource *resource) override; + void org_kde_plasma_window_request_move(Resource *resource) override; + void org_kde_plasma_window_request_resize(Resource *resource) override; + void org_kde_plasma_window_destroy(Resource *resource) override; + void org_kde_plasma_window_get_icon(Resource *resource, int32_t fd) override; + void org_kde_plasma_window_request_enter_virtual_desktop(Resource *resource, const QString &id) override; + void org_kde_plasma_window_request_enter_new_virtual_desktop(Resource *resource) override; + void org_kde_plasma_window_request_leave_virtual_desktop(Resource *resource, const QString &id) override; }; -const quint32 PlasmaWindowManagementInterface::Private::s_version = 13; +const quint32 PlasmaWindowManagementInterfacePrivate::s_version = 13; -PlasmaWindowManagementInterface::Private::Private(PlasmaWindowManagementInterface *q, Display *d) - : Global::Private(d, &org_kde_plasma_window_management_interface, s_version) - , q(q) +PlasmaWindowManagementInterfacePrivate::PlasmaWindowManagementInterfacePrivate(PlasmaWindowManagementInterface *_q, Display *display) + : QtWaylandServer::org_kde_plasma_window_management(*display, s_version) + , q(_q) { } -#ifndef K_DOXYGEN -const struct org_kde_plasma_window_management_interface PlasmaWindowManagementInterface::Private::s_interface = { - showDesktopCallback, - getWindowCallback, - getWindowByUuidCallback -}; -#endif - -void PlasmaWindowManagementInterface::Private::sendShowingDesktopState() +void PlasmaWindowManagementInterfacePrivate::sendShowingDesktopState() { - for (wl_resource *r : resources) { - sendShowingDesktopState(r); + const auto clientResources = resourceMap(); + for (auto resource : clientResources) { + sendShowingDesktopState(resource->handle); } } -void PlasmaWindowManagementInterface::Private::sendShowingDesktopState(wl_resource *r) +void PlasmaWindowManagementInterfacePrivate::sendShowingDesktopState(wl_resource *r) { uint32_t s = 0; switch (state) { - case ShowingDesktopState::Enabled: - s = ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_ENABLED; + case PlasmaWindowManagementInterface::ShowingDesktopState::Enabled: + s = QtWaylandServer::org_kde_plasma_window_management::show_desktop_enabled; break; - case ShowingDesktopState::Disabled: - s = ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_DISABLED; + case PlasmaWindowManagementInterface::ShowingDesktopState::Disabled: + s = QtWaylandServer::org_kde_plasma_window_management::show_desktop_disabled; break; default: Q_UNREACHABLE(); break; } - org_kde_plasma_window_management_send_show_desktop_changed(r, s); + send_show_desktop_changed(r, s); } -void PlasmaWindowManagementInterface::Private::sendStackingOrderChanged() +void PlasmaWindowManagementInterfacePrivate::sendStackingOrderChanged() { - for (wl_resource *r : resources) { - sendStackingOrderChanged(r); + const auto clientResources = resourceMap(); + for (auto resource : clientResources) { + sendStackingOrderChanged(resource->handle); } } -void PlasmaWindowManagementInterface::Private::sendStackingOrderChanged(wl_resource *r) +void PlasmaWindowManagementInterfacePrivate::sendStackingOrderChanged(wl_resource *r) { if (wl_resource_get_version(r) < ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STACKING_ORDER_CHANGED_SINCE_VERSION) { return; } - wl_array wlIds; - wl_array_init(&wlIds); - const size_t memLength = sizeof(uint32_t) * stackingOrder.size(); - void *s = wl_array_add(&wlIds, memLength); - memcpy(s, stackingOrder.data(), memLength); + send_stacking_order_changed(r, QByteArray::fromRawData(reinterpret_cast(stackingOrder.constData()), sizeof(uint32_t) * stackingOrder.size())); - org_kde_plasma_window_management_send_stacking_order_changed(r, &wlIds); - - wl_array_release(&wlIds); - - QByteArray uuids; + QString uuids; for (const auto &uuid : qAsConst(stackingOrderUuids)) { uuids += uuid; - uuids += ';'; + uuids += QStringLiteral(";"); } - org_kde_plasma_window_management_send_stacking_order_uuid_changed(r, uuids.constData()); + send_stacking_order_uuid_changed(r, uuids); } -void PlasmaWindowManagementInterface::Private::showDesktopCallback(wl_client *client, wl_resource *resource, uint32_t state) +void PlasmaWindowManagementInterfacePrivate::org_kde_plasma_window_management_bind_resource(Resource *resource) { - Q_UNUSED(client) - ShowingDesktopState s = ShowingDesktopState::Disabled; + for (auto window : windows) { + if (resource->version() >= ORG_KDE_PLASMA_WINDOW_MANAGEMENT_WINDOW_WITH_UUID_SINCE_VERSION) { + send_window_with_uuid(resource->handle, window->d->windowId, window->d->uuid); + } else { + send_window(resource->handle, window->d->windowId); + } + } + sendStackingOrderChanged(resource->handle); +} + +void PlasmaWindowManagementInterfacePrivate::org_kde_plasma_window_management_show_desktop(Resource *resource, uint32_t state) +{ + Q_UNUSED(resource) + PlasmaWindowManagementInterface::ShowingDesktopState s = PlasmaWindowManagementInterface::ShowingDesktopState::Disabled; switch (state) { case ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_ENABLED: - s = ShowingDesktopState::Enabled; + s = PlasmaWindowManagementInterface::ShowingDesktopState::Enabled; break; case ORG_KDE_PLASMA_WINDOW_MANAGEMENT_SHOW_DESKTOP_DISABLED: default: - s = ShowingDesktopState::Disabled; + s = PlasmaWindowManagementInterface::ShowingDesktopState::Disabled; break; } - emit reinterpret_cast(wl_resource_get_user_data(resource))->q->requestChangeShowingDesktop(s); + emit q->requestChangeShowingDesktop(s); } -void PlasmaWindowManagementInterface::Private::getWindowCallback(wl_client *client, wl_resource *resource, uint32_t id, uint32_t internalWindowId) +void PlasmaWindowManagementInterfacePrivate::org_kde_plasma_window_management_get_window(Resource *resource, uint32_t id, uint32_t internal_window_id) { - 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; + for (auto window : windows) { + if (window->d->windowId == internal_window_id) { + window->d->add(resource->client(), id, resource->version()); + return; } - ); - 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); + // create a temp window just for the resource and directly send an unmapped + PlasmaWindowInterface *window = new PlasmaWindowInterface(q, q); + window->d->unmapped = true; + window->d->add(resource->client(), id, resource->version()); } -void PlasmaWindowManagementInterface::Private::getWindowByUuidCallback(wl_client *client, wl_resource *resource, uint32_t id, const char* uuid) +void PlasmaWindowManagementInterfacePrivate::org_kde_plasma_window_management_get_window_by_uuid(Resource *resource, uint32_t id, const QString &internal_window_uuid) { - Q_UNUSED(client) - auto p = reinterpret_cast(wl_resource_get_user_data(resource)); - auto it = std::find_if(p->windows.constBegin(), p->windows.constEnd(), - [uuid] (PlasmaWindowInterface *window) { - return window->d->uuid == uuid; + auto it = std::find_if(windows.constBegin(), windows.constEnd(), + [internal_window_uuid] (PlasmaWindowInterface *window) { + return window->d->uuid == internal_window_uuid; } ); - if (it == p->windows.constEnd()) { - qWarning() << "Could not find window with uuid" << uuid; + if (it == windows.constEnd()) { + qWarning() << "Could not find window with uuid" << internal_window_uuid; // create a temp window just for the resource and directly send an unmapped - PlasmaWindowInterface *window = new PlasmaWindowInterface(p->q, p->q); + PlasmaWindowInterface *window = new PlasmaWindowInterface(q, q); window->d->unmapped = true; - window->d->createResource(resource, id); + window->d->add(resource->client(), id, resource->version()); return; } - (*it)->d->createResource(resource, id); + (*it)->d->add(resource->client(), id, resource->version()); } PlasmaWindowManagementInterface::PlasmaWindowManagementInterface(Display *display, QObject *parent) - : Global(new Private(this, display), parent) + : QObject(parent) + , d(new PlasmaWindowManagementInterfacePrivate(this, display)) { } 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) { - if (wl_resource_get_version(shell) >= ORG_KDE_PLASMA_WINDOW_MANAGEMENT_WINDOW_WITH_UUID_SINCE_VERSION) { - org_kde_plasma_window_management_send_window_with_uuid(shell, (*it)->d->windowId, (*it)->d->uuid.constData()); - } else { - org_kde_plasma_window_management_send_window(shell, (*it)->d->windowId); - } - } - sendStackingOrderChanged(shell); -} - -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; } @@ -288,30 +240,24 @@ void PlasmaWindowManagementInterface::setShowingDesktopState(PlasmaWindowManagem d->sendShowingDesktopState(); } -PlasmaWindowManagementInterface::Private *PlasmaWindowManagementInterface::d_func() const -{ - return reinterpret_cast(d.data()); -} - PlasmaWindowInterface *PlasmaWindowManagementInterface::createWindow(QObject *parent, const QUuid &uuid) { - Q_D(); PlasmaWindowInterface *window = new PlasmaWindowInterface(this, parent); - window->d->uuid = uuid.toByteArray(); + window->d->uuid = uuid.toString(); window->d->windowId = ++d->windowIdCounter; //NOTE the window id is deprecated - for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) { - if (wl_resource_get_version(*it) >= ORG_KDE_PLASMA_WINDOW_MANAGEMENT_WINDOW_WITH_UUID_SINCE_VERSION) { - org_kde_plasma_window_management_send_window_with_uuid(*it, window->d->windowId, window->d->uuid.constData()); + const auto clientResources = d->resourceMap(); + for (auto resource : clientResources) { + if (resource->version() >= ORG_KDE_PLASMA_WINDOW_MANAGEMENT_WINDOW_WITH_UUID_SINCE_VERSION) { + d->send_window_with_uuid(resource->handle, window->d->windowId, window->d->uuid); } else { - org_kde_plasma_window_management_send_window(*it, window->d->windowId); + d->send_window(resource->handle, window->d->windowId); } } d->windows << window; connect(window, &QObject::destroyed, this, [this, window] { - Q_D(); d->windows.removeAll(window); } ); @@ -320,7 +266,6 @@ PlasmaWindowInterface *PlasmaWindowManagementInterface::createWindow(QObject *pa QList PlasmaWindowManagementInterface::windows() const { - Q_D(); return d->windows; } @@ -329,7 +274,6 @@ void PlasmaWindowManagementInterface::unmapWindow(PlasmaWindowInterface *window) if (!window) { return; } - Q_D(); d->windows.removeOne(window); Q_ASSERT(!d->windows.contains(window)); window->d->unmap(); @@ -337,7 +281,6 @@ void PlasmaWindowManagementInterface::unmapWindow(PlasmaWindowInterface *window) void PlasmaWindowManagementInterface::setStackingOrder(const QVector& stackingOrder) { - Q_D(); if (d->stackingOrder == stackingOrder) { return; } @@ -347,7 +290,6 @@ void PlasmaWindowManagementInterface::setStackingOrder(const QVector& s void PlasmaWindowManagementInterface::setPlasmaVirtualDesktopManagementInterface(PlasmaVirtualDesktopManagementInterface *manager) { - Q_D(); if (d->plasmaVirtualDesktopManagementInterface == manager) { return; } @@ -356,167 +298,144 @@ void PlasmaWindowManagementInterface::setPlasmaVirtualDesktopManagementInterface PlasmaVirtualDesktopManagementInterface *PlasmaWindowManagementInterface::plasmaVirtualDesktopManagementInterface() const { - Q_D(); return d->plasmaVirtualDesktopManagementInterface; } -#ifndef K_DOXYGEN -const struct org_kde_plasma_window_interface PlasmaWindowInterface::Private::s_interface = { - setStateCallback, - setVirtualDesktopCallback, - setMinimizedGeometryCallback, - unsetMinimizedGeometryCallback, - closeCallback, - requestMoveCallback, - requestResizeCallback, - destroyCallback, - getIconCallback, - requestEnterVirtualDesktopCallback, - requestEnterNewVirtualDesktopCallback, - requestLeaveVirtualDesktopCallback -}; -#endif - -PlasmaWindowInterface::Private::Private(PlasmaWindowManagementInterface *wm, PlasmaWindowInterface *q) - : wm(wm) +//////PlasmaWindow +PlasmaWindowInterfacePrivate::PlasmaWindowInterfacePrivate(PlasmaWindowManagementInterface *wm, PlasmaWindowInterface *q) + : QtWaylandServer::org_kde_plasma_window() + , wm(wm) , q(q) { } -PlasmaWindowInterface::Private::~Private() +PlasmaWindowInterfacePrivate::~PlasmaWindowInterfacePrivate() { - // 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); + destroyed = true; + const auto clientResources = resourceMap(); + for (auto resource : clientResources) { + if(!unmapped) { + send_unmapped(resource->handle); + } + wl_resource_destroy(resource->handle); } } -void PlasmaWindowInterface::Private::destroyCallback(wl_client *, wl_resource *r) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_destroy(Resource *resource) { - Private *p = cast(r); - p->resources.removeAll(r); - wl_resource_destroy(r); - if (p->unmapped && p->resources.isEmpty()) { - p->q->deleteLater(); + wl_resource_destroy(resource->handle); +} + +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_destroy_resource(Resource *resource) +{ + Q_UNUSED(resource) + // Auto destruct when all resources gone + if (unmapped && resourceMap().isEmpty() && !destroyed) { + delete q; } } -void PlasmaWindowInterface::Private::unbind(wl_resource *resource) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_bind_resource(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; + send_virtual_desktop_changed(resource->handle, m_virtualDesktop); - org_kde_plasma_window_send_virtual_desktop_changed(resource, m_virtualDesktop); for (const auto &desk : plasmaVirtualDesktops) { - org_kde_plasma_window_send_virtual_desktop_entered(resource, desk.toUtf8().constData()); + send_virtual_desktop_entered(resource->handle, desk); } if (!m_appId.isEmpty()) { - org_kde_plasma_window_send_app_id_changed(resource, m_appId.toUtf8().constData()); + send_app_id_changed(resource->handle, m_appId); } if (m_pid != 0) { - org_kde_plasma_window_send_pid_changed(resource, m_pid); + send_pid_changed(resource->handle, m_pid); } if (!m_title.isEmpty()) { - org_kde_plasma_window_send_title_changed(resource, m_title.toUtf8().constData()); + send_title_changed(resource->handle, m_title); } if (!m_appObjectPath.isEmpty() || !m_appServiceName.isEmpty()) { - org_kde_plasma_window_send_application_menu(resource, m_appServiceName.toUtf8().constData(), m_appObjectPath.toUtf8().constData()); + send_application_menu(resource->handle, m_appServiceName, m_appObjectPath); } - org_kde_plasma_window_send_state_changed(resource, m_state); + send_state_changed(resource->handle, m_state); if (!m_themedIconName.isEmpty()) { - org_kde_plasma_window_send_themed_icon_name_changed(resource, m_themedIconName.toUtf8().constData()); + send_themed_icon_name_changed(resource->handle, m_themedIconName); } else { - if (wl_resource_get_version(resource) >= ORG_KDE_PLASMA_WINDOW_ICON_CHANGED_SINCE_VERSION) { - org_kde_plasma_window_send_icon_changed(resource); + if (resource->version() >= ORG_KDE_PLASMA_WINDOW_ICON_CHANGED_SINCE_VERSION) { + send_icon_changed(resource->handle); } } - org_kde_plasma_window_send_parent_window(resource, resourceForParent(parentWindow, resource)); + send_parent_window(resource->handle, resourceForParent(parentWindow, resource)); if (unmapped) { - org_kde_plasma_window_send_unmapped(resource); + send_unmapped(resource->handle); } - 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 (geometry.isValid() && resource->version() >= ORG_KDE_PLASMA_WINDOW_GEOMETRY_SINCE_VERSION) { + send_geometry(resource->handle, 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); + if (resource->version() >= ORG_KDE_PLASMA_WINDOW_INITIAL_STATE_SINCE_VERSION) { + send_initial_state(resource->handle); } - c->flush(); } -void PlasmaWindowInterface::Private::setAppId(const QString &appId) +void PlasmaWindowInterfacePrivate::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()); + const auto clientResources = resourceMap(); + + for (auto resource : clientResources) { + send_app_id_changed(resource->handle,m_appId); } } -void PlasmaWindowInterface::Private::setPid(quint32 pid) +void PlasmaWindowInterfacePrivate::setPid(quint32 pid) { if (m_pid == pid) { return; } m_pid = pid; - for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { - org_kde_plasma_window_send_pid_changed(*it, pid); + const auto clientResources = resourceMap(); + + for (auto resource : clientResources) { + send_pid_changed(resource->handle,pid); } } -void PlasmaWindowInterface::Private::setThemedIconName(const QString &iconName) +void PlasmaWindowInterfacePrivate::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()); + const auto clientResources = resourceMap(); + + for (auto resource : clientResources) { + send_themed_icon_name_changed(resource->handle, m_themedIconName); } } -void PlasmaWindowInterface::Private::setIcon(const QIcon &icon) +void PlasmaWindowInterfacePrivate::setIcon(const QIcon &icon) { m_icon = icon; setThemedIconName(m_icon.name()); - if (m_icon.name().isEmpty()) { - for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { - if (wl_resource_get_version(*it) >= ORG_KDE_PLASMA_WINDOW_ICON_CHANGED_SINCE_VERSION) { - org_kde_plasma_window_send_icon_changed(*it); - } + + const auto clientResources = resourceMap(); + for (auto resource : clientResources) { + if (resource->version() >= ORG_KDE_PLASMA_WINDOW_ICON_CHANGED_SINCE_VERSION) { + send_icon_changed(resource->handle); } } + } -void PlasmaWindowInterface::Private::getIconCallback(wl_client *client, wl_resource *resource, int32_t fd) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_get_icon(Resource *resource, int32_t fd) { - Q_UNUSED(client) - Private *p = cast(resource); + Q_UNUSED(resource) QtConcurrent::run( [fd] (const QIcon &icon) { QFile file; @@ -524,66 +443,69 @@ void PlasmaWindowInterface::Private::getIconCallback(wl_client *client, wl_resou QDataStream ds(&file); ds << icon; file.close(); - }, p->m_icon + }, m_icon ); } -void PlasmaWindowInterface::Private::requestEnterVirtualDesktopCallback(wl_client *client, wl_resource *resource, const char *id) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_request_enter_virtual_desktop(Resource *resource, const QString &id) { - Q_UNUSED(client) - Private *p = cast(resource); - emit p->q->enterPlasmaVirtualDesktopRequested(QString::fromUtf8(id)); + Q_UNUSED(resource) + emit q->enterPlasmaVirtualDesktopRequested(id); } -void PlasmaWindowInterface::Private::requestEnterNewVirtualDesktopCallback(wl_client *client, wl_resource *resource) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_request_enter_new_virtual_desktop(Resource *resource) { - Q_UNUSED(client) - Private *p = cast(resource); - emit p->q->enterNewPlasmaVirtualDesktopRequested(); + Q_UNUSED(resource) + emit q->enterNewPlasmaVirtualDesktopRequested(); } -void PlasmaWindowInterface::Private::requestLeaveVirtualDesktopCallback(wl_client *client, wl_resource *resource, const char *id) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_request_leave_virtual_desktop(Resource *resource, const QString &id) { - Q_UNUSED(client) - Private *p = cast(resource); - emit p->q->leavePlasmaVirtualDesktopRequested(QString::fromUtf8(id)); + Q_UNUSED(resource) + emit q->leavePlasmaVirtualDesktopRequested(id); } -void PlasmaWindowInterface::Private::setTitle(const QString &title) +void PlasmaWindowInterfacePrivate::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()); + const auto clientResources = resourceMap(); + + for (auto resource : clientResources) { + send_title_changed(resource->handle, m_title); } } -void PlasmaWindowInterface::Private::setVirtualDesktop(quint32 desktop) +void PlasmaWindowInterfacePrivate::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); + const auto clientResources = resourceMap(); + + for (auto resource : clientResources) { + send_virtual_desktop_changed(resource->handle, m_virtualDesktop); } } -void PlasmaWindowInterface::Private::unmap() +void PlasmaWindowInterfacePrivate::unmap() { unmapped = true; - for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { - org_kde_plasma_window_send_unmapped(*it); + const auto clientResources = resourceMap(); + + for (auto resource : clientResources) { + send_unmapped(resource->handle); } - if (resources.isEmpty()) { - q->deleteLater(); + + if (clientResources.isEmpty()) { + delete q; } } -void PlasmaWindowInterface::Private::setState(org_kde_plasma_window_management_state flag, bool set) +void PlasmaWindowInterfacePrivate::setState(org_kde_plasma_window_management_state flag, bool set) { quint32 newState = m_state; if (set) { @@ -595,28 +517,30 @@ void PlasmaWindowInterface::Private::setState(org_kde_plasma_window_management_s return; } m_state = newState; - for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { - org_kde_plasma_window_send_state_changed(*it, m_state); + const auto clientResources = resourceMap(); + + for (auto resource : clientResources) { + send_state_changed(resource->handle, m_state); } } -wl_resource *PlasmaWindowInterface::Private::resourceForParent(PlasmaWindowInterface *parent, wl_resource *child) const +wl_resource *PlasmaWindowInterfacePrivate::resourceForParent(PlasmaWindowInterface *parent, 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); + + const auto parentResource = parent->d->resourceMap(); + + for (auto resource : parentResource) { + if (child->client() == resource->client()) { + return resource->handle; } - ); - if (it != parent->d->resources.end()) { - return *it; } return nullptr; } -void PlasmaWindowInterface::Private::setParentWindow(PlasmaWindowInterface *window) +void PlasmaWindowInterfacePrivate::setParentWindow(PlasmaWindowInterface *window) { if (parentWindow == window) { return; @@ -629,18 +553,20 @@ void PlasmaWindowInterface::Private::setParentWindow(PlasmaWindowInterface *wind [this] { parentWindow = nullptr; parentWindowDestroyConnection = QMetaObject::Connection(); - for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { - org_kde_plasma_window_send_parent_window(*it, nullptr); + const auto clientResources = resourceMap(); + for (auto resource : clientResources) { + send_parent_window(resource->handle, nullptr); } } ); } - for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { - org_kde_plasma_window_send_parent_window(*it, resourceForParent(window, *it)); + const auto clientResources = resourceMap(); + for (auto resource : clientResources) { + send_parent_window(resource->handle, resourceForParent(window, resource)); } } -void PlasmaWindowInterface::Private::setGeometry(const QRect &geo) +void PlasmaWindowInterfacePrivate::setGeometry(const QRect &geo) { if (geometry == geo) { return; @@ -649,161 +575,155 @@ void PlasmaWindowInterface::Private::setGeometry(const QRect &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) { + + const auto clientResources = resourceMap(); + for (auto resource : clientResources) { + if (resource->version() < ORG_KDE_PLASMA_WINDOW_GEOMETRY_SINCE_VERSION) { continue; } - org_kde_plasma_window_send_geometry(resource, geometry.x(), geometry.y(), geometry.width(), geometry.height()); + send_geometry(resource->handle, geometry.x(), geometry.y(), geometry.width(), geometry.height()); } } -void PlasmaWindowInterface::Private::setApplicationMenuPaths(const QString &service, const QString &object) +void PlasmaWindowInterfacePrivate::setApplicationMenuPaths(const QString &service, const QString &object) { if (m_appServiceName == service && m_appObjectPath == object) { return; } m_appServiceName = service; m_appObjectPath = object; - for (auto it = resources.constBegin(); it != resources.constEnd(); ++it) { - auto resource = *it; - if (wl_resource_get_version(resource) < ORG_KDE_PLASMA_WINDOW_APPLICATION_MENU_SINCE_VERSION) { + const auto clientResources = resourceMap(); + for (auto resource : clientResources) { + if (resource->version() < ORG_KDE_PLASMA_WINDOW_APPLICATION_MENU_SINCE_VERSION) { continue; } - org_kde_plasma_window_send_application_menu(resource, qUtf8Printable(service), qUtf8Printable(object)); + send_application_menu(resource->handle, service, object); } } -void PlasmaWindowInterface::Private::closeCallback(wl_client *client, wl_resource *resource) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_close(Resource *resource) { - Q_UNUSED(client) - Private *p = cast(resource); - emit p->q->closeRequested(); + Q_UNUSED(resource) + emit q->closeRequested(); } -void PlasmaWindowInterface::Private::requestMoveCallback(wl_client *client, wl_resource *resource) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_request_move(Resource *resource) { - Q_UNUSED(client) - Private *p = cast(resource); - emit p->q->moveRequested(); + Q_UNUSED(resource) + emit q->moveRequested(); } -void PlasmaWindowInterface::Private::requestResizeCallback(wl_client *client, wl_resource *resource) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_request_resize(Resource *resource) { - Q_UNUSED(client) - Private *p = cast(resource); - emit p->q->resizeRequested(); + Q_UNUSED(resource) + emit q->resizeRequested(); } -void PlasmaWindowInterface::Private::setVirtualDesktopCallback(wl_client *client, wl_resource *resource, uint32_t number) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_set_virtual_desktop(Resource *resource, uint32_t number) { - Q_UNUSED(client) - Private *p = cast(resource); - emit p->q->virtualDesktopRequested(number); + Q_UNUSED(resource) + emit q->virtualDesktopRequested(number); } -void PlasmaWindowInterface::Private::setStateCallback(wl_client *client, wl_resource *resource, uint32_t flags, uint32_t state) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_set_state(Resource *resource, uint32_t flags, uint32_t state) { - Q_UNUSED(client) - Private *p = cast(resource); + Q_UNUSED(resource) if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ACTIVE) { - emit p->q->activeRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_ACTIVE); + emit 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); + emit 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); + emit 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); + emit 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); + emit 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); + emit 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); + emit 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); + emit 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); + emit 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); + emit 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); + emit 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); + emit q->skipTaskbarRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPTASKBAR); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPSWITCHER) { - emit p->q->skipSwitcherRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPSWITCHER); + emit q->skipSwitcherRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SKIPSWITCHER); } if (flags & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADEABLE) { - emit p->q->shadeableRequested(state & ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_SHADEABLE); + emit 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); + emit 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); + emit 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); + emit 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); + emit 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) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_set_minimized_geometry(Resource *resource, wl_resource *panel, uint32_t x, uint32_t y, uint32_t width, uint32_t height) { - Q_UNUSED(client) - Private *p = cast(resource); + Q_UNUSED(resource) SurfaceInterface *panelSurface = SurfaceInterface::get(panel); if (!panelSurface) { return; } - if (p->minimizedGeometries.value(panelSurface) == QRect(x, y, width, height)) { + if (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(); + minimizedGeometries[panelSurface] = QRect(x, y, width, height); + emit q->minimizedGeometriesChanged(); + QObject::connect(panelSurface, &QObject::destroyed, q, [this, panelSurface] () { + if (minimizedGeometries.remove(panelSurface)) { + emit q->minimizedGeometriesChanged(); } }); } -void PlasmaWindowInterface::Private::unsetMinimizedGeometryCallback(wl_client *client, wl_resource *resource, wl_resource *panel) +void PlasmaWindowInterfacePrivate::org_kde_plasma_window_unset_minimized_geometry(Resource *resource, wl_resource *panel) { - Q_UNUSED(client) - Private *p = cast(resource); + Q_UNUSED(resource) SurfaceInterface *panelSurface = SurfaceInterface::get(panel); if (!panelSurface) { return; } - if (!p->minimizedGeometries.contains(panelSurface)) { + if (!minimizedGeometries.contains(panelSurface)) { return; } - p->minimizedGeometries.remove(panelSurface); - emit p->q->minimizedGeometriesChanged(); + minimizedGeometries.remove(panelSurface); + emit q->minimizedGeometriesChanged(); } PlasmaWindowInterface::PlasmaWindowInterface(PlasmaWindowManagementInterface *wm, QObject *parent) : QObject(parent) - , d(new Private(wm, this)) + , d(new PlasmaWindowInterfacePrivate(wm, this)) { } @@ -877,7 +797,7 @@ void PlasmaWindowInterface::setOnAllDesktops(bool set) if (!d->wm->plasmaVirtualDesktopManagementInterface()) { return; } - + const auto clientResources = d->resourceMap(); //the current vd management if (set) { if (d->plasmaVirtualDesktops.isEmpty()) { @@ -885,8 +805,8 @@ void PlasmaWindowInterface::setOnAllDesktops(bool set) } //leaving everything means on all desktops for (auto desk : plasmaVirtualDesktops()) { - for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) { - org_kde_plasma_window_send_virtual_desktop_left(*it, desk.toUtf8().constData()); + for (auto resource : clientResources) { + d->send_virtual_desktop_left(resource->handle, desk); } } d->plasmaVirtualDesktops.clear(); @@ -898,8 +818,8 @@ void PlasmaWindowInterface::setOnAllDesktops(bool set) for (auto desk : d->wm->plasmaVirtualDesktopManagementInterface()->desktops()) { if (desk->isActive() && !d->plasmaVirtualDesktops.contains(desk->id())) { d->plasmaVirtualDesktops << desk->id(); - for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) { - org_kde_plasma_window_send_virtual_desktop_entered(*it, desk->id().toUtf8().constData()); + for (auto resource : clientResources) { + d->send_virtual_desktop_entered(resource->handle, desk->id()); } } } @@ -970,8 +890,10 @@ void PlasmaWindowInterface::addPlasmaVirtualDesktop(const QString &id) connect(desktop, &QObject::destroyed, this, [this, id](){removePlasmaVirtualDesktop(id);}); - for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) { - org_kde_plasma_window_send_virtual_desktop_entered(*it, id.toUtf8().constData()); + + const auto clientResources = d->resourceMap(); + for (auto resource : clientResources) { + d->send_virtual_desktop_entered(resource->handle, id); } } @@ -982,8 +904,9 @@ void PlasmaWindowInterface::removePlasmaVirtualDesktop(const QString &id) } d->plasmaVirtualDesktops.removeAll(id); - for (auto it = d->resources.constBegin(); it != d->resources.constEnd(); ++it) { - org_kde_plasma_window_send_virtual_desktop_left(*it, id.toUtf8().constData()); + const auto clientResources = d->resourceMap(); + for (auto resource : clientResources) { + d->send_virtual_desktop_left(resource->handle, id); } //we went on all desktops diff --git a/src/wayland/plasmawindowmanagement_interface.h b/src/wayland/plasmawindowmanagement_interface.h index 82c3194471..14bcd9291c 100644 --- a/src/wayland/plasmawindowmanagement_interface.h +++ b/src/wayland/plasmawindowmanagement_interface.h @@ -10,9 +10,6 @@ #include -#include "global.h" -#include "resource.h" - class QSize; namespace KWaylandServer @@ -22,15 +19,17 @@ class Display; class PlasmaWindowInterface; class SurfaceInterface; class PlasmaVirtualDesktopManagementInterface; +class PlasmaWindowManagementInterfacePrivate; +class PlasmaWindowInterfacePrivate; /** * @todo Add documentation */ -class KWAYLANDSERVER_EXPORT PlasmaWindowManagementInterface : public Global +class KWAYLANDSERVER_EXPORT PlasmaWindowManagementInterface : public QObject { Q_OBJECT public: - virtual ~PlasmaWindowManagementInterface(); + ~PlasmaWindowManagementInterface() override; enum class ShowingDesktopState { Disabled, Enabled @@ -84,8 +83,7 @@ Q_SIGNALS: private: friend class Display; explicit PlasmaWindowManagementInterface(Display *display, QObject *parent); - class Private; - Private *d_func() const; + QScopedPointer d; }; /** @@ -95,7 +93,7 @@ class KWAYLANDSERVER_EXPORT PlasmaWindowInterface : public QObject { Q_OBJECT public: - virtual ~PlasmaWindowInterface(); + ~PlasmaWindowInterface() override; void setTitle(const QString &title); void setAppId(const QString &appId); @@ -317,10 +315,11 @@ Q_SIGNALS: private: friend class PlasmaWindowManagementInterface; + friend class PlasmaWindowInterfacePrivate; + friend class PlasmaWindowManagementInterfacePrivate; explicit PlasmaWindowInterface(PlasmaWindowManagementInterface *wm, QObject *parent); - class Private; - const QScopedPointer d; + QScopedPointer d; }; }