KWayland

compositor_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 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 "compositor_interface.h"
7 #include "display.h"
8 #include "global_p.h"
9 // Wayland
10 #include <wayland-server.h>
11 
12 namespace KWayland
13 {
14 namespace Server
15 {
16 class CompositorInterface::Private : public Global::Private
17 {
18 public:
19  Private(CompositorInterface *q, Display *d);
20 
21 private:
22  void bind(wl_client *client, uint32_t version, uint32_t id) override;
23  void createSurface(wl_client *client, wl_resource *resource, uint32_t id);
24  void createRegion(wl_client *client, wl_resource *resource, uint32_t id);
25 
26  static void unbind(wl_resource *resource);
27  static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id);
28  static void createRegionCallback(wl_client *client, wl_resource *resource, uint32_t id);
29  static Private *cast(wl_resource *r)
30  {
31  return reinterpret_cast<Private *>(wl_resource_get_user_data(r));
32  }
33 
34  CompositorInterface *q;
35  static const struct wl_compositor_interface s_interface;
36  static const quint32 s_version;
37 };
38 
39 const quint32 CompositorInterface::Private::s_version = 4;
40 
41 CompositorInterface::Private::Private(CompositorInterface *q, Display *d)
42  : Global::Private(d, &wl_compositor_interface, s_version)
43  , q(q)
44 {
45 }
46 
47 #ifndef K_DOXYGEN
48 const struct wl_compositor_interface CompositorInterface::Private::s_interface = {createSurfaceCallback, createRegionCallback};
49 #endif
50 
51 CompositorInterface::CompositorInterface(Display *display, QObject *parent)
52  : Global(new Private(this, display), parent)
53 {
54 }
55 
56 CompositorInterface::~CompositorInterface() = default;
57 
58 void CompositorInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
59 {
60  auto c = display->getConnection(client);
61  wl_resource *resource = c->createResource(&wl_compositor_interface, qMin(version, s_version), id);
62  if (!resource) {
63  wl_client_post_no_memory(client);
64  return;
65  }
66  wl_resource_set_implementation(resource, &s_interface, this, unbind);
67  // TODO: should we track?
68 }
69 
70 void CompositorInterface::Private::unbind(wl_resource *resource)
71 {
72  Q_UNUSED(resource)
73  // TODO: implement?
74 }
75 
76 void CompositorInterface::Private::createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id)
77 {
78  cast(resource)->createSurface(client, resource, id);
79 }
80 
81 void CompositorInterface::Private::createSurface(wl_client *client, wl_resource *resource, uint32_t id)
82 {
83  SurfaceInterface *surface = new SurfaceInterface(q, resource);
84  surface->create(display->getConnection(client), wl_resource_get_version(resource), id);
85  if (!surface->resource()) {
86  wl_resource_post_no_memory(resource);
87  delete surface;
88  return;
89  }
90  Q_EMIT q->surfaceCreated(surface);
91 }
92 
93 void CompositorInterface::Private::createRegionCallback(wl_client *client, wl_resource *resource, uint32_t id)
94 {
95  cast(resource)->createRegion(client, resource, id);
96 }
97 
98 void CompositorInterface::Private::createRegion(wl_client *client, wl_resource *resource, uint32_t id)
99 {
100  RegionInterface *region = new RegionInterface(q, resource);
101  region->create(display->getConnection(client), wl_resource_get_version(resource), id);
102  if (!region->resource()) {
103  wl_resource_post_no_memory(resource);
104  delete region;
105  return;
106  }
107  Q_EMIT q->regionCreated(region);
108 }
109 
110 }
111 }
QObject * parent() const const
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Jun 20 2021 22:50:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.