From 3465ecac1685256b0862d5c4478756d2b5ca1c4f Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Fri, 16 Feb 2024 00:53:38 +0100 Subject: [PATCH] wayland: implement plasma window management v17 This fixes plasmashell crashing because of the stacking order string exceeding the size of a Wayland message CCBUG: 479492 --- src/wayland/plasmawindowmanagement.cpp | 38 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/wayland/plasmawindowmanagement.cpp b/src/wayland/plasmawindowmanagement.cpp index 5943238b75..8506326ea0 100644 --- a/src/wayland/plasmawindowmanagement.cpp +++ b/src/wayland/plasmawindowmanagement.cpp @@ -24,7 +24,7 @@ namespace KWin { -static const quint32 s_version = 16; +static const quint32 s_version = 17; static const quint32 s_activationVersion = 1; class PlasmaWindowManagementInterfacePrivate : public QtWaylandServer::org_kde_plasma_window_management @@ -37,6 +37,8 @@ public: void sendStackingOrderChanged(wl_resource *resource); void sendStackingOrderUuidsChanged(); void sendStackingOrderUuidsChanged(wl_resource *resource); + void sendStackingOrderChanged2(); + void sendStackingOrderChanged2(Resource *resource); PlasmaWindowManagementInterface::ShowingDesktopState state = PlasmaWindowManagementInterface::ShowingDesktopState::Disabled; QList windows; @@ -51,6 +53,7 @@ protected: 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; + void org_kde_plasma_window_management_get_stacking_order(Resource *resource, uint32_t id) override; }; class PlasmaWindowInterfacePrivate : public QtWaylandServer::org_kde_plasma_window @@ -161,7 +164,8 @@ void PlasmaWindowManagementInterfacePrivate::sendStackingOrderChanged() void PlasmaWindowManagementInterfacePrivate::sendStackingOrderChanged(wl_resource *r) { - if (wl_resource_get_version(r) < ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STACKING_ORDER_CHANGED_SINCE_VERSION) { + if (wl_resource_get_version(r) < ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STACKING_ORDER_CHANGED_SINCE_VERSION + || wl_resource_get_version(r) >= ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STACKING_ORDER_CHANGED_2_SINCE_VERSION) { return; } @@ -178,7 +182,8 @@ void PlasmaWindowManagementInterfacePrivate::sendStackingOrderUuidsChanged() void PlasmaWindowManagementInterfacePrivate::sendStackingOrderUuidsChanged(wl_resource *r) { - if (wl_resource_get_version(r) < ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STACKING_ORDER_UUID_CHANGED_SINCE_VERSION) { + if (wl_resource_get_version(r) < ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STACKING_ORDER_UUID_CHANGED_SINCE_VERSION + || wl_resource_get_version(r) >= ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STACKING_ORDER_CHANGED_2_SINCE_VERSION) { return; } @@ -194,6 +199,22 @@ void PlasmaWindowManagementInterfacePrivate::sendStackingOrderUuidsChanged(wl_re send_stacking_order_uuid_changed(r, uuids); } +void PlasmaWindowManagementInterfacePrivate::sendStackingOrderChanged2() +{ + const auto clientResources = resourceMap(); + for (auto resource : clientResources) { + sendStackingOrderChanged2(resource); + } +} + +void PlasmaWindowManagementInterfacePrivate::sendStackingOrderChanged2(Resource *resource) +{ + if (resource->version() < ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STACKING_ORDER_CHANGED_2_SINCE_VERSION) { + return; + } + org_kde_plasma_window_management_send_stacking_order_changed_2(resource->handle); +} + void PlasmaWindowManagementInterfacePrivate::org_kde_plasma_window_management_bind_resource(Resource *resource) { for (const auto window : std::as_const(windows)) { @@ -257,6 +278,16 @@ void PlasmaWindowManagementInterfacePrivate::org_kde_plasma_window_management_ge (*it)->d->sendInitialState(windowResource); } +void PlasmaWindowManagementInterfacePrivate::org_kde_plasma_window_management_get_stacking_order(Resource *resource, uint32_t id) +{ + wl_resource *stackingOrder = wl_resource_create(resource->client(), &org_kde_plasma_stacking_order_interface, resource->version(), id); + for (const auto &uuid : std::as_const(stackingOrderUuids)) { + org_kde_plasma_stacking_order_send_window(stackingOrder, uuid.toUtf8().constData()); + } + org_kde_plasma_stacking_order_send_done(stackingOrder); + wl_resource_destroy(stackingOrder); +} + PlasmaWindowManagementInterface::PlasmaWindowManagementInterface(Display *display, QObject *parent) : QObject(parent) , d(new PlasmaWindowManagementInterfacePrivate(this, display)) @@ -317,6 +348,7 @@ void PlasmaWindowManagementInterface::setStackingOrderUuids(const QList } d->stackingOrderUuids = stackingOrderUuids; d->sendStackingOrderUuidsChanged(); + d->sendStackingOrderChanged2(); } void PlasmaWindowManagementInterface::setPlasmaVirtualDesktopManagementInterface(PlasmaVirtualDesktopManagementInterface *manager)