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

KDE's Doxygen guidelines are available online.