KWaylandServer

server_decoration_palette_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 David Edmundson <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "server_decoration_palette_interface.h"
7 #include "display.h"
8 #include "logging.h"
9 #include "surface_interface.h"
10 
11 #include <QtGlobal>
12 
13 #include <qwayland-server-server-decoration-palette.h>
14 
15 namespace KWaylandServer
16 {
17 static const quint32 s_version = 1;
18 
19 class ServerSideDecorationPaletteManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_server_decoration_palette_manager
20 {
21 public:
22  ServerSideDecorationPaletteManagerInterfacePrivate(ServerSideDecorationPaletteManagerInterface *q, Display *display);
23 
25  ServerSideDecorationPaletteManagerInterface *q;
26 
27 protected:
28  void org_kde_kwin_server_decoration_palette_manager_create(Resource *resource, uint32_t id, struct ::wl_resource *surface) override;
29 };
30 
31 void ServerSideDecorationPaletteManagerInterfacePrivate::org_kde_kwin_server_decoration_palette_manager_create(Resource *resource,
32  uint32_t id,
33  wl_resource *surface)
34 {
35  SurfaceInterface *s = SurfaceInterface::get(surface);
36  if (!s) {
37  wl_resource_post_error(resource->handle, 0, "invalid surface");
38  qCWarning(KWAYLAND_SERVER) << "ServerSideDecorationPaletteInterface requested for non existing SurfaceInterface";
39  return;
40  }
41 
42  wl_resource *palette_resource = wl_resource_create(resource->client(), &org_kde_kwin_server_decoration_palette_interface, resource->version(), id);
43  if (!palette_resource) {
44  wl_client_post_no_memory(resource->client());
45  return;
46  }
47  auto palette = new ServerSideDecorationPaletteInterface(s, palette_resource);
48 
49  palettes.append(palette);
50  QObject::connect(palette, &QObject::destroyed, q, [=]() {
51  palettes.removeOne(palette);
52  });
53  Q_EMIT q->paletteCreated(palette);
54 }
55 
56 ServerSideDecorationPaletteManagerInterfacePrivate::ServerSideDecorationPaletteManagerInterfacePrivate(ServerSideDecorationPaletteManagerInterface *_q,
57  Display *display)
58  : QtWaylandServer::org_kde_kwin_server_decoration_palette_manager(*display, s_version)
59  , q(_q)
60 {
61 }
62 
63 ServerSideDecorationPaletteManagerInterface::ServerSideDecorationPaletteManagerInterface(Display *display, QObject *parent)
64  : QObject(parent)
65  , d(new ServerSideDecorationPaletteManagerInterfacePrivate(this, display))
66 {
67 }
68 
69 ServerSideDecorationPaletteManagerInterface::~ServerSideDecorationPaletteManagerInterface() = default;
70 
72 {
73  for (ServerSideDecorationPaletteInterface *menu : qAsConst(d->palettes)) {
74  if (menu->surface() == surface) {
75  return menu;
76  }
77  }
78  return nullptr;
79 }
80 
81 class ServerSideDecorationPaletteInterfacePrivate : public QtWaylandServer::org_kde_kwin_server_decoration_palette
82 {
83 public:
84  ServerSideDecorationPaletteInterfacePrivate(ServerSideDecorationPaletteInterface *_q, SurfaceInterface *surface, wl_resource *resource);
85 
87  QString palette;
89 
90 protected:
91  void org_kde_kwin_server_decoration_palette_destroy_resource(Resource *resource) override;
92  void org_kde_kwin_server_decoration_palette_set_palette(Resource *resource, const QString &palette) override;
93  void org_kde_kwin_server_decoration_palette_release(Resource *resource) override;
94 };
95 
96 void ServerSideDecorationPaletteInterfacePrivate::org_kde_kwin_server_decoration_palette_release(Resource *resource)
97 {
98  wl_resource_destroy(resource->handle);
99 }
100 
101 void ServerSideDecorationPaletteInterfacePrivate::org_kde_kwin_server_decoration_palette_set_palette(Resource *resource, const QString &palette)
102 {
103  Q_UNUSED(resource)
104 
105  if (this->palette == palette) {
106  return;
107  }
108  this->palette = palette;
109  Q_EMIT q->paletteChanged(this->palette);
110 }
111 
112 void ServerSideDecorationPaletteInterfacePrivate::org_kde_kwin_server_decoration_palette_destroy_resource(Resource *resource)
113 {
114  Q_UNUSED(resource)
115  delete q;
116 }
117 
118 ServerSideDecorationPaletteInterfacePrivate::ServerSideDecorationPaletteInterfacePrivate(ServerSideDecorationPaletteInterface *_q,
119  SurfaceInterface *surface,
120  wl_resource *resource)
121  : QtWaylandServer::org_kde_kwin_server_decoration_palette(resource)
122  , surface(surface)
123  , q(_q)
124 {
125 }
126 
127 ServerSideDecorationPaletteInterface::ServerSideDecorationPaletteInterface(SurfaceInterface *surface, wl_resource *resource)
128  : QObject()
129  , d(new ServerSideDecorationPaletteInterfacePrivate(this, surface, resource))
130 {
131 }
132 
133 ServerSideDecorationPaletteInterface::~ServerSideDecorationPaletteInterface() = default;
134 
136 {
137  return d->palette;
138 }
139 
141 {
142  return d->surface;
143 }
144 
145 } // namespace
ServerSideDecorationPaletteInterface * paletteForSurface(SurfaceInterface *)
Returns any existing palette for a given surface This returns a null pointer if no ServerSideDecorati...
static SurfaceInterface * get(wl_resource *native)
Provides the palette This interface is attached to a wl_surface and informs the server of a requested...
QObject(QObject *parent)
Resource representing a wl_surface.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
void destroyed(QObject *obj)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:08:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.