1/*
2 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
3 SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
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
15namespace KWayland
16{
17namespace Client
18{
19class Q_DECL_HIDDEN ContrastManager::Private
20{
21public:
22 Private() = default;
23
24 WaylandPointer<org_kde_kwin_contrast_manager, org_kde_kwin_contrast_manager_destroy> manager;
25 EventQueue *queue = nullptr;
26};
27
28ContrastManager::ContrastManager(QObject *parent)
29 : QObject(parent)
30 , d(new Private)
31{
32}
33
34ContrastManager::~ContrastManager()
35{
36 release();
37}
38
39void ContrastManager::release()
40{
41 d->manager.release();
42}
43
44void ContrastManager::destroy()
45{
46 d->manager.destroy();
47}
48
49bool ContrastManager::isValid() const
50{
51 return d->manager.isValid();
52}
53
54void ContrastManager::setup(org_kde_kwin_contrast_manager *manager)
55{
56 Q_ASSERT(manager);
57 Q_ASSERT(!d->manager);
58 d->manager.setup(pointer: manager);
59}
60
61void ContrastManager::setEventQueue(EventQueue *queue)
62{
63 d->queue = queue;
64}
65
66EventQueue *ContrastManager::eventQueue()
67{
68 return d->queue;
69}
70
71Contrast *ContrastManager::createContrast(Surface *surface, QObject *parent)
72{
73 Q_ASSERT(isValid());
74 Contrast *s = new Contrast(parent);
75 auto w = org_kde_kwin_contrast_manager_create(org_kde_kwin_contrast_manager: d->manager, surface: *surface);
76 if (d->queue) {
77 d->queue->addProxy(proxy: w);
78 }
79 s->setup(w);
80 return s;
81}
82
83void ContrastManager::removeContrast(Surface *surface)
84{
85 Q_ASSERT(isValid());
86 org_kde_kwin_contrast_manager_unset(org_kde_kwin_contrast_manager: d->manager, surface: *surface);
87}
88
89ContrastManager::operator org_kde_kwin_contrast_manager *()
90{
91 return d->manager;
92}
93
94ContrastManager::operator org_kde_kwin_contrast_manager *() const
95{
96 return d->manager;
97}
98
99class Contrast::Private
100{
101public:
102 WaylandPointer<org_kde_kwin_contrast, org_kde_kwin_contrast_release> contrast;
103};
104
105Contrast::Contrast(QObject *parent)
106 : QObject(parent)
107 , d(new Private)
108{
109}
110
111Contrast::~Contrast()
112{
113 release();
114}
115
116void Contrast::release()
117{
118 d->contrast.release();
119}
120
121void Contrast::setup(org_kde_kwin_contrast *contrast)
122{
123 Q_ASSERT(contrast);
124 Q_ASSERT(!d->contrast);
125 d->contrast.setup(pointer: contrast);
126}
127
128void Contrast::destroy()
129{
130 d->contrast.destroy();
131}
132
133bool Contrast::isValid() const
134{
135 return d->contrast.isValid();
136}
137
138void Contrast::commit()
139{
140 Q_ASSERT(isValid());
141 org_kde_kwin_contrast_commit(org_kde_kwin_contrast: d->contrast);
142}
143
144void Contrast::setRegion(Region *region)
145{
146 org_kde_kwin_contrast_set_region(org_kde_kwin_contrast: d->contrast, region: *region);
147}
148
149void Contrast::setContrast(qreal contrast)
150{
151 org_kde_kwin_contrast_set_contrast(org_kde_kwin_contrast: d->contrast, contrast: wl_fixed_from_double(d: contrast));
152}
153
154void Contrast::setIntensity(qreal intensity)
155{
156 org_kde_kwin_contrast_set_intensity(org_kde_kwin_contrast: d->contrast, intensity: wl_fixed_from_double(d: intensity));
157}
158
159void Contrast::setSaturation(qreal saturation)
160{
161 org_kde_kwin_contrast_set_saturation(org_kde_kwin_contrast: d->contrast, saturation: wl_fixed_from_double(d: saturation));
162}
163
164void Contrast::setFrost(QColor frost)
165{
166 if (org_kde_kwin_contrast_get_version(org_kde_kwin_contrast: 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(org_kde_kwin_contrast: d->contrast, red: frost.red(), green: frost.green(), blue: frost.blue(), alpha: frost.alpha());
172 } else {
173 org_kde_kwin_contrast_unset_frost(org_kde_kwin_contrast: d->contrast);
174 }
175}
176
177Contrast::operator org_kde_kwin_contrast *()
178{
179 return d->contrast;
180}
181
182Contrast::operator org_kde_kwin_contrast *() const
183{
184 return d->contrast;
185}
186
187}
188}
189
190#include "moc_contrast.cpp"
191

source code of kwayland/src/client/contrast.cpp