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

source code of kwayland/src/client/xdgforeign_v2.cpp