KWayland

blur_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Martin Gräßlin <[email protected]>
3  SPDX-FileCopyrightText: 2015 Marco Martin <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 #include "blur_interface.h"
8 #include "display.h"
9 #include "global_p.h"
10 #include "region_interface.h"
11 #include "resource_p.h"
12 #include "surface_interface_p.h"
13 
14 #include <wayland-blur-server-protocol.h>
15 #include <wayland-server.h>
16 
17 namespace KWayland
18 {
19 namespace Server
20 {
21 class BlurManagerInterface::Private : public Global::Private
22 {
23 public:
24  Private(BlurManagerInterface *q, Display *d);
25 
26 private:
27  void bind(wl_client *client, uint32_t version, uint32_t id) override;
28  void createBlur(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface);
29 
30  static void createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface);
31  static void unsetCallback(wl_client *client, wl_resource *resource, wl_resource *surface);
32  static void unbind(wl_resource *resource);
33  static Private *cast(wl_resource *r)
34  {
35  auto blurManager = reinterpret_cast<QPointer<BlurManagerInterface> *>(wl_resource_get_user_data(r))->data();
36  if (blurManager) {
37  return static_cast<Private *>(blurManager->d.data());
38  }
39  return nullptr;
40  }
41  BlurManagerInterface *q;
42  static const struct org_kde_kwin_blur_manager_interface s_interface;
43  static const quint32 s_version;
44 };
45 
46 const quint32 BlurManagerInterface::Private::s_version = 1;
47 
48 #ifndef K_DOXYGEN
49 const struct org_kde_kwin_blur_manager_interface BlurManagerInterface::Private::s_interface = {createCallback, unsetCallback};
50 #endif
51 
52 BlurManagerInterface::Private::Private(BlurManagerInterface *q, Display *d)
53  : Global::Private(d, &org_kde_kwin_blur_manager_interface, s_version)
54  , q(q)
55 {
56 }
57 
58 void BlurManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
59 {
60  auto c = display->getConnection(client);
61  wl_resource *resource = c->createResource(&org_kde_kwin_blur_manager_interface, qMin(version, s_version), id);
62  if (!resource) {
63  wl_client_post_no_memory(client);
64  return;
65  }
66  auto ref = new QPointer<BlurManagerInterface>(q); // deleted in unbind
67  wl_resource_set_implementation(resource, &s_interface, ref, unbind);
68 }
69 
70 void BlurManagerInterface::Private::unbind(wl_resource *r)
71 {
72  delete reinterpret_cast<QPointer<BlurManagerInterface> *>(wl_resource_get_user_data(r));
73 }
74 
75 void BlurManagerInterface::Private::createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
76 {
77  auto m = cast(resource);
78  if (!m) {
79  return; // will happen if global is deleted
80  }
81  m->createBlur(client, resource, id, surface);
82 }
83 
84 void BlurManagerInterface::Private::createBlur(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
85 {
86  SurfaceInterface *s = SurfaceInterface::get(surface);
87  if (!s) {
88  return;
89  }
90 
91  BlurInterface *blur = new BlurInterface(q, resource);
92  blur->create(display->getConnection(client), wl_resource_get_version(resource), id);
93  if (!blur->resource()) {
94  wl_resource_post_no_memory(resource);
95  delete blur;
96  return;
97  }
98  s->d_func()->setBlur(QPointer<BlurInterface>(blur));
99 }
100 
101 void BlurManagerInterface::Private::unsetCallback(wl_client *client, wl_resource *resource, wl_resource *surface)
102 {
103  Q_UNUSED(client)
104  Q_UNUSED(resource)
105  SurfaceInterface *s = SurfaceInterface::get(surface);
106  if (!s) {
107  return;
108  }
109  s->d_func()->setBlur(QPointer<BlurInterface>());
110 }
111 
112 BlurManagerInterface::BlurManagerInterface(Display *display, QObject *parent)
113  : Global(new Private(this, display), parent)
114 {
115 }
116 
117 BlurManagerInterface::~BlurManagerInterface() = default;
118 
119 class BlurInterface::Private : public Resource::Private
120 {
121 public:
122  Private(BlurInterface *q, BlurManagerInterface *c, wl_resource *parentResource);
123  ~Private();
124 
125  QRegion pendingRegion;
126  QRegion currentRegion;
127 
128 private:
129  void commit();
130  // TODO
131  BlurInterface *q_func()
132  {
133  return reinterpret_cast<BlurInterface *>(q);
134  }
135 
136  static void commitCallback(wl_client *client, wl_resource *resource);
137  static void setRegionCallback(wl_client *client, wl_resource *resource, wl_resource *region);
138 
139  static const struct org_kde_kwin_blur_interface s_interface;
140 };
141 
142 #ifndef K_DOXYGEN
143 const struct org_kde_kwin_blur_interface BlurInterface::Private::s_interface = {commitCallback, setRegionCallback, resourceDestroyedCallback};
144 #endif
145 
146 void BlurInterface::Private::commitCallback(wl_client *client, wl_resource *resource)
147 {
148  Q_UNUSED(client)
149  cast<Private>(resource)->commit();
150 }
151 
152 void BlurInterface::Private::commit()
153 {
154  currentRegion = pendingRegion;
155 }
156 
157 void BlurInterface::Private::setRegionCallback(wl_client *client, wl_resource *resource, wl_resource *region)
158 {
159  Q_UNUSED(client)
160  Private *p = cast<Private>(resource);
161  RegionInterface *r = RegionInterface::get(region);
162  if (r) {
163  p->pendingRegion = r->region();
164  } else {
165  p->pendingRegion = QRegion();
166  }
167 }
168 
169 BlurInterface::Private::Private(BlurInterface *q, BlurManagerInterface *c, wl_resource *parentResource)
170  : Resource::Private(q, c, parentResource, &org_kde_kwin_blur_interface, &s_interface)
171 {
172 }
173 
174 BlurInterface::Private::~Private() = default;
175 
176 BlurInterface::BlurInterface(BlurManagerInterface *parent, wl_resource *parentResource)
177  : Resource(new Private(this, parent, parentResource))
178 {
179 }
180 
181 BlurInterface::~BlurInterface() = default;
182 
183 QRegion BlurInterface::region()
184 {
185  Q_D();
186  return d->currentRegion;
187 }
188 
189 BlurInterface::Private *BlurInterface::d_func() const
190 {
191  return reinterpret_cast<Private *>(d.data());
192 }
193 
194 }
195 }
void ref()
T * data() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Sep 25 2021 22:51:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.