KWayland

xdgforeign_v2.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 Marco Martin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "xdgforeign_v2.h"
7 #include "xdgforeign_p.h"
8 #include "event_queue.h"
9 #include "wayland_pointer_p.h"
10 
11 #include <wayland-xdg-foreign-unstable-v2-client-protocol.h>
12 
13 #include <QDebug>
14 
15 namespace KWayland
16 {
17 namespace Client
18 {
19 
20 class Q_DECL_HIDDEN XdgExporterUnstableV2::Private : public XdgExporter::Private
21 {
22 public:
23  Private();
24 
25  XdgExported *exportTopLevelV2(Surface *surface, QObject *parent) override;
26  void setupV2(zxdg_exporter_v2 *arg) override;
27  zxdg_exporter_v2 *exporterV2() override;
28 
29  void release() override;
30  void destroy() override;
31  bool isValid() override;
32 
33  WaylandPointer<zxdg_exporter_v2, zxdg_exporter_v2_destroy> exporter;
34 };
35 
36 XdgExporterUnstableV2::Private::Private()
37  : XdgExporter::Private()
38 {}
39 
40 zxdg_exporter_v2 *XdgExporterUnstableV2::Private::exporterV2()
41 {
42  return exporter;
43 }
44 
45 void XdgExporterUnstableV2::Private::release()
46 {
47  exporter.release();
48 }
49 
50 void XdgExporterUnstableV2::Private::destroy()
51 {
52  exporter.destroy();
53 }
54 
55 bool XdgExporterUnstableV2::Private::isValid()
56 {
57  return exporter.isValid();
58 }
59 
60 XdgExported *XdgExporterUnstableV2::Private::exportTopLevelV2(Surface *surface, QObject *parent)
61 {
62  Q_ASSERT(isValid());
63  auto p = new XdgExportedUnstableV2(parent);
64  auto w = zxdg_exporter_v2_export_toplevel(exporter, *surface);
65  if (queue) {
66  queue->addProxy(w);
67  }
68  p->setup(w);
69  return p;
70 }
71 
72 
73 XdgExporterUnstableV2::XdgExporterUnstableV2(QObject *parent)
74  : XdgExporter(new Private, parent)
75 {
76 }
77 
78 void XdgExporterUnstableV2::Private::setupV2(zxdg_exporter_v2 *arg)
79 {
80  Q_ASSERT(arg);
81  Q_ASSERT(!exporter);
82  exporter.setup(arg);
83 }
84 
85 XdgExporterUnstableV2::~XdgExporterUnstableV2()
86 {
87 }
88 
89 class Q_DECL_HIDDEN XdgImporterUnstableV2::Private : public XdgImporter::Private
90 {
91 public:
92  Private();
93 
94  XdgImported *importTopLevelV2(const QString & handle, QObject *parent) override;
95  void setupV2(zxdg_importer_v2 *arg) override;
96  zxdg_importer_v2 *importerV2() override;
97 
98  void release() override;
99  void destroy() override;
100  bool isValid() override;
101 
102  WaylandPointer<zxdg_importer_v2, zxdg_importer_v2_destroy> importer;
103  EventQueue *queue = nullptr;
104 };
105 
106 XdgImporterUnstableV2::Private::Private()
107  : XdgImporter::Private()
108 {}
109 
110 zxdg_importer_v2 *XdgImporterUnstableV2::Private::importerV2()
111 {
112  return importer;
113 }
114 
115 void XdgImporterUnstableV2::Private::release()
116 {
117  importer.release();
118 }
119 
120 void XdgImporterUnstableV2::Private::destroy()
121 {
122  importer.destroy();
123 }
124 
125 bool XdgImporterUnstableV2::Private::isValid()
126 {
127  return importer.isValid();
128 }
129 
130 XdgImported *XdgImporterUnstableV2::Private::importTopLevelV2(const QString & handle, QObject *parent)
131 {
132  Q_ASSERT(isValid());
133  auto p = new XdgImportedUnstableV2(parent);
134  auto w = zxdg_importer_v2_import_toplevel(importer, handle.toUtf8());
135  if (queue) {
136  queue->addProxy(w);
137  }
138  p->setup(w);
139  return p;
140 }
141 
142 
144  : XdgImporter(new Private, parent)
145 {
146 }
147 
148 void XdgImporterUnstableV2::Private::setupV2(zxdg_importer_v2 *arg)
149 {
150  Q_ASSERT(arg);
151  Q_ASSERT(!importer);
152  importer.setup(arg);
153 }
154 
155 XdgImporterUnstableV2::~XdgImporterUnstableV2()
156 {
157 }
158 
159 
160 class Q_DECL_HIDDEN XdgExportedUnstableV2::Private : public XdgExported::Private
161 {
162 public:
163  Private(XdgExportedUnstableV2 *q);
164 
165  void setupV2(zxdg_exported_v2 *arg) override;
166  zxdg_exported_v2 *exportedV2() override;
167 
168  void release() override;
169  void destroy() override;
170  bool isValid() override;
171 
172  WaylandPointer<zxdg_exported_v2, zxdg_exported_v2_destroy> exported;
173 
174 private:
175  static void handleCallback(void *data, zxdg_exported_v2 *zxdg_exported_v2, const char * handle);
176 
177  static const zxdg_exported_v2_listener s_listener;
178 };
179 
180 zxdg_exported_v2 *XdgExportedUnstableV2::Private::exportedV2()
181 {
182  return exported;
183 }
184 
185 void XdgExportedUnstableV2::Private::release()
186 {
187  exported.release();
188 }
189 
190 void XdgExportedUnstableV2::Private::destroy()
191 {
192  exported.destroy();
193 }
194 
195 bool XdgExportedUnstableV2::Private::isValid()
196 {
197  return exported.isValid();
198 }
199 
200 
201 const zxdg_exported_v2_listener XdgExportedUnstableV2::Private::s_listener = {
202  handleCallback
203 };
204 
205 void XdgExportedUnstableV2::Private::handleCallback(void *data, zxdg_exported_v2 *zxdg_exported_v2, const char * handle)
206 {
207  auto p = reinterpret_cast<XdgExportedUnstableV2::Private*>(data);
208  Q_ASSERT(p->exported == zxdg_exported_v2);
209 
210  p->handle = handle;
211  emit p->q->done();
212 }
213 
214 XdgExportedUnstableV2::XdgExportedUnstableV2(QObject *parent)
215  : XdgExported(new Private(this), parent)
216 {
217 }
218 
219 void XdgExportedUnstableV2::Private::setupV2(zxdg_exported_v2 *arg)
220 {
221  Q_ASSERT(arg);
222  Q_ASSERT(!exported);
223  exported.setup(arg);
224  zxdg_exported_v2_add_listener(exported, &s_listener, this);
225 }
226 
227 XdgExportedUnstableV2::Private::Private(XdgExportedUnstableV2 *q)
228  : XdgExported::Private::Private(q)
229 {
230 }
231 
232 XdgExportedUnstableV2::~XdgExportedUnstableV2()
233 {
234 }
235 
236 class Q_DECL_HIDDEN XdgImportedUnstableV2::Private : public XdgImported::Private
237 {
238 public:
239  Private(XdgImportedUnstableV2 *q);
240 
241  void setupV2(zxdg_imported_v2 *arg) override;
242  zxdg_imported_v2 *importedV2() override;
243 
244  void setParentOf(Surface *surface) override;
245  void release() override;
246  void destroy() override;
247  bool isValid() override;
248 
249  WaylandPointer<zxdg_imported_v2, zxdg_imported_v2_destroy> imported;
250 
251 private:
252  static void destroyedCallback(void *data, zxdg_imported_v2 *zxdg_imported_v2);
253 
254  static const zxdg_imported_v2_listener s_listener;
255 };
256 
257 XdgImportedUnstableV2::Private::Private(XdgImportedUnstableV2 *q)
258  : XdgImported::Private::Private(q)
259 {
260 }
261 
262 zxdg_imported_v2 *XdgImportedUnstableV2::Private::importedV2()
263 {
264  return imported;
265 }
266 
267 void XdgImportedUnstableV2::Private::release()
268 {
269  imported.release();
270 }
271 
272 void XdgImportedUnstableV2::Private::destroy()
273 {
274  imported.destroy();
275 }
276 
277 bool XdgImportedUnstableV2::Private::isValid()
278 {
279  return imported.isValid();
280 }
281 
282 void XdgImportedUnstableV2::Private::setParentOf(Surface *surface)
283 {
284  Q_ASSERT(isValid());
285  zxdg_imported_v2_set_parent_of(imported, *surface);
286 }
287 
288 const zxdg_imported_v2_listener XdgImportedUnstableV2::Private::s_listener = {
289  destroyedCallback
290 };
291 
292 void XdgImportedUnstableV2::Private::destroyedCallback(void *data, zxdg_imported_v2 *zxdg_imported_v2)
293 {
294  auto p = reinterpret_cast<XdgImportedUnstableV2::Private*>(data);
295  Q_ASSERT(p->imported == zxdg_imported_v2);
296 
297  p->q->release();
298  emit p->q->importedDestroyed();
299 }
300 
301 
302 
303 XdgImportedUnstableV2::XdgImportedUnstableV2(QObject *parent)
304  : XdgImported(new Private(this), parent)
305 {
306 }
307 
308 void XdgImportedUnstableV2::Private::setupV2(zxdg_imported_v2 *arg)
309 {
310  Q_ASSERT(arg);
311  Q_ASSERT(!imported);
312  imported.setup(arg);
313  zxdg_imported_v2_add_listener(imported, &s_listener, this);
314 }
315 
316 XdgImportedUnstableV2::~XdgImportedUnstableV2()
317 {
318 }
319 
320 
321 }
322 }
323 
Wrapper for the zxdg_exporter_v2 interface.
Definition: xdgforeign.h:53
void destroy()
Destroys the data held by this .
Definition: xdgforeign.cpp:113
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:55
Wrapper for the zxdg_importer_v2 interface.
Definition: xdgforeign.h:153
Wrapper for the wl_surface interface.
Definition: surface.h:44
void release()
Releases the zxdg_exporter_v2 interface.
Definition: xdgforeign.cpp:44
XdgImporterUnstableV2(QObject *parent=nullptr)
Creates a new .
void destroy()
Destroys the data held by this .
Definition: xdgforeign.cpp:49
QObject * parent() const const
void release()
Releases the zxdg_importer_v2 interface.
Definition: xdgforeign.cpp:108
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 14 2020 22:49:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.