GCC Code Coverage Report


Directory: ./
File: src/client/pointergestures.cpp
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 208 226 92.0%
Branches: 42 78 53.8%

Line Branch Exec Source
1 /****************************************************************************
2 Copyright 2016 Martin Gräßlin <mgraesslin@kde.org>
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 "pointergestures.h"
21 #include "event_queue.h"
22 #include "pointer.h"
23 #include "surface.h"
24 #include "wayland_pointer_p.h"
25
26 #include <wayland-pointer-gestures-unstable-v1-client-protocol.h>
27
28 #include <QSizeF>
29
30 namespace Wrapland
31 {
32 namespace Client
33 {
34
35 class Q_DECL_HIDDEN PointerGestures::Private
36 {
37 public:
38 106 Private() = default;
39
40 WaylandPointer<zwp_pointer_gestures_v1, zwp_pointer_gestures_v1_destroy> pointergestures;
41 53 EventQueue* queue = nullptr;
42 };
43
44 53 PointerGestures::PointerGestures(QObject* parent)
45 53 : QObject(parent)
46
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
53 , d(new Private)
47 53 {
48 53 }
49
50 106 PointerGestures::~PointerGestures()
51 106 {
52
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
53 release();
53 106 }
54
55 53 void PointerGestures::setup(zwp_pointer_gestures_v1* pointergestures)
56 {
57
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
53 Q_ASSERT(pointergestures);
58
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
53 Q_ASSERT(!d->pointergestures);
59 53 d->pointergestures.setup(pointergestures);
60 53 }
61
62 55 void PointerGestures::release()
63 {
64 55 d->pointergestures.release();
65 55 }
66
67 PointerGestures::operator zwp_pointer_gestures_v1*()
68 {
69 return d->pointergestures;
70 }
71
72 PointerGestures::operator zwp_pointer_gestures_v1*() const
73 {
74 return d->pointergestures;
75 }
76
77 59 bool PointerGestures::isValid() const
78 {
79 59 return d->pointergestures.isValid();
80 }
81
82 53 void PointerGestures::setEventQueue(EventQueue* queue)
83 {
84 53 d->queue = queue;
85 53 }
86
87 EventQueue* PointerGestures::eventQueue()
88 {
89 return d->queue;
90 }
91
92 2 PointerSwipeGesture* PointerGestures::createSwipeGesture(Pointer* pointer, QObject* parent)
93 {
94
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(isValid());
95
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 PointerSwipeGesture* p = new PointerSwipeGesture(parent);
96 2 auto w = zwp_pointer_gestures_v1_get_swipe_gesture(d->pointergestures, *pointer);
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (d->queue) {
98 2 d->queue->addProxy(w);
99 2 }
100 2 p->setup(w);
101 2 return p;
102 }
103
104 2 PointerPinchGesture* PointerGestures::createPinchGesture(Pointer* pointer, QObject* parent)
105 {
106
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(isValid());
107
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 PointerPinchGesture* p = new PointerPinchGesture(parent);
108 2 auto w = zwp_pointer_gestures_v1_get_pinch_gesture(d->pointergestures, *pointer);
109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (d->queue) {
110 2 d->queue->addProxy(w);
111 2 }
112 2 p->setup(w);
113 2 return p;
114 }
115
116 2 pointer_hold_gesture* PointerGestures::create_hold_gesture(Pointer* pointer, QObject* parent)
117 {
118
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(isValid());
119
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto gesture = new pointer_hold_gesture(parent);
120 2 auto w = zwp_pointer_gestures_v1_get_hold_gesture(d->pointergestures, *pointer);
121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (d->queue) {
122 2 d->queue->addProxy(w);
123 2 }
124 2 gesture->setup(w);
125 2 return gesture;
126 }
127
128 class Q_DECL_HIDDEN PointerSwipeGesture::Private
129 {
130 public:
131 Private(PointerSwipeGesture* q);
132
133 void setup(zwp_pointer_gesture_swipe_v1* pg);
134
135 WaylandPointer<zwp_pointer_gesture_swipe_v1, zwp_pointer_gesture_swipe_v1_destroy>
136 pointerswipegesture;
137 2 quint32 fingerCount = 0;
138 QPointer<Surface> surface;
139
140 private:
141 static void beginCallback(void* data,
142 zwp_pointer_gesture_swipe_v1* zwp_pointer_gesture_swipe_v1,
143 uint32_t serial,
144 uint32_t time,
145 wl_surface* surface,
146 uint32_t fingers);
147 static void updateCallback(void* data,
148 zwp_pointer_gesture_swipe_v1* zwp_pointer_gesture_swipe_v1,
149 uint32_t time,
150 wl_fixed_t dx,
151 wl_fixed_t dy);
152 static void endCallback(void* data,
153 zwp_pointer_gesture_swipe_v1* zwp_pointer_gesture_swipe_v1,
154 uint32_t serial,
155 uint32_t time,
156 int32_t cancelled);
157
158 PointerSwipeGesture* q;
159 static const zwp_pointer_gesture_swipe_v1_listener s_listener;
160 };
161
162 const zwp_pointer_gesture_swipe_v1_listener PointerSwipeGesture::Private::s_listener = {
163 beginCallback,
164 updateCallback,
165 endCallback,
166 };
167
168 4 void PointerSwipeGesture::Private::beginCallback(
169 void* data,
170 zwp_pointer_gesture_swipe_v1* zwp_pointer_gesture_swipe_v1,
171 uint32_t serial,
172 uint32_t time,
173 wl_surface* surface,
174 uint32_t fingers)
175 {
176 4 auto p = reinterpret_cast<PointerSwipeGesture::Private*>(data);
177
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(p->pointerswipegesture == zwp_pointer_gesture_swipe_v1);
178 4 p->fingerCount = fingers;
179 4 p->surface = QPointer<Surface>(Surface::get(surface));
180 4 Q_EMIT p->q->started(serial, time);
181 4 }
182
183 6 void PointerSwipeGesture::Private::updateCallback(
184 void* data,
185 zwp_pointer_gesture_swipe_v1* zwp_pointer_gesture_swipe_v1,
186 uint32_t time,
187 wl_fixed_t dx,
188 wl_fixed_t dy)
189 {
190 6 auto p = reinterpret_cast<PointerSwipeGesture::Private*>(data);
191
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 Q_ASSERT(p->pointerswipegesture == zwp_pointer_gesture_swipe_v1);
192 6 Q_EMIT p->q->updated(QSizeF(wl_fixed_to_double(dx), wl_fixed_to_double(dy)), time);
193 6 }
194
195 4 void PointerSwipeGesture::Private::endCallback(
196 void* data,
197 zwp_pointer_gesture_swipe_v1* zwp_pointer_gesture_swipe_v1,
198 uint32_t serial,
199 uint32_t time,
200 int32_t cancelled)
201 {
202 4 auto p = reinterpret_cast<PointerSwipeGesture::Private*>(data);
203
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(p->pointerswipegesture == zwp_pointer_gesture_swipe_v1);
204
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (cancelled) {
205 2 Q_EMIT p->q->cancelled(serial, time);
206 2 } else {
207 2 Q_EMIT p->q->ended(serial, time);
208 }
209 4 p->fingerCount = 0;
210 4 p->surface.clear();
211 4 }
212
213 4 PointerSwipeGesture::Private::Private(PointerSwipeGesture* q)
214 2 : q(q)
215 {
216 2 }
217
218 2 PointerSwipeGesture::PointerSwipeGesture(QObject* parent)
219 2 : QObject(parent)
220
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 , d(new Private(this))
221 2 {
222 2 }
223
224 4 PointerSwipeGesture::~PointerSwipeGesture()
225 4 {
226
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 release();
227 4 }
228
229 6 quint32 PointerSwipeGesture::fingerCount() const
230 {
231 6 return d->fingerCount;
232 }
233
234 6 QPointer<Surface> PointerSwipeGesture::surface() const
235 {
236 6 return d->surface;
237 }
238
239 2 void PointerSwipeGesture::Private::setup(zwp_pointer_gesture_swipe_v1* pg)
240 {
241
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(pg);
242
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(!pointerswipegesture);
243 2 pointerswipegesture.setup(pg);
244 2 zwp_pointer_gesture_swipe_v1_add_listener(pointerswipegesture, &s_listener, this);
245 2 }
246
247 2 void PointerSwipeGesture::setup(zwp_pointer_gesture_swipe_v1* pointerswipegesture)
248 {
249 2 d->setup(pointerswipegesture);
250 2 }
251
252 2 void PointerSwipeGesture::release()
253 {
254 2 d->pointerswipegesture.release();
255 2 }
256
257 PointerSwipeGesture::operator zwp_pointer_gesture_swipe_v1*()
258 {
259 return d->pointerswipegesture;
260 }
261
262 PointerSwipeGesture::operator zwp_pointer_gesture_swipe_v1*() const
263 {
264 return d->pointerswipegesture;
265 }
266
267 2 bool PointerSwipeGesture::isValid() const
268 {
269 2 return d->pointerswipegesture.isValid();
270 }
271
272 class Q_DECL_HIDDEN PointerPinchGesture::Private
273 {
274 public:
275 Private(PointerPinchGesture* q);
276
277 void setup(zwp_pointer_gesture_pinch_v1* pg);
278
279 WaylandPointer<zwp_pointer_gesture_pinch_v1, zwp_pointer_gesture_pinch_v1_destroy>
280 pointerpinchgesture;
281 2 quint32 fingerCount = 0;
282 QPointer<Surface> surface;
283
284 private:
285 static void beginCallback(void* data,
286 zwp_pointer_gesture_pinch_v1* zwp_pointer_gesture_pinch_v1,
287 uint32_t serial,
288 uint32_t time,
289 wl_surface* surface,
290 uint32_t fingers);
291 static void updateCallback(void* data,
292 zwp_pointer_gesture_pinch_v1* zwp_pointer_gesture_pinch_v1,
293 uint32_t time,
294 wl_fixed_t dx,
295 wl_fixed_t dy,
296 wl_fixed_t scale,
297 wl_fixed_t rotation);
298 static void endCallback(void* data,
299 zwp_pointer_gesture_pinch_v1* zwp_pointer_gesture_pinch_v1,
300 uint32_t serial,
301 uint32_t time,
302 int32_t cancelled);
303
304 PointerPinchGesture* q;
305 static const zwp_pointer_gesture_pinch_v1_listener s_listener;
306 };
307
308 const zwp_pointer_gesture_pinch_v1_listener PointerPinchGesture::Private::s_listener = {
309 beginCallback,
310 updateCallback,
311 endCallback,
312 };
313
314 4 void PointerPinchGesture::Private::beginCallback(void* data,
315 zwp_pointer_gesture_pinch_v1* pg,
316 uint32_t serial,
317 uint32_t time,
318 wl_surface* surface,
319 uint32_t fingers)
320 {
321 4 auto p = reinterpret_cast<PointerPinchGesture::Private*>(data);
322
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(p->pointerpinchgesture == pg);
323 4 p->fingerCount = fingers;
324 4 p->surface = QPointer<Surface>(Surface::get(surface));
325 4 Q_EMIT p->q->started(serial, time);
326 4 }
327
328 6 void PointerPinchGesture::Private::updateCallback(void* data,
329 zwp_pointer_gesture_pinch_v1* pg,
330 uint32_t time,
331 wl_fixed_t dx,
332 wl_fixed_t dy,
333 wl_fixed_t scale,
334 wl_fixed_t rotation)
335 {
336 6 auto p = reinterpret_cast<PointerPinchGesture::Private*>(data);
337
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 Q_ASSERT(p->pointerpinchgesture == pg);
338 12 Q_EMIT p->q->updated(QSizeF(wl_fixed_to_double(dx), wl_fixed_to_double(dy)),
339 6 wl_fixed_to_double(scale),
340 6 wl_fixed_to_double(rotation),
341 6 time);
342 6 }
343
344 4 void PointerPinchGesture::Private::endCallback(void* data,
345 zwp_pointer_gesture_pinch_v1* pg,
346 uint32_t serial,
347 uint32_t time,
348 int32_t cancelled)
349 {
350 4 auto p = reinterpret_cast<PointerPinchGesture::Private*>(data);
351
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(p->pointerpinchgesture == pg);
352
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (cancelled) {
353 2 Q_EMIT p->q->cancelled(serial, time);
354 2 } else {
355 2 Q_EMIT p->q->ended(serial, time);
356 }
357 4 p->fingerCount = 0;
358 4 p->surface.clear();
359 4 }
360
361 4 PointerPinchGesture::Private::Private(PointerPinchGesture* q)
362 2 : q(q)
363 {
364 2 }
365
366 2 PointerPinchGesture::PointerPinchGesture(QObject* parent)
367 2 : QObject(parent)
368
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 , d(new Private(this))
369 2 {
370 2 }
371
372 4 PointerPinchGesture::~PointerPinchGesture()
373 4 {
374
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 release();
375 4 }
376
377 2 void PointerPinchGesture::Private::setup(zwp_pointer_gesture_pinch_v1* pg)
378 {
379
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(pg);
380
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(!pointerpinchgesture);
381 2 pointerpinchgesture.setup(pg);
382 2 zwp_pointer_gesture_pinch_v1_add_listener(pointerpinchgesture, &s_listener, this);
383 2 }
384
385 2 void PointerPinchGesture::setup(zwp_pointer_gesture_pinch_v1* pointerpinchgesture)
386 {
387 2 d->setup(pointerpinchgesture);
388 2 }
389
390 2 void PointerPinchGesture::release()
391 {
392 2 d->pointerpinchgesture.release();
393 2 }
394
395 PointerPinchGesture::operator zwp_pointer_gesture_pinch_v1*()
396 {
397 return d->pointerpinchgesture;
398 }
399
400 PointerPinchGesture::operator zwp_pointer_gesture_pinch_v1*() const
401 {
402 return d->pointerpinchgesture;
403 }
404
405 2 bool PointerPinchGesture::isValid() const
406 {
407 2 return d->pointerpinchgesture.isValid();
408 }
409
410 6 quint32 PointerPinchGesture::fingerCount() const
411 {
412 6 return d->fingerCount;
413 }
414
415 6 QPointer<Surface> PointerPinchGesture::surface() const
416 {
417 6 return d->surface;
418 }
419
420 class Q_DECL_HIDDEN pointer_hold_gesture::Private
421 {
422 public:
423 Private(pointer_hold_gesture* q);
424
425 void setup(zwp_pointer_gesture_hold_v1* pg);
426
427 WaylandPointer<zwp_pointer_gesture_hold_v1, zwp_pointer_gesture_hold_v1_destroy> native;
428 2 quint32 fingerCount = 0;
429 QPointer<Surface> surface;
430
431 private:
432 static void begin_callback(void* data,
433 zwp_pointer_gesture_hold_v1* zwp_pointer_gesture_hold_v1,
434 uint32_t serial,
435 uint32_t time,
436 wl_surface* surface,
437 uint32_t fingers);
438 static void end_callback(void* data,
439 zwp_pointer_gesture_hold_v1* zwp_pointer_gesture_hold_v1,
440 uint32_t serial,
441 uint32_t time,
442 int32_t cancelled);
443
444 pointer_hold_gesture* q;
445 static const zwp_pointer_gesture_hold_v1_listener s_listener;
446 };
447
448 const zwp_pointer_gesture_hold_v1_listener pointer_hold_gesture::Private::s_listener = {
449 begin_callback,
450 end_callback,
451 };
452
453 4 void pointer_hold_gesture::Private::begin_callback(void* data,
454 zwp_pointer_gesture_hold_v1* pg,
455 uint32_t serial,
456 uint32_t time,
457 wl_surface* surface,
458 uint32_t fingers)
459 {
460 4 auto p = reinterpret_cast<pointer_hold_gesture::Private*>(data);
461
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(p->native == pg);
462 4 p->fingerCount = fingers;
463 4 p->surface = QPointer<Surface>(Surface::get(surface));
464 4 Q_EMIT p->q->started(serial, time);
465 4 }
466
467 4 void pointer_hold_gesture::Private::end_callback(void* data,
468 zwp_pointer_gesture_hold_v1* pg,
469 uint32_t serial,
470 uint32_t time,
471 int32_t cancelled)
472 {
473 4 auto p = reinterpret_cast<pointer_hold_gesture::Private*>(data);
474
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Q_ASSERT(p->native == pg);
475
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (cancelled) {
476 2 Q_EMIT p->q->cancelled(serial, time);
477 2 } else {
478 2 Q_EMIT p->q->ended(serial, time);
479 }
480 4 p->fingerCount = 0;
481 4 p->surface.clear();
482 4 }
483
484 4 pointer_hold_gesture::Private::Private(pointer_hold_gesture* q)
485 2 : q(q)
486 {
487 2 }
488
489 2 pointer_hold_gesture::pointer_hold_gesture(QObject* parent)
490 2 : QObject(parent)
491
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 , d(new Private(this))
492 2 {
493 2 }
494
495 4 pointer_hold_gesture::~pointer_hold_gesture()
496 4 {
497
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 release();
498 4 }
499
500 2 void pointer_hold_gesture::Private::setup(zwp_pointer_gesture_hold_v1* pg)
501 {
502
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(pg);
503
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Q_ASSERT(!native);
504 2 native.setup(pg);
505 2 zwp_pointer_gesture_hold_v1_add_listener(native, &s_listener, this);
506 2 }
507
508 2 void pointer_hold_gesture::setup(zwp_pointer_gesture_hold_v1* gesture)
509 {
510 2 d->setup(gesture);
511 2 }
512
513 2 void pointer_hold_gesture::release()
514 {
515 2 d->native.release();
516 2 }
517
518 pointer_hold_gesture::operator zwp_pointer_gesture_hold_v1*()
519 {
520 return d->native;
521 }
522
523 pointer_hold_gesture::operator zwp_pointer_gesture_hold_v1*() const
524 {
525 return d->native;
526 }
527
528 2 bool pointer_hold_gesture::isValid() const
529 {
530 2 return d->native.isValid();
531 }
532
533 6 quint32 pointer_hold_gesture::fingerCount() const
534 {
535 6 return d->fingerCount;
536 }
537
538 6 QPointer<Surface> pointer_hold_gesture::surface() const
539 {
540 6 return d->surface;
541 }
542
543 }
544
545 }
546