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 | |
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 | |
28 | ContrastManager::ContrastManager(QObject *parent) |
29 | : QObject(parent) |
30 | , d(new Private) |
31 | { |
32 | } |
33 | |
34 | ContrastManager::~ContrastManager() |
35 | { |
36 | release(); |
37 | } |
38 | |
39 | void ContrastManager::release() |
40 | { |
41 | d->manager.release(); |
42 | } |
43 | |
44 | void ContrastManager::destroy() |
45 | { |
46 | d->manager.destroy(); |
47 | } |
48 | |
49 | bool ContrastManager::isValid() const |
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(pointer: manager); |
59 | } |
60 | |
61 | void ContrastManager::setEventQueue(EventQueue *queue) |
62 | { |
63 | d->queue = queue; |
64 | } |
65 | |
66 | EventQueue *ContrastManager::eventQueue() |
67 | { |
68 | return d->queue; |
69 | } |
70 | |
71 | Contrast *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 | |
83 | void 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 | |
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 | |
116 | void Contrast::release() |
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(pointer: contrast); |
126 | } |
127 | |
128 | void Contrast::destroy() |
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(org_kde_kwin_contrast: d->contrast); |
142 | } |
143 | |
144 | void Contrast::setRegion(Region *region) |
145 | { |
146 | org_kde_kwin_contrast_set_region(org_kde_kwin_contrast: d->contrast, region: *region); |
147 | } |
148 | |
149 | void 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 | |
154 | void 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 | |
159 | void 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 | |
164 | void 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 | |
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 | } |
189 | |
190 | #include "moc_contrast.cpp" |
191 | |