Directory: | ./ |
---|---|
File: | src/client/contrast.cpp |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 68 | 81 | 84.0% |
Branches: | 13 | 26 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /******************************************************************** | ||
2 | Copyright 2015 Martin Gräßlin <mgraesslin@kde.org> | ||
3 | Copyright 2015 Marco Martin <mart@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) version 3, or any | ||
9 | later version accepted by the membership of KDE e.V. (or its | ||
10 | successor approved by the membership of KDE e.V.), which shall | ||
11 | act as a proxy defined in Section 6 of version 3 of the license. | ||
12 | |||
13 | This library is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | Lesser General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Lesser General Public | ||
19 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | *********************************************************************/ | ||
21 | #include "contrast.h" | ||
22 | #include "event_queue.h" | ||
23 | #include "region.h" | ||
24 | #include "surface.h" | ||
25 | #include "wayland_pointer_p.h" | ||
26 | |||
27 | #include <wayland-contrast-client-protocol.h> | ||
28 | |||
29 | namespace Wrapland | ||
30 | { | ||
31 | |||
32 | namespace Client | ||
33 | { | ||
34 | |||
35 | class Q_DECL_HIDDEN ContrastManager::Private | ||
36 | { | ||
37 | public: | ||
38 | 6 | Private() = default; | |
39 | |||
40 | WaylandPointer<org_kde_kwin_contrast_manager, org_kde_kwin_contrast_manager_destroy> manager; | ||
41 | 3 | EventQueue* queue = nullptr; | |
42 | }; | ||
43 | |||
44 | 3 | ContrastManager::ContrastManager(QObject* parent) | |
45 | 3 | : QObject(parent) | |
46 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | , d(new Private) |
47 | 3 | { | |
48 | 3 | } | |
49 | |||
50 | 6 | ContrastManager::~ContrastManager() | |
51 | 6 | { | |
52 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | release(); |
53 | 6 | } | |
54 | |||
55 | 3 | void ContrastManager::release() | |
56 | { | ||
57 | 3 | d->manager.release(); | |
58 | 3 | } | |
59 | |||
60 | 3 | bool ContrastManager::isValid() const | |
61 | { | ||
62 | 3 | return d->manager.isValid(); | |
63 | } | ||
64 | |||
65 | 3 | void ContrastManager::setup(org_kde_kwin_contrast_manager* manager) | |
66 | { | ||
67 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | Q_ASSERT(manager); |
68 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | Q_ASSERT(!d->manager); |
69 | 3 | d->manager.setup(manager); | |
70 | 3 | } | |
71 | |||
72 | 3 | void ContrastManager::setEventQueue(EventQueue* queue) | |
73 | { | ||
74 | 3 | d->queue = queue; | |
75 | 3 | } | |
76 | |||
77 | ✗ | EventQueue* ContrastManager::eventQueue() | |
78 | { | ||
79 | ✗ | return d->queue; | |
80 | } | ||
81 | |||
82 | 3 | Contrast* ContrastManager::createContrast(Surface* surface, QObject* parent) | |
83 | { | ||
84 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | Q_ASSERT(isValid()); |
85 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | Contrast* s = new Contrast(parent); |
86 | 3 | auto w = org_kde_kwin_contrast_manager_create(d->manager, *surface); | |
87 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (d->queue) { |
88 | 2 | d->queue->addProxy(w); | |
89 | 2 | } | |
90 | 3 | s->setup(w); | |
91 | 3 | return s; | |
92 | } | ||
93 | |||
94 | ✗ | void ContrastManager::removeContrast(Surface* surface) | |
95 | { | ||
96 | ✗ | Q_ASSERT(isValid()); | |
97 | ✗ | org_kde_kwin_contrast_manager_unset(d->manager, *surface); | |
98 | } | ||
99 | |||
100 | ✗ | ContrastManager::operator org_kde_kwin_contrast_manager*() | |
101 | { | ||
102 | ✗ | return d->manager; | |
103 | } | ||
104 | |||
105 | ✗ | ContrastManager::operator org_kde_kwin_contrast_manager*() const | |
106 | { | ||
107 | ✗ | return d->manager; | |
108 | } | ||
109 | |||
110 | class Contrast::Private | ||
111 | { | ||
112 | public: | ||
113 | WaylandPointer<org_kde_kwin_contrast, org_kde_kwin_contrast_release> contrast; | ||
114 | }; | ||
115 | |||
116 | 3 | Contrast::Contrast(QObject* parent) | |
117 | 3 | : QObject(parent) | |
118 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | , d(new Private) |
119 | 3 | { | |
120 | 3 | } | |
121 | |||
122 | 6 | Contrast::~Contrast() | |
123 | 6 | { | |
124 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | release(); |
125 | 6 | } | |
126 | |||
127 | 3 | void Contrast::release() | |
128 | { | ||
129 | 3 | d->contrast.release(); | |
130 | 3 | } | |
131 | |||
132 | 3 | void Contrast::setup(org_kde_kwin_contrast* contrast) | |
133 | { | ||
134 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | Q_ASSERT(contrast); |
135 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | Q_ASSERT(!d->contrast); |
136 | 3 | d->contrast.setup(contrast); | |
137 | 3 | } | |
138 | |||
139 | 2 | bool Contrast::isValid() const | |
140 | { | ||
141 | 2 | return d->contrast.isValid(); | |
142 | } | ||
143 | |||
144 | 2 | void Contrast::commit() | |
145 | { | ||
146 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | Q_ASSERT(isValid()); |
147 | 2 | org_kde_kwin_contrast_commit(d->contrast); | |
148 | 2 | } | |
149 | |||
150 | 2 | void Contrast::setRegion(Region* region) | |
151 | { | ||
152 | 2 | org_kde_kwin_contrast_set_region(d->contrast, *region); | |
153 | 2 | } | |
154 | |||
155 | 1 | void Contrast::setContrast(qreal contrast) | |
156 | { | ||
157 | 1 | org_kde_kwin_contrast_set_contrast(d->contrast, wl_fixed_from_double(contrast)); | |
158 | 1 | } | |
159 | |||
160 | 1 | void Contrast::setIntensity(qreal intensity) | |
161 | { | ||
162 | 1 | org_kde_kwin_contrast_set_intensity(d->contrast, wl_fixed_from_double(intensity)); | |
163 | 1 | } | |
164 | |||
165 | 1 | void Contrast::setSaturation(qreal saturation) | |
166 | { | ||
167 | 1 | org_kde_kwin_contrast_set_saturation(d->contrast, wl_fixed_from_double(saturation)); | |
168 | 1 | } | |
169 | |||
170 | ✗ | Contrast::operator org_kde_kwin_contrast*() | |
171 | { | ||
172 | ✗ | return d->contrast; | |
173 | } | ||
174 | |||
175 | ✗ | Contrast::operator org_kde_kwin_contrast*() const | |
176 | { | ||
177 | ✗ | return d->contrast; | |
178 | } | ||
179 | |||
180 | } | ||
181 | } | ||
182 |