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

KDE's Doxygen guidelines are available online.