KWayland

contrast.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.h"
8 #include "event_queue.h"
9 #include "region.h"
10 #include "surface.h"
11 #include "wayland_pointer_p.h"
12 
13 #include <wayland-contrast-client-protocol.h>
14 
15 namespace KWayland
16 {
17 namespace Client
18 {
19 class Q_DECL_HIDDEN ContrastManager::Private
20 {
21 public:
22  Private() = default;
23 
24  WaylandPointer<org_kde_kwin_contrast_manager, org_kde_kwin_contrast_manager_destroy> manager;
25  EventQueue *queue = nullptr;
26 };
27 
29  : QObject(parent)
30  , d(new Private)
31 {
32 }
33 
34 ContrastManager::~ContrastManager()
35 {
36  release();
37 }
38 
40 {
41  d->manager.release();
42 }
43 
45 {
46  d->manager.destroy();
47 }
48 
50 {
51  return d->manager.isValid();
52 }
53 
54 void ContrastManager::setup(org_kde_kwin_contrast_manager *manager)
55 {
56  Q_ASSERT(manager);
57  Q_ASSERT(!d->manager);
58  d->manager.setup(manager);
59 }
60 
62 {
63  d->queue = queue;
64 }
65 
67 {
68  return d->queue;
69 }
70 
72 {
73  Q_ASSERT(isValid());
74  Contrast *s = new Contrast(parent);
75  auto w = org_kde_kwin_contrast_manager_create(d->manager, *surface);
76  if (d->queue) {
77  d->queue->addProxy(w);
78  }
79  s->setup(w);
80  return s;
81 }
82 
83 void ContrastManager::removeContrast(Surface *surface)
84 {
85  Q_ASSERT(isValid());
86  org_kde_kwin_contrast_manager_unset(d->manager, *surface);
87 }
88 
89 ContrastManager::operator org_kde_kwin_contrast_manager *()
90 {
91  return d->manager;
92 }
93 
94 ContrastManager::operator org_kde_kwin_contrast_manager *() const
95 {
96  return d->manager;
97 }
98 
99 class Contrast::Private
100 {
101 public:
102  WaylandPointer<org_kde_kwin_contrast, org_kde_kwin_contrast_release> contrast;
103 };
104 
105 Contrast::Contrast(QObject *parent)
106  : QObject(parent)
107  , d(new Private)
108 {
109 }
110 
111 Contrast::~Contrast()
112 {
113  release();
114 }
115 
117 {
118  d->contrast.release();
119 }
120 
121 void Contrast::setup(org_kde_kwin_contrast *contrast)
122 {
123  Q_ASSERT(contrast);
124  Q_ASSERT(!d->contrast);
125  d->contrast.setup(contrast);
126 }
127 
129 {
130  d->contrast.destroy();
131 }
132 
133 bool Contrast::isValid() const
134 {
135  return d->contrast.isValid();
136 }
137 
138 void Contrast::commit()
139 {
140  Q_ASSERT(isValid());
141  org_kde_kwin_contrast_commit(d->contrast);
142 }
143 
145 {
146  org_kde_kwin_contrast_set_region(d->contrast, *region);
147 }
148 
149 void Contrast::setContrast(qreal contrast)
150 {
151  org_kde_kwin_contrast_set_contrast(d->contrast, wl_fixed_from_double(contrast));
152 }
153 
154 void Contrast::setIntensity(qreal intensity)
155 {
156  org_kde_kwin_contrast_set_intensity(d->contrast, wl_fixed_from_double(intensity));
157 }
158 
159 void Contrast::setSaturation(qreal saturation)
160 {
161  org_kde_kwin_contrast_set_saturation(d->contrast, wl_fixed_from_double(saturation));
162 }
163 
164 void Contrast::setFrost(QColor frost)
165 {
166  if (org_kde_kwin_contrast_get_version(d->contrast) < ORG_KDE_KWIN_CONTRAST_SET_FROST_SINCE_VERSION) {
167  return;
168  }
169 
170  if (frost.isValid()) {
171  org_kde_kwin_contrast_set_frost(d->contrast, frost.red(), frost.green(), frost.blue(), frost.alpha());
172  } else {
173  org_kde_kwin_contrast_unset_frost(d->contrast);
174  }
175 }
176 
177 Contrast::operator org_kde_kwin_contrast *()
178 {
179  return d->contrast;
180 }
181 
182 Contrast::operator org_kde_kwin_contrast *() const
183 {
184  return d->contrast;
185 }
186 
187 }
188 }
void destroy()
Destroys the data held by this Contrast.
Definition: contrast.cpp:128
Wrapper for the org_kde_kwin_contrast interface.
Definition: contrast.h:130
void release()
Releases the org_kde_kwin_contrast interface.
Definition: contrast.cpp:116
Wrapper for the wl_surface interface.
Definition: surface.h:43
void setup(org_kde_kwin_contrast *contrast)
Setup this Contrast to manage the contrast.
Definition: contrast.cpp:121
int red() const const
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating a Contrast.
Definition: contrast.cpp:61
void destroy()
Destroys the data held by this ContrastManager.
Definition: contrast.cpp:44
ContrastManager(QObject *parent=nullptr)
Creates a new ContrastManager.
Definition: contrast.cpp:28
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:54
int alpha() const const
int green() const const
Contrast * createContrast(Surface *surface, QObject *parent=nullptr)
Creates and setup a new Contrast with parent.
Definition: contrast.cpp:71
int blue() const const
bool isValid() const const
void setup(org_kde_kwin_contrast_manager *contrastManager)
Setup this ContrastManager to manage the contrastManager.
Definition: contrast.cpp:54
void setRegion(Region *region)
Sets the area of the window that will have a contrasted background.
Definition: contrast.cpp:144
QObject * parent() const const
void release()
Releases the org_kde_kwin_contrast_manager interface.
Definition: contrast.cpp:39
Wrapper for the wl_region interface.
Definition: region.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:56:21 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.