KWaylandServer

blur_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Martin Gräßlin <[email protected]>
3  SPDX-FileCopyrightText: 2015 Marco Martin <[email protected]>
4  SPDX-FileCopyrightText: 2020 David Edmundson <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8 #include "blur_interface.h"
9 #include "display.h"
10 #include "region_interface_p.h"
11 #include "surface_interface_p.h"
12 
13 #include "qwayland-server-blur.h"
14 
15 namespace KWaylandServer
16 {
17 static const quint32 s_version = 1;
18 
19 class BlurManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_blur_manager
20 {
21 public:
22  BlurManagerInterfacePrivate(BlurManagerInterface *q, Display *d);
23 
24  BlurManagerInterface *q;
25 
26 protected:
27  void org_kde_kwin_blur_manager_destroy_global() override;
28  void org_kde_kwin_blur_manager_create(Resource *resource, uint32_t id, wl_resource *surface) override;
29  void org_kde_kwin_blur_manager_unset(Resource *resource, wl_resource *surface) override;
30 };
31 
32 BlurManagerInterfacePrivate::BlurManagerInterfacePrivate(BlurManagerInterface *_q, Display *d)
33  : QtWaylandServer::org_kde_kwin_blur_manager(*d, s_version)
34  , q(_q)
35 {
36 }
37 
38 void BlurManagerInterfacePrivate::org_kde_kwin_blur_manager_destroy_global()
39 {
40  delete q;
41 }
42 
43 void BlurManagerInterfacePrivate::org_kde_kwin_blur_manager_unset(Resource *resource, wl_resource *surface)
44 {
45  Q_UNUSED(resource);
46  SurfaceInterface *s = SurfaceInterface::get(surface);
47  if (!s) {
48  return;
49  }
50  SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
51  surfacePrivate->setBlur(QPointer<BlurInterface>());
52 }
53 
54 void BlurManagerInterfacePrivate::org_kde_kwin_blur_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
55 {
56  SurfaceInterface *s = SurfaceInterface::get(surface);
57  if (!s) {
58  wl_resource_post_error(resource->handle, 0, "Invalid surface");
59  return;
60  }
61  wl_resource *blur_resource = wl_resource_create(resource->client(), &org_kde_kwin_blur_interface, resource->version(), id);
62  if (!blur_resource) {
63  wl_client_post_no_memory(resource->client());
64  return;
65  }
66  auto blur = new BlurInterface(blur_resource);
67  SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
68  surfacePrivate->setBlur(blur);
69 }
70 
71 BlurManagerInterface::BlurManagerInterface(Display *display, QObject *parent)
72  : QObject(parent)
73  , d(new BlurManagerInterfacePrivate(this, display))
74 {
75 }
76 
77 BlurManagerInterface::~BlurManagerInterface()
78 {
79 }
80 
81 void BlurManagerInterface::remove()
82 {
83  d->globalRemove();
84 }
85 
86 class BlurInterfacePrivate : public QtWaylandServer::org_kde_kwin_blur
87 {
88 public:
89  BlurInterfacePrivate(BlurInterface *q, wl_resource *resource);
90  QRegion pendingRegion;
91  QRegion currentRegion;
92 
93  BlurInterface *q;
94 
95 protected:
96  void org_kde_kwin_blur_destroy_resource(Resource *resource) override;
97  void org_kde_kwin_blur_commit(Resource *resource) override;
98  void org_kde_kwin_blur_set_region(Resource *resource, wl_resource *region) override;
99  void org_kde_kwin_blur_release(Resource *resource) override;
100 };
101 
102 void BlurInterfacePrivate::org_kde_kwin_blur_commit(Resource *resource)
103 {
104  Q_UNUSED(resource)
105  currentRegion = pendingRegion;
106 }
107 
108 void BlurInterfacePrivate::org_kde_kwin_blur_set_region(Resource *resource, wl_resource *region)
109 {
110  Q_UNUSED(resource)
111  RegionInterface *r = RegionInterface::get(region);
112  if (r) {
113  pendingRegion = r->region();
114  } else {
115  pendingRegion = QRegion();
116  }
117 }
118 
119 void BlurInterfacePrivate::org_kde_kwin_blur_release(Resource *resource)
120 {
121  wl_resource_destroy(resource->handle);
122 }
123 
124 void BlurInterfacePrivate::org_kde_kwin_blur_destroy_resource(Resource *resource)
125 {
126  Q_UNUSED(resource)
127  delete q;
128 }
129 
130 BlurInterfacePrivate::BlurInterfacePrivate(BlurInterface *_q, wl_resource *resource)
131  : QtWaylandServer::org_kde_kwin_blur(resource)
132  , q(_q)
133 {
134 }
135 
136 BlurInterface::BlurInterface(wl_resource *resource)
137  : QObject()
138  , d(new BlurInterfacePrivate(this, resource))
139 {
140 }
141 
142 BlurInterface::~BlurInterface() = default;
143 
145 {
146  return d->currentRegion;
147 }
148 
149 }
static SurfaceInterface * get(wl_resource *native)
SurfaceInterface * surface() const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:08:27 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.