From 89dc01ada88774a750a7c80b5b062a6979a112e8 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 13 May 2021 09:16:35 +0300 Subject: [PATCH] Add a PlasmaShellSurfaceInterface getter This allows to simplify some compositor code. --- src/wayland/plasmashell_interface.cpp | 24 +++++++++++++++--------- src/wayland/plasmashell_interface.h | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/wayland/plasmashell_interface.cpp b/src/wayland/plasmashell_interface.cpp index b9dbef39cb..ada674bc28 100644 --- a/src/wayland/plasmashell_interface.cpp +++ b/src/wayland/plasmashell_interface.cpp @@ -15,14 +15,13 @@ namespace KWaylandServer { static const quint32 s_version = 6; +static QList s_shellSurfaces; class PlasmaShellInterfacePrivate : public QtWaylandServer::org_kde_plasma_shell { public: PlasmaShellInterfacePrivate(PlasmaShellInterface *q, Display *display); - QList shellSurfaces; - private: void org_kde_plasma_shell_get_surface(Resource * resource, uint32_t id, struct ::wl_resource *surface) override; PlasmaShellInterface *q; @@ -79,10 +78,7 @@ void PlasmaShellInterfacePrivate::org_kde_plasma_shell_get_surface(QtWaylandServ return; } - auto it = std::find_if(shellSurfaces.constBegin(), shellSurfaces.constEnd(), [&s](PlasmaShellSurfaceInterface *shellSurface) { - return shellSurface->surface() == s; - }); - if (it != shellSurfaces.constEnd()) { + if (PlasmaShellSurfaceInterface::get(s)) { wl_resource_post_error(resource->handle, 0, "org_kde_plasma_shell_surface already exists"); return; } @@ -90,10 +86,10 @@ void PlasmaShellInterfacePrivate::org_kde_plasma_shell_get_surface(QtWaylandServ wl_resource *shell_resource = wl_resource_create(resource->client(), &org_kde_plasma_surface_interface, resource->version(), id); auto shellSurface = new PlasmaShellSurfaceInterface(s, shell_resource); - shellSurfaces.append(shellSurface); + s_shellSurfaces.append(shellSurface); - QObject::connect(shellSurface, &QObject::destroyed, q, [this, shellSurface]() { - shellSurfaces.removeOne(shellSurface); + QObject::connect(shellSurface, &QObject::destroyed, [shellSurface]() { + s_shellSurfaces.removeOne(shellSurface); }); emit q->surfaceCreated(shellSurface); @@ -310,4 +306,14 @@ PlasmaShellSurfaceInterface *PlasmaShellSurfaceInterface::get(wl_resource *nativ return nullptr; } +PlasmaShellSurfaceInterface *PlasmaShellSurfaceInterface::get(SurfaceInterface *surface) +{ + for (PlasmaShellSurfaceInterface *shellSurface : qAsConst(s_shellSurfaces)) { + if (shellSurface->surface() == surface) { + return shellSurface; + } + } + return nullptr; +} + } diff --git a/src/wayland/plasmashell_interface.h b/src/wayland/plasmashell_interface.h index 00430e0185..4af9af8212 100644 --- a/src/wayland/plasmashell_interface.h +++ b/src/wayland/plasmashell_interface.h @@ -153,6 +153,7 @@ public: * @returns The PlasmaShellSurfaceInterface for the @p native resource. */ static PlasmaShellSurfaceInterface *get(wl_resource *native); + static PlasmaShellSurfaceInterface *get(SurfaceInterface *surface); Q_SIGNALS: /**