KWaylandServer

contrast_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 "contrast_interface.h"
8 #include "display.h"
9 #include "region_interface_p.h"
10 #include "surface_interface_p.h"
11 
12 #include <qwayland-server-contrast.h>
13 
14 namespace KWaylandServer
15 {
16 static const quint32 s_version = 2;
17 
18 class ContrastManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_contrast_manager
19 {
20 public:
21  ContrastManagerInterfacePrivate(ContrastManagerInterface *q, Display *display);
22 
23  ContrastManagerInterface *q;
24 
25 protected:
26  void org_kde_kwin_contrast_manager_destroy_global() override;
27  void org_kde_kwin_contrast_manager_create(Resource *resource, uint32_t id, wl_resource *surface) override;
28  void org_kde_kwin_contrast_manager_unset(Resource *resource, wl_resource *surface) override;
29 };
30 
31 ContrastManagerInterfacePrivate::ContrastManagerInterfacePrivate(ContrastManagerInterface *q, Display *display)
32  : QtWaylandServer::org_kde_kwin_contrast_manager(*display, s_version)
33  , q(q)
34 {
35 }
36 
37 void ContrastManagerInterfacePrivate::org_kde_kwin_contrast_manager_destroy_global()
38 {
39  delete q;
40 }
41 
42 void ContrastManagerInterfacePrivate::org_kde_kwin_contrast_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
43 {
44  SurfaceInterface *s = SurfaceInterface::get(surface);
45  if (!s) {
46  wl_resource_post_error(resource->handle, 0, "Invalid surface");
47  return;
48  }
49 
50  wl_resource *contrast_resource = wl_resource_create(resource->client(), &org_kde_kwin_contrast_interface, resource->version(), id);
51  if (!contrast_resource) {
52  wl_client_post_no_memory(resource->client());
53  return;
54  }
55  auto contrast = new ContrastInterface(contrast_resource);
56  SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
57  surfacePrivate->setContrast(contrast);
58 }
59 
60 void ContrastManagerInterfacePrivate::org_kde_kwin_contrast_manager_unset(Resource *resource, wl_resource *surface)
61 {
62  SurfaceInterface *s = SurfaceInterface::get(surface);
63  if (!s) {
64  wl_resource_post_error(resource->handle, 0, "Invalid surface");
65  return;
66  }
67  SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
68  surfacePrivate->setContrast(QPointer<ContrastInterface>());
69 }
70 
71 ContrastManagerInterface::ContrastManagerInterface(Display *display, QObject *parent)
72  : QObject(parent)
73  , d(new ContrastManagerInterfacePrivate(this, display))
74 {
75 }
76 
77 ContrastManagerInterface::~ContrastManagerInterface()
78 {
79 }
80 
81 void ContrastManagerInterface::remove()
82 {
83  d->globalRemove();
84 }
85 
86 class ContrastInterfacePrivate : public QtWaylandServer::org_kde_kwin_contrast
87 {
88 public:
89  ContrastInterfacePrivate(ContrastInterface *_q, wl_resource *resource);
90 
91  QRegion pendingRegion;
92  QRegion currentRegion;
93  qreal pendingContrast;
94  qreal currentContrast;
95  qreal pendingIntensity;
96  qreal currentIntensity;
97  qreal pendingSaturation;
98  qreal currentSaturation;
99  QColor currentFrost;
100  QColor pendingFrost;
101  ContrastInterface *q;
102 
103 protected:
104  void org_kde_kwin_contrast_commit(Resource *resource) override;
105  void org_kde_kwin_contrast_set_region(Resource *resource, wl_resource *region) override;
106  void org_kde_kwin_contrast_set_contrast(Resource *resource, wl_fixed_t contrast) override;
107  void org_kde_kwin_contrast_set_intensity(Resource *resource, wl_fixed_t intensity) override;
108  void org_kde_kwin_contrast_set_saturation(Resource *resource, wl_fixed_t saturation) override;
109  void org_kde_kwin_contrast_set_frost(Resource *resource, int r, int g, int b, int a) override;
110  void org_kde_kwin_contrast_unset_frost(Resource *resource) override;
111  void org_kde_kwin_contrast_release(Resource *resource) override;
112  void org_kde_kwin_contrast_destroy_resource(Resource *resource) override;
113 };
114 
115 void ContrastInterfacePrivate::org_kde_kwin_contrast_commit(Resource *resource)
116 {
117  Q_UNUSED(resource)
118  currentRegion = pendingRegion;
119  currentContrast = pendingContrast;
120  currentIntensity = pendingIntensity;
121  currentSaturation = pendingSaturation;
122  currentFrost = pendingFrost;
123 }
124 
125 void ContrastInterfacePrivate::org_kde_kwin_contrast_set_region(Resource *resource, wl_resource *region)
126 {
127  Q_UNUSED(resource)
128  RegionInterface *r = RegionInterface::get(region);
129  if (r) {
130  pendingRegion = r->region();
131  } else {
132  pendingRegion = QRegion();
133  }
134 }
135 
136 void ContrastInterfacePrivate::org_kde_kwin_contrast_set_contrast(Resource *resource, wl_fixed_t contrast)
137 {
138  Q_UNUSED(resource)
139  pendingContrast = wl_fixed_to_double(contrast);
140 }
141 
142 void ContrastInterfacePrivate::org_kde_kwin_contrast_set_intensity(Resource *resource, wl_fixed_t intensity)
143 {
144  Q_UNUSED(resource)
145  pendingIntensity = wl_fixed_to_double(intensity);
146 }
147 
148 void ContrastInterfacePrivate::org_kde_kwin_contrast_set_saturation(Resource *resource, wl_fixed_t saturation)
149 {
150  Q_UNUSED(resource)
151  pendingSaturation = wl_fixed_to_double(saturation);
152 }
153 
154 void ContrastInterfacePrivate::org_kde_kwin_contrast_set_frost(Resource *resource, int r, int g, int b, int a)
155 {
156  Q_UNUSED(resource)
157 
158  pendingFrost = QColor(r, g, b, a);
159 }
160 
161 void ContrastInterfacePrivate::org_kde_kwin_contrast_unset_frost(Resource *resource)
162 {
163  Q_UNUSED(resource)
164 
165  pendingFrost = {};
166 }
167 
168 void ContrastInterfacePrivate::org_kde_kwin_contrast_release(Resource *resource)
169 {
170  wl_resource_destroy(resource->handle);
171 }
172 
173 void ContrastInterfacePrivate::org_kde_kwin_contrast_destroy_resource(Resource *resource)
174 {
175  Q_UNUSED(resource)
176  delete q;
177 }
178 
179 ContrastInterfacePrivate::ContrastInterfacePrivate(ContrastInterface *_q, wl_resource *resource)
180  : QtWaylandServer::org_kde_kwin_contrast(resource)
181  , q(_q)
182 {
183 }
184 
185 ContrastInterface::ContrastInterface(wl_resource *resource)
186  : QObject()
187  , d(new ContrastInterfacePrivate(this, resource))
188 {
189 }
190 
191 ContrastInterface::~ContrastInterface() = default;
192 
193 QRegion ContrastInterface::region() const
194 {
195  return d->currentRegion;
196 }
197 
198 qreal ContrastInterface::contrast() const
199 {
200  return d->currentContrast;
201 }
202 
203 qreal ContrastInterface::intensity() const
204 {
205  return d->currentIntensity;
206 }
207 
208 qreal ContrastInterface::saturation() const
209 {
210  return d->currentSaturation;
211 }
212 
213 QColor ContrastInterface::frost() const
214 {
215  return d->currentFrost;
216 }
217 
218 }
static SurfaceInterface * get(wl_resource *native)
Display * display() const
Returns the Display object for this CompositorInterface.
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:08:43 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.