KWayland

server_decoration.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Martin Gräßlin <[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.h"
7 #include "event_queue.h"
8 #include "logging.h"
9 #include "surface.h"
10 #include "wayland_pointer_p.h"
11 
12 #include <wayland-server-decoration-client-protocol.h>
13 
14 #include <QVector>
15 
16 namespace KWayland
17 {
18 namespace Client
19 {
20 class Q_DECL_HIDDEN ServerSideDecorationManager::Private
21 {
22 public:
23  Private() = default;
24 
25  void setup(org_kde_kwin_server_decoration_manager *serversidedecorationmanager);
26 
27  WaylandPointer<org_kde_kwin_server_decoration_manager, org_kde_kwin_server_decoration_manager_destroy> serversidedecorationmanager;
28  EventQueue *queue = nullptr;
31 
32 private:
33  static void defaultModeCallback(void *data, org_kde_kwin_server_decoration_manager *manager, uint32_t mode);
34  static const struct org_kde_kwin_server_decoration_manager_listener s_listener;
35 };
36 
37 class Q_DECL_HIDDEN ServerSideDecoration::Private
38 {
39 public:
40  Private(ServerSideDecoration *q);
41 
42  void setup(org_kde_kwin_server_decoration *serversidedecoration);
43 
44  WaylandPointer<org_kde_kwin_server_decoration, org_kde_kwin_server_decoration_release> serversidedecoration;
45  Mode mode = Mode::None;
46  Mode defaultMode = Mode::None;
47 
48 private:
49  static void modeCallback(void *data, org_kde_kwin_server_decoration *org_kde_kwin_server_decoration, uint32_t mode);
50  static const struct org_kde_kwin_server_decoration_listener s_listener;
51 
52  ServerSideDecoration *q;
53 };
54 
55 #ifndef K_DOXYGEN
56 const org_kde_kwin_server_decoration_manager_listener ServerSideDecorationManager::Private::s_listener = {defaultModeCallback};
57 #endif
58 
59 void ServerSideDecorationManager::Private::defaultModeCallback(void *data, org_kde_kwin_server_decoration_manager *manager, uint32_t mode)
60 {
61  auto p = reinterpret_cast<ServerSideDecorationManager::Private *>(data);
62  Q_ASSERT(p->serversidedecorationmanager == manager);
63 
65  switch (mode) {
66  case ORG_KDE_KWIN_SERVER_DECORATION_MODE_NONE:
68  break;
69  case ORG_KDE_KWIN_SERVER_DECORATION_MODE_CLIENT:
71  break;
72  case ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER:
74  break;
75  default:
76  // invalid mode cannot set
77  qCWarning(KWAYLAND_CLIENT) << "Invalid decoration mode pushed by Server:" << mode;
78  return;
79  }
80  p->defaultMode = m;
81  // update the default mode on all decorations
82  for (auto it = p->decorations.constBegin(); it != p->decorations.constEnd(); ++it) {
83  (*it)->d->defaultMode = m;
84  // TODO: do we need a signal?
85  }
86 }
87 
88 void ServerSideDecorationManager::Private::setup(org_kde_kwin_server_decoration_manager *manager)
89 {
90  Q_ASSERT(manager);
91  Q_ASSERT(!serversidedecorationmanager);
92  serversidedecorationmanager.setup(manager);
93  org_kde_kwin_server_decoration_manager_add_listener(serversidedecorationmanager, &s_listener, this);
94 }
95 
97  : QObject(parent)
98  , d(new Private)
99 {
100 }
101 
102 ServerSideDecorationManager::~ServerSideDecorationManager()
103 {
104  release();
105 }
106 
107 void ServerSideDecorationManager::setup(org_kde_kwin_server_decoration_manager *serversidedecorationmanager)
108 {
109  d->setup(serversidedecorationmanager);
110 }
111 
113 {
114  d->serversidedecorationmanager.release();
115 }
116 
118 {
119  d->serversidedecorationmanager.destroy();
120 }
121 
123 {
124  d->queue = queue;
125 }
126 
128 {
129  return d->queue;
130 }
131 
132 ServerSideDecorationManager::operator org_kde_kwin_server_decoration_manager *()
133 {
134  return d->serversidedecorationmanager;
135 }
136 
137 ServerSideDecorationManager::operator org_kde_kwin_server_decoration_manager *() const
138 {
139  return d->serversidedecorationmanager;
140 }
141 
143 {
144  return d->serversidedecorationmanager.isValid();
145 }
146 
147 ServerSideDecoration *ServerSideDecorationManager::create(Surface *surface, QObject *parent)
148 {
149  return create(*surface, parent);
150 }
151 
152 ServerSideDecoration *ServerSideDecorationManager::create(wl_surface *surface, QObject *parent)
153 {
154  Q_ASSERT(isValid());
155  ServerSideDecoration *deco = new ServerSideDecoration(parent);
156  auto w = org_kde_kwin_server_decoration_manager_create(d->serversidedecorationmanager, surface);
157  if (d->queue) {
158  d->queue->addProxy(w);
159  }
160  deco->d->defaultMode = d->defaultMode;
161  deco->d->mode = d->defaultMode;
162  deco->setup(w);
163  return deco;
164 }
165 
166 #ifndef K_DOXYGEN
167 const org_kde_kwin_server_decoration_listener ServerSideDecoration::Private::s_listener = {modeCallback};
168 #endif
169 
170 ServerSideDecoration::Private::Private(ServerSideDecoration *q)
171  : q(q)
172 {
173 }
174 
175 void ServerSideDecoration::Private::modeCallback(void *data, org_kde_kwin_server_decoration *decoration, uint32_t mode)
176 {
177  Q_UNUSED(decoration)
178  Private *p = reinterpret_cast<Private *>(data);
179  Mode m;
180  switch (mode) {
181  case ORG_KDE_KWIN_SERVER_DECORATION_MODE_NONE:
182  m = Mode::None;
183  break;
184  case ORG_KDE_KWIN_SERVER_DECORATION_MODE_CLIENT:
185  m = Mode::Client;
186  break;
187  case ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER:
188  m = Mode::Server;
189  break;
190  default:
191  // invalid mode cannot set
192  qCWarning(KWAYLAND_CLIENT) << "Invalid decoration mode pushed by Server:" << mode;
193  return;
194  }
195  p->mode = m;
196  Q_EMIT p->q->modeChanged();
197 }
198 
199 ServerSideDecoration::ServerSideDecoration(QObject *parent)
200  : QObject(parent)
201  , d(new Private(this))
202 {
203 }
204 
205 ServerSideDecoration::~ServerSideDecoration()
206 {
207  release();
208 }
209 
210 void ServerSideDecoration::Private::setup(org_kde_kwin_server_decoration *s)
211 {
212  Q_ASSERT(s);
213  Q_ASSERT(!serversidedecoration.isValid());
214  serversidedecoration.setup(s);
215  org_kde_kwin_server_decoration_add_listener(serversidedecoration, &s_listener, this);
216 }
217 
218 void ServerSideDecoration::setup(org_kde_kwin_server_decoration *serversidedecoration)
219 {
220  d->setup(serversidedecoration);
221 }
222 
224 {
225  d->serversidedecoration.release();
226 }
227 
229 {
230  d->serversidedecoration.destroy();
231 }
232 
233 ServerSideDecoration::operator org_kde_kwin_server_decoration *()
234 {
235  return d->serversidedecoration;
236 }
237 
238 ServerSideDecoration::operator org_kde_kwin_server_decoration *() const
239 {
240  return d->serversidedecoration;
241 }
242 
244 {
245  return d->serversidedecoration.isValid();
246 }
247 
249 {
250  Q_ASSERT(d->serversidedecoration.isValid());
251  uint32_t wlMode = 0;
252  switch (mode) {
253  case Mode::None:
254  wlMode = ORG_KDE_KWIN_SERVER_DECORATION_MODE_NONE;
255  break;
256  case Mode::Client:
257  wlMode = ORG_KDE_KWIN_SERVER_DECORATION_MODE_CLIENT;
258  break;
259  case Mode::Server:
260  wlMode = ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER;
261  break;
262  default:
263  Q_UNREACHABLE();
264  }
265  org_kde_kwin_server_decoration_request_mode(d->serversidedecoration, wlMode);
266 }
267 
269 {
270  return d->mode;
271 }
272 
274 {
275  return d->defaultMode;
276 }
277 
278 }
279 }
void destroy()
Destroys the data held by this ServerSideDecoration.
@ Client
The decoration is part of the surface.
Wrapper for the wl_surface interface.
Definition: surface.h:43
void setup(org_kde_kwin_server_decoration_manager *serversidedecorationmanager)
Setup this ServerSideDecorationManager to manage the serversidedecorationmanager.
Describing how a Surface should be decorated.
void setup(org_kde_kwin_server_decoration *serversidedecoration)
Setup this ServerSideDecoration to manage the serversidedecoration.
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:54
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating objects with this ServerSideDecorationManager.
@ Server
The surface gets embedded into a decoration frame provided by the Server.
Mode
Decoration mode used for the Surface.
ServerSideDecorationManager(QObject *parent=nullptr)
Creates a new ServerSideDecorationManager.
void requestMode(Mode mode)
Request the decoration mode for the Surface.
@ None
Undecorated: neither client, nor server provide decoration.
void destroy()
Destroys the data held by this ServerSideDecorationManager.
QObject * parent() const const
void release()
Releases the org_kde_kwin_server_decoration_manager interface.
void release()
Releases the org_kde_kwin_server_decoration interface.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 03:54:08 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.