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 
17 class CompositorInterface::Private : public Global::Private
18 {
19 public:
20  Private(CompositorInterface *q, Display *d);
21 
22 private:
23  void bind(wl_client *client, uint32_t version, uint32_t id) override;
24  void createSurface(wl_client *client, wl_resource *resource, uint32_t id);
25  void createRegion(wl_client *client, wl_resource *resource, uint32_t id);
26 
27  static void unbind(wl_resource *resource);
28  static void createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id);
29  static void createRegionCallback(wl_client *client, wl_resource *resource, uint32_t id);
30  static Private *cast(wl_resource *r) {
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 = {
49  createSurfaceCallback,
50  createRegionCallback
51 };
52 #endif
53 
54 CompositorInterface::CompositorInterface(Display *display, QObject *parent)
55  : Global(new Private(this, display), parent)
56 {
57 }
58 
59 CompositorInterface::~CompositorInterface() = default;
60 
61 void CompositorInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
62 {
63  auto c = display->getConnection(client);
64  wl_resource *resource = c->createResource(&wl_compositor_interface, qMin(version, s_version), id);
65  if (!resource) {
66  wl_client_post_no_memory(client);
67  return;
68  }
69  wl_resource_set_implementation(resource, &s_interface, this, unbind);
70  // TODO: should we track?
71 }
72 
73 void CompositorInterface::Private::unbind(wl_resource *resource)
74 {
75  Q_UNUSED(resource)
76  // TODO: implement?
77 }
78 
79 void CompositorInterface::Private::createSurfaceCallback(wl_client *client, wl_resource *resource, uint32_t id)
80 {
81  cast(resource)->createSurface(client, resource, id);
82 }
83 
84 void CompositorInterface::Private::createSurface(wl_client *client, wl_resource *resource, uint32_t id)
85 {
86  SurfaceInterface *surface = new SurfaceInterface(q, resource);
87  surface->create(display->getConnection(client), wl_resource_get_version(resource), id);
88  if (!surface->resource()) {
89  wl_resource_post_no_memory(resource);
90  delete surface;
91  return;
92  }
93  Q_EMIT q->surfaceCreated(surface);
94 }
95 
96 void CompositorInterface::Private::createRegionCallback(wl_client *client, wl_resource *resource, uint32_t id)
97 {
98  cast(resource)->createRegion(client, resource, id);
99 }
100 
101 void CompositorInterface::Private::createRegion(wl_client *client, wl_resource *resource, uint32_t id)
102 {
103  RegionInterface *region = new RegionInterface(q, resource);
104  region->create(display->getConnection(client), wl_resource_get_version(resource), id);
105  if (!region->resource()) {
106  wl_resource_post_no_memory(resource);
107  delete region;
108  return;
109  }
110  Q_EMIT q->regionCreated(region);
111 }
112 
113 }
114 }
QObject * parent() const const
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Mar 8 2021 22:50:06 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.