Directory: | ./ |
---|---|
File: | server/contrast.cpp |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 64 | 70 | 91.4% |
Branches: | 11 | 24 | 45.8% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /******************************************************************** | ||
2 | Copyright 2020 Faveraux Adrien <ad1rie3@hotmail.fr> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||
8 | later version accepted by the membership of KDE e.V. (or its | ||
9 | successor approved by the membership of KDE e.V.), which shall | ||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | |||
12 | This library is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Lesser General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | ||
20 | #include "contrast.h" | ||
21 | #include "contrast_p.h" | ||
22 | |||
23 | #include "wayland/client.h" | ||
24 | #include "wayland/global.h" | ||
25 | #include "wayland/resource.h" | ||
26 | |||
27 | #include "client.h" | ||
28 | #include "display.h" | ||
29 | #include "region.h" | ||
30 | #include "surface.h" | ||
31 | #include "surface_p.h" | ||
32 | |||
33 | #include <wayland-server.h> | ||
34 | |||
35 | namespace Wrapland::Server | ||
36 | { | ||
37 | |||
38 | const struct org_kde_kwin_contrast_manager_interface ContrastManager::Private::s_interface = { | ||
39 | cb<createCallback>, | ||
40 | unsetCallback, | ||
41 | }; | ||
42 | |||
43 | 37 | ContrastManager::Private::Private(Display* display, ContrastManager* q_ptr) | |
44 | 37 | : ContrastManagerGlobal(q_ptr, display, &org_kde_kwin_contrast_manager_interface, &s_interface) | |
45 | 37 | { | |
46 | 37 | display->globals.contrast_manager = q_ptr; | |
47 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | create(); |
48 | 37 | } | |
49 | |||
50 | 2 | void ContrastManager::Private::createCallback(ContrastManagerBind* bind, | |
51 | uint32_t id, | ||
52 | wl_resource* wlSurface) | ||
53 | { | ||
54 | 2 | auto surface = Wayland::Resource<Surface>::get_handle(wlSurface); | |
55 | |||
56 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | auto contrast = new Contrast(bind->client->handle, bind->version, id); |
57 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (!contrast->d_ptr->resource) { |
58 | ✗ | bind->post_no_memory(); | |
59 | ✗ | delete contrast; | |
60 | ✗ | return; | |
61 | } | ||
62 | |||
63 | 2 | surface->d_ptr->setContrast(contrast); | |
64 | 2 | } | |
65 | |||
66 | ✗ | void ContrastManager::Private::unsetCallback([[maybe_unused]] wl_client* wlClient, | |
67 | [[maybe_unused]] wl_resource* wlResource, | ||
68 | wl_resource* wlSurface) | ||
69 | { | ||
70 | ✗ | auto surface = Wayland::Resource<Surface>::get_handle(wlSurface); | |
71 | ✗ | surface->d_ptr->setContrast(nullptr); | |
72 | } | ||
73 | |||
74 | 37 | ContrastManager::ContrastManager(Display* display) | |
75 |
2/4✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
|
37 | : d_ptr(new Private(display, this)) |
76 | 37 | { | |
77 | 37 | } | |
78 | |||
79 | 74 | ContrastManager::~ContrastManager() = default; | |
80 | |||
81 | const struct org_kde_kwin_contrast_interface Contrast::Private::s_interface = { | ||
82 | commitCallback, | ||
83 | setRegionCallback, | ||
84 | setContrastCallback, | ||
85 | setIntensityCallback, | ||
86 | setSaturationCallback, | ||
87 | destroyCallback, | ||
88 | }; | ||
89 | |||
90 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
4 | Contrast::Private::Private(Client* client, uint32_t version, uint32_t id, Contrast* q_ptr) |
91 | 4 | : Wayland::Resource<Contrast>(client, | |
92 | 2 | version, | |
93 | 2 | id, | |
94 | &org_kde_kwin_contrast_interface, | ||
95 | &s_interface, | ||
96 | 2 | q_ptr) | |
97 | 2 | { | |
98 | 2 | } | |
99 | |||
100 | 4 | Contrast::Private::~Private() = default; | |
101 | |||
102 | 2 | void Contrast::Private::commitCallback([[maybe_unused]] wl_client* wlClient, | |
103 | wl_resource* wlResource) | ||
104 | { | ||
105 | 2 | auto priv = get_handle(wlResource)->d_ptr; | |
106 | 2 | priv->commit(); | |
107 | 2 | } | |
108 | |||
109 | 2 | void Contrast::Private::commit() | |
110 | { | ||
111 | 2 | currentRegion = pendingRegion; | |
112 | 2 | currentContrast = pendingContrast; | |
113 | 2 | currentIntensity = pendingIntensity; | |
114 | 2 | currentSaturation = pendingSaturation; | |
115 | 2 | } | |
116 | |||
117 | 2 | void Contrast::Private::setRegionCallback([[maybe_unused]] wl_client* wlClient, | |
118 | wl_resource* wlResource, | ||
119 | wl_resource* wlRegion) | ||
120 | { | ||
121 | 2 | auto priv = get_handle(wlResource)->d_ptr; | |
122 | 2 | auto region = Wayland::Resource<Region>::get_handle(wlRegion); | |
123 | |||
124 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | priv->pendingRegion = region ? region->region() : QRegion(); |
125 | 2 | } | |
126 | |||
127 | 1 | void Contrast::Private::setContrastCallback([[maybe_unused]] wl_client* wlClient, | |
128 | wl_resource* wlResource, | ||
129 | wl_fixed_t contrast) | ||
130 | { | ||
131 | 1 | auto priv = get_handle(wlResource)->d_ptr; | |
132 | 1 | priv->pendingContrast = wl_fixed_to_double(contrast); | |
133 | 1 | } | |
134 | |||
135 | 1 | void Contrast::Private::setIntensityCallback([[maybe_unused]] wl_client* wlClient, | |
136 | wl_resource* wlResource, | ||
137 | wl_fixed_t intensity) | ||
138 | { | ||
139 | 1 | auto priv = get_handle(wlResource)->d_ptr; | |
140 | 1 | priv->pendingIntensity = wl_fixed_to_double(intensity); | |
141 | 1 | } | |
142 | |||
143 | 1 | void Contrast::Private::setSaturationCallback([[maybe_unused]] wl_client* wlClient, | |
144 | wl_resource* wlResource, | ||
145 | wl_fixed_t saturation) | ||
146 | { | ||
147 | 1 | auto priv = get_handle(wlResource)->d_ptr; | |
148 | 1 | priv->pendingSaturation = wl_fixed_to_double(saturation); | |
149 | 1 | } | |
150 | |||
151 | 2 | Contrast::Contrast(Client* client, uint32_t version, uint32_t id) | |
152 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | : d_ptr(new Private(client, version, id, this)) |
153 | 2 | { | |
154 | 2 | } | |
155 | |||
156 | 2 | QRegion Contrast::region() const | |
157 | { | ||
158 | 2 | return d_ptr->currentRegion; | |
159 | } | ||
160 | |||
161 | 1 | qreal Contrast::contrast() const | |
162 | { | ||
163 | 1 | return d_ptr->currentContrast; | |
164 | } | ||
165 | |||
166 | 1 | qreal Contrast::intensity() const | |
167 | { | ||
168 | 1 | return d_ptr->currentIntensity; | |
169 | } | ||
170 | |||
171 | 1 | qreal Contrast::saturation() const | |
172 | { | ||
173 | 1 | return d_ptr->currentSaturation; | |
174 | } | ||
175 | } | ||
176 |