GCC Code Coverage Report


Directory: ./
File: src/client/xdgoutput.cpp
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 118 130 90.8%
Branches: 26 46 56.5%

Line Branch Exec Source
1 /****************************************************************************
2 Copyright 2018 David Edmundson <kde@davidedmundson.co.uk>
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 "xdgoutput.h"
21 #include "event_queue.h"
22 #include "output.h"
23 #include "wayland_pointer_p.h"
24
25 #include <wayland-client-protocol.h>
26 #include <wayland-xdg-output-unstable-v1-client-protocol.h>
27
28 #include <QDebug>
29
30 namespace Wrapland
31 {
32 namespace Client
33 {
34
35 class XdgOutputManager::Private
36 {
37 public:
38 6 Private() = default;
39
40 void setup(zxdg_output_manager_v1* arg);
41
42 WaylandPointer<zxdg_output_manager_v1, zxdg_output_manager_v1_destroy> xdgoutputmanager;
43 3 EventQueue* queue = nullptr;
44 };
45
46 3 XdgOutputManager::XdgOutputManager(QObject* parent)
47 3 : QObject(parent)
48
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 , d(new Private)
49 3 {
50 3 }
51
52 3 void XdgOutputManager::Private::setup(zxdg_output_manager_v1* arg)
53 {
54
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(arg);
55
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(!xdgoutputmanager);
56 3 xdgoutputmanager.setup(arg);
57 3 }
58
59 6 XdgOutputManager::~XdgOutputManager()
60 6 {
61
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 release();
62 6 }
63
64 3 void XdgOutputManager::setup(zxdg_output_manager_v1* xdgoutputmanager)
65 {
66 3 d->setup(xdgoutputmanager);
67 3 }
68
69 3 void XdgOutputManager::release()
70 {
71 3 d->xdgoutputmanager.release();
72 3 }
73
74 XdgOutputManager::operator zxdg_output_manager_v1*()
75 {
76 return d->xdgoutputmanager;
77 }
78
79 XdgOutputManager::operator zxdg_output_manager_v1*() const
80 {
81 return d->xdgoutputmanager;
82 }
83
84 3 bool XdgOutputManager::isValid() const
85 {
86 3 return d->xdgoutputmanager.isValid();
87 }
88
89 3 void XdgOutputManager::setEventQueue(EventQueue* queue)
90 {
91 3 d->queue = queue;
92 3 }
93
94 EventQueue* XdgOutputManager::eventQueue()
95 {
96 return d->queue;
97 }
98
99 struct XdgOutputBuffer {
100 QPoint logicalPosition;
101 QSize logicalSize;
102 std::string name;
103 std::string description;
104 };
105
106 class XdgOutput::Private
107 {
108 public:
109 Private(XdgOutput* q);
110
111 void setup(zxdg_output_v1* arg);
112 void done();
113
114 WaylandPointer<zxdg_output_v1, zxdg_output_v1_destroy> xdgoutput;
115
116 XdgOutputBuffer current;
117 XdgOutputBuffer pending;
118
119 private:
120 XdgOutput* q;
121
122 private:
123 static void
124 logical_positionCallback(void* data, zxdg_output_v1* zxdg_output_v1, int32_t x, int32_t y);
125 static void
126 logical_sizeCallback(void* data, zxdg_output_v1* zxdg_output_v1, int32_t width, int32_t height);
127 static void doneCallback(void* data, zxdg_output_v1* zxdg_output_v1);
128 static void name_callback(void* data, zxdg_output_v1* zxdg_output_v1, char const* name);
129 static void
130 description_callback(void* data, zxdg_output_v1* zxdg_output_v1, char const* description);
131
132 static const zxdg_output_v1_listener s_listener;
133 };
134
135 3 XdgOutput* XdgOutputManager::getXdgOutput(Output* output, QObject* parent)
136 {
137
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(isValid());
138
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 auto p = new XdgOutput(parent);
139 3 auto w = zxdg_output_manager_v1_get_xdg_output(d->xdgoutputmanager, *output);
140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (d->queue) {
141 3 d->queue->addProxy(w);
142 3 }
143 3 p->setup(w);
144
145
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (wl_proxy_get_version(reinterpret_cast<wl_proxy*>(w)) >= 3) {
146 3 connect(output, &Output::changed, p, [p] { p->d->done(); });
147 1 }
148
149 3 return p;
150 }
151 const zxdg_output_v1_listener XdgOutput::Private::s_listener = {
152 logical_positionCallback,
153 logical_sizeCallback,
154 doneCallback,
155 name_callback,
156 description_callback,
157 };
158
159 6 void XdgOutput::Private::logical_positionCallback(void* data,
160 zxdg_output_v1* zxdg_output_v1,
161 int32_t x,
162 int32_t y)
163 {
164 6 auto p = reinterpret_cast<XdgOutput::Private*>(data);
165
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 Q_ASSERT(p->xdgoutput == zxdg_output_v1);
166 6 p->pending.logicalPosition = QPoint(x, y);
167 6 }
168
169 6 void XdgOutput::Private::logical_sizeCallback(void* data,
170 zxdg_output_v1* zxdg_output_v1,
171 int32_t width,
172 int32_t height)
173 {
174 6 auto p = reinterpret_cast<XdgOutput::Private*>(data);
175
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 Q_ASSERT(p->xdgoutput == zxdg_output_v1);
176 6 p->pending.logicalSize = QSize(width, height);
177 6 }
178
179 4 void XdgOutput::Private::doneCallback(void* data, zxdg_output_v1* zxdg_output_v1)
180 {
181 4 auto p = reinterpret_cast<XdgOutput::Private*>(data);
182
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(p->xdgoutput == zxdg_output_v1);
183 4 p->done();
184 4 }
185
186 2 void XdgOutput::Private::name_callback(void* data, zxdg_output_v1* zxdg_output_v1, char const* name)
187 {
188 2 auto p = reinterpret_cast<XdgOutput::Private*>(data);
189
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(p->xdgoutput == zxdg_output_v1);
190 2 p->pending.name = name;
191 2 }
192
193 3 void XdgOutput::Private::description_callback(void* data,
194 zxdg_output_v1* zxdg_output_v1,
195 char const* description)
196 {
197 3 auto p = reinterpret_cast<XdgOutput::Private*>(data);
198
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(p->xdgoutput == zxdg_output_v1);
199 3 p->pending.description = description;
200 3 }
201
202 6 void XdgOutput::Private::done()
203 {
204 6 bool changed = false;
205
206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (current.logicalSize != pending.logicalSize) {
207 6 current.logicalSize = pending.logicalSize;
208 6 changed = true;
209 6 }
210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (current.logicalPosition != pending.logicalPosition) {
211 6 current.logicalPosition = pending.logicalPosition;
212 6 changed = true;
213 6 }
214
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 if (current.name != pending.name) {
215 2 current.name = pending.name;
216 2 changed = true;
217 2 }
218
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (current.description != pending.description) {
219 3 current.description = pending.description;
220 3 changed = true;
221 3 }
222
223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (changed) {
224 6 Q_EMIT q->changed();
225 6 }
226 6 }
227
228 3 XdgOutput::Private::Private(XdgOutput* qptr)
229 3 : q(qptr)
230 {
231 3 }
232
233 3 XdgOutput::XdgOutput(QObject* parent)
234 3 : QObject(parent)
235
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 , d(new Private(this))
236 3 {
237 3 }
238
239 3 void XdgOutput::Private::setup(zxdg_output_v1* arg)
240 {
241
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(arg);
242
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Q_ASSERT(!xdgoutput);
243 3 xdgoutput.setup(arg);
244 3 zxdg_output_v1_add_listener(xdgoutput, &s_listener, this);
245 3 }
246
247 6 XdgOutput::~XdgOutput()
248 6 {
249
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 release();
250 6 }
251
252 3 void XdgOutput::setup(zxdg_output_v1* xdgoutput)
253 {
254 3 d->setup(xdgoutput);
255 3 }
256
257 3 void XdgOutput::release()
258 {
259 3 d->xdgoutput.release();
260 3 }
261
262 6 QSize XdgOutput::logicalSize() const
263 {
264 6 return d->current.logicalSize;
265 }
266
267 6 QPoint XdgOutput::logicalPosition() const
268 {
269 6 return d->current.logicalPosition;
270 }
271
272 3 std::string XdgOutput::name() const
273 {
274 3 return d->current.name;
275 }
276
277 6 std::string XdgOutput::description() const
278 {
279 6 return d->current.description;
280 }
281
282 XdgOutput::operator zxdg_output_v1*()
283 {
284 return d->xdgoutput;
285 }
286
287 XdgOutput::operator zxdg_output_v1*() const
288 {
289 return d->xdgoutput;
290 }
291
292 bool XdgOutput::isValid() const
293 {
294 return d->xdgoutput.isValid();
295 }
296
297 }
298 }
299