9 #include "resource_p.h"
10 #include "surface_interface_p.h"
11 #include "xdgforeign_interface.h"
12 #include "xdgforeign_v2_interface_p.h"
14 #include "wayland-xdg-foreign-unstable-v2-server-protocol.h"
23 class Q_DECL_HIDDEN XdgExporterUnstableV2Interface::Private :
public Global::Private
26 Private(XdgExporterUnstableV2Interface *q, Display *d, XdgForeignInterface *foreignInterface);
28 XdgForeignInterface *foreignInterface;
32 void bind(wl_client *client, uint32_t version, uint32_t
id)
override;
34 static void unbind(wl_resource *resource);
35 static Private *cast(wl_resource *r)
37 return reinterpret_cast<Private *
>(wl_resource_get_user_data(r));
40 static void destroyCallback(wl_client *client, wl_resource *resource);
41 static void exportCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface);
43 XdgExporterUnstableV2Interface *q;
44 static const struct zxdg_exporter_v2_interface s_interface;
45 static const quint32 s_version;
48 const quint32 XdgExporterUnstableV2Interface::Private::s_version = 1;
51 const struct zxdg_exporter_v2_interface XdgExporterUnstableV2Interface::Private::s_interface = {destroyCallback, exportCallback};
54 XdgExporterUnstableV2Interface::XdgExporterUnstableV2Interface(Display *display, XdgForeignInterface *parent)
55 : Global(new Private(this, display, parent), parent)
59 XdgExporterUnstableV2Interface::~XdgExporterUnstableV2Interface()
63 XdgExporterUnstableV2Interface::Private *XdgExporterUnstableV2Interface::d_func()
const
65 return reinterpret_cast<Private *
>(d.data());
68 XdgExportedUnstableV2Interface *XdgExporterUnstableV2Interface::exportedSurface(
const QString &handle)
72 auto it = d->exportedSurfaces.constFind(handle);
73 if (it != d->exportedSurfaces.constEnd()) {
79 void XdgExporterUnstableV2Interface::Private::destroyCallback(wl_client *client, wl_resource *resource)
85 void XdgExporterUnstableV2Interface::Private::exportCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface)
87 auto s = cast(resource);
90 e->create(s->display->getConnection(client), wl_resource_get_version(resource),
id);
93 wl_resource_post_no_memory(resource);
101 connect(e.
data(), &XdgExportedUnstableV2Interface::unbound, s->q, [s, handle]() {
102 s->exportedSurfaces.remove(handle);
103 Q_EMIT s->q->surfaceUnexported(handle);
111 s->exportedSurfaces.remove(handle);
112 Q_EMIT s->q->surfaceUnexported(handle);
115 s->exportedSurfaces[handle] = e;
116 zxdg_exported_v2_send_handle(e->resource(), handle.
toUtf8().
constData());
117 Q_EMIT s->q->surfaceExported(handle, e);
120 XdgExporterUnstableV2Interface::Private::Private(XdgExporterUnstableV2Interface *q, Display *d, XdgForeignInterface *foreignInterface)
121 : Global::Private(d, &zxdg_exporter_v2_interface, s_version)
122 , foreignInterface(foreignInterface)
127 void XdgExporterUnstableV2Interface::Private::bind(wl_client *client, uint32_t version, uint32_t
id)
129 auto c = display->getConnection(client);
130 wl_resource *resource = c->createResource(&zxdg_exporter_v2_interface, qMin(version, s_version),
id);
132 wl_client_post_no_memory(client);
135 wl_resource_set_implementation(resource, &s_interface,
this, unbind);
139 void XdgExporterUnstableV2Interface::Private::unbind(wl_resource *resource)
145 class Q_DECL_HIDDEN XdgImporterUnstableV2Interface::Private :
public Global::Private
148 Private(XdgImporterUnstableV2Interface *q, Display *d, XdgForeignInterface *foreignInterface);
150 XdgForeignInterface *foreignInterface;
160 void bind(wl_client *client, uint32_t version, uint32_t
id)
override;
162 static void unbind(wl_resource *resource);
163 static Private *cast(wl_resource *r)
165 return reinterpret_cast<Private *
>(wl_resource_get_user_data(r));
168 static void destroyCallback(wl_client *client, wl_resource *resource);
169 static void importCallback(wl_client *client, wl_resource *resource, uint32_t
id,
const char *handle);
171 XdgImporterUnstableV2Interface *q;
172 static const struct zxdg_importer_v2_interface s_interface;
173 static const quint32 s_version;
176 const quint32 XdgImporterUnstableV2Interface::Private::s_version = 1;
179 const struct zxdg_importer_v2_interface XdgImporterUnstableV2Interface::Private::s_interface = {destroyCallback, importCallback};
182 XdgImporterUnstableV2Interface::XdgImporterUnstableV2Interface(Display *display, XdgForeignInterface *parent)
183 : Global(new Private(this, display, parent), parent)
187 XdgImporterUnstableV2Interface::~XdgImporterUnstableV2Interface()
191 XdgImportedUnstableV2Interface *XdgImporterUnstableV2Interface::importedSurface(
const QString &handle)
195 auto it = d->importedSurfaces.constFind(handle);
196 if (it != d->importedSurfaces.constEnd()) {
202 SurfaceInterface *XdgImporterUnstableV2Interface::transientFor(SurfaceInterface *surface)
206 auto it = d->parents.constFind(surface);
207 if (it == d->parents.constEnd()) {
213 XdgImporterUnstableV2Interface::Private *XdgImporterUnstableV2Interface::d_func()
const
215 return reinterpret_cast<Private *
>(d.data());
218 void XdgImporterUnstableV2Interface::Private::destroyCallback(wl_client *client, wl_resource *resource)
224 void XdgImporterUnstableV2Interface::Private::importCallback(wl_client *client, wl_resource *resource, uint32_t
id,
const char *h)
226 auto s = cast(resource);
228 Q_ASSERT(s->foreignInterface);
231 XdgExportedUnstableV2Interface *exp = s->foreignInterface->d->exporter->exportedSurface(handle);
233 zxdg_imported_v2_send_destroyed(resource);
237 wl_resource *surface = exp->parentResource();
239 zxdg_imported_v2_send_destroyed(resource);
244 imp->create(s->display->getConnection(client), wl_resource_get_version(resource),
id);
247 connect(exp, &XdgExportedUnstableV2Interface::unbound, s->q, [s, imp, handle]() {
250 zxdg_imported_v2_send_destroyed(imp->resource());
253 s->importedSurfaces.remove(handle);
254 Q_EMIT s->q->surfaceUnimported(handle);
257 connect(imp.
data(), &XdgImportedUnstableV2Interface::childChanged, s->q, [s, imp](SurfaceInterface *child) {
259 auto it = s->children.find(imp);
260 if (it != s->children.end()) {
261 s->parents.remove(*it);
262 s->children.erase(it);
265 s->parents[child] = imp;
266 s->children[imp] = child;
268 Q_EMIT s->q->transientChanged(child, parent);
271 connect(child, &Resource::unbound, s->q, [s, child]() {
272 auto it = s->parents.find(child);
273 if (it != s->parents.end()) {
274 KWayland::Server::XdgImportedUnstableV2Interface *parent = *it;
275 s->children.remove(*it);
276 s->parents.erase(it);
277 Q_EMIT s->q->transientChanged(nullptr, SurfaceInterface::get(parent->parentResource()));
283 connect(imp.
data(), &XdgImportedUnstableV2Interface::unbound, s->q, [s, handle, imp]() {
284 s->importedSurfaces.remove(handle);
285 Q_EMIT s->q->surfaceUnimported(handle);
287 auto it = s->children.find(imp);
288 if (it != s->children.end()) {
289 KWayland::Server::SurfaceInterface *child = *it;
290 s->parents.remove(*it);
291 s->children.erase(it);
292 Q_EMIT s->q->transientChanged(child, nullptr);
296 if (!imp->resource()) {
297 wl_resource_post_no_memory(resource);
302 s->importedSurfaces[handle] = imp;
303 Q_EMIT s->q->surfaceImported(handle, imp);
306 XdgImporterUnstableV2Interface::Private::Private(XdgImporterUnstableV2Interface *q, Display *d, XdgForeignInterface *foreignInterface)
307 : Global::Private(d, &zxdg_importer_v2_interface, s_version)
308 , foreignInterface(foreignInterface)
313 void XdgImporterUnstableV2Interface::Private::bind(wl_client *client, uint32_t version, uint32_t
id)
315 auto c = display->getConnection(client);
316 wl_resource *resource = c->createResource(&zxdg_importer_v2_interface, qMin(version, s_version),
id);
318 wl_client_post_no_memory(client);
321 wl_resource_set_implementation(resource, &s_interface,
this, unbind);
325 void XdgImporterUnstableV2Interface::Private::unbind(wl_resource *resource)
331 class Q_DECL_HIDDEN XdgExportedUnstableV2Interface::Private :
public Resource::Private
334 Private(XdgExportedUnstableV2Interface *q, XdgExporterUnstableV2Interface *c, wl_resource *parentResource);
338 XdgExportedUnstableV2Interface *q_func()
340 return reinterpret_cast<XdgExportedUnstableV2Interface *
>(q);
343 static const struct zxdg_exported_v2_interface s_interface;
347 const struct zxdg_exported_v2_interface XdgExportedUnstableV2Interface::Private::s_interface = {resourceDestroyedCallback};
350 XdgExportedUnstableV2Interface::XdgExportedUnstableV2Interface(XdgExporterUnstableV2Interface *parent, wl_resource *parentResource)
351 :
Resource(new Private(this, parent, parentResource))
355 XdgExportedUnstableV2Interface::~XdgExportedUnstableV2Interface()
359 XdgExportedUnstableV2Interface::Private *XdgExportedUnstableV2Interface::d_func()
const
361 return reinterpret_cast<Private *
>(d.data());
364 XdgExportedUnstableV2Interface::Private::Private(XdgExportedUnstableV2Interface *q, XdgExporterUnstableV2Interface *c, wl_resource *parentResource)
365 :
Resource::Private(q, c, parentResource, &zxdg_exported_v2_interface, &s_interface)
369 XdgExportedUnstableV2Interface::Private::~Private()
373 class Q_DECL_HIDDEN XdgImportedUnstableV2Interface::Private :
public Resource::Private
376 Private(XdgImportedUnstableV2Interface *q, XdgImporterUnstableV2Interface *c, wl_resource *parentResource);
382 static void setParentOfCallback(wl_client *client, wl_resource *resource, wl_resource *surface);
384 XdgImportedUnstableV2Interface *q_func()
386 return reinterpret_cast<XdgImportedUnstableV2Interface *
>(q);
389 static const struct zxdg_imported_v2_interface s_interface;
393 const struct zxdg_imported_v2_interface XdgImportedUnstableV2Interface::Private::s_interface = {resourceDestroyedCallback, setParentOfCallback};
396 XdgImportedUnstableV2Interface::XdgImportedUnstableV2Interface(XdgImporterUnstableV2Interface *parent, wl_resource *parentResource)
397 :
Resource(new Private(this, parent, parentResource))
401 XdgImportedUnstableV2Interface::~XdgImportedUnstableV2Interface()
405 XdgImportedUnstableV2Interface::Private *XdgImportedUnstableV2Interface::d_func()
const
407 return reinterpret_cast<Private *
>(d.data());
410 SurfaceInterface *XdgImportedUnstableV2Interface::child()
const
413 return d->parentOf.data();
416 void XdgImportedUnstableV2Interface::Private::setParentOfCallback(wl_client *client, wl_resource *resource, wl_resource *surface)
420 auto s = cast<Private>(resource);
428 Q_EMIT s->q_func()->childChanged(surf);
431 XdgImportedUnstableV2Interface::Private::Private(XdgImportedUnstableV2Interface *q, XdgImporterUnstableV2Interface *c, wl_resource *parentResource)
432 :
Resource::Private(q, c, parentResource, &zxdg_imported_v2_interface, &s_interface)
436 XdgImportedUnstableV2Interface::Private::~Private()