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

KDE's Doxygen guidelines are available online.