Add a PlasmaShellSurfaceInterface getter

This allows to simplify some compositor code.
This commit is contained in:
Vlad Zahorodnii 2021-05-13 09:16:35 +03:00
parent c2fc33872e
commit 89dc01ada8
2 changed files with 16 additions and 9 deletions

View file

@ -15,14 +15,13 @@ namespace KWaylandServer
{
static const quint32 s_version = 6;
static QList<PlasmaShellSurfaceInterface *> s_shellSurfaces;
class PlasmaShellInterfacePrivate : public QtWaylandServer::org_kde_plasma_shell
{
public:
PlasmaShellInterfacePrivate(PlasmaShellInterface *q, Display *display);
QList<PlasmaShellSurfaceInterface *> 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;
}
}

View file

@ -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:
/**