KWayland

pointergestures.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "pointergestures.h"
7 #include "event_queue.h"
8 #include "pointer.h"
9 #include "surface.h"
10 #include "wayland_pointer_p.h"
11 
12 #include <wayland-pointer-gestures-unstable-v1-client-protocol.h>
13 
14 #include <QSizeF>
15 
16 namespace KWayland
17 {
18 namespace Client
19 {
20 class Q_DECL_HIDDEN PointerGestures::Private
21 {
22 public:
23  Private() = default;
24 
25  WaylandPointer<zwp_pointer_gestures_v1, zwp_pointer_gestures_v1_destroy> pointergestures;
26  EventQueue *queue = nullptr;
27 };
28 
30  : QObject(parent)
31  , d(new Private)
32 {
33 }
34 
35 PointerGestures::~PointerGestures()
36 {
37  release();
38 }
39 
40 void PointerGestures::setup(zwp_pointer_gestures_v1 *pointergestures)
41 {
42  Q_ASSERT(pointergestures);
43  Q_ASSERT(!d->pointergestures);
44  d->pointergestures.setup(pointergestures);
45 }
46 
48 {
49  d->pointergestures.release();
50 }
51 
53 {
54  d->pointergestures.destroy();
55 }
56 
57 PointerGestures::operator zwp_pointer_gestures_v1 *()
58 {
59  return d->pointergestures;
60 }
61 
62 PointerGestures::operator zwp_pointer_gestures_v1 *() const
63 {
64  return d->pointergestures;
65 }
66 
68 {
69  return d->pointergestures.isValid();
70 }
71 
73 {
74  d->queue = queue;
75 }
76 
78 {
79  return d->queue;
80 }
81 
83 {
84  Q_ASSERT(isValid());
86  auto w = zwp_pointer_gestures_v1_get_swipe_gesture(d->pointergestures, *pointer);
87  if (d->queue) {
88  d->queue->addProxy(w);
89  }
90  p->setup(w);
91  return p;
92 }
93 
95 {
96  Q_ASSERT(isValid());
98  auto w = zwp_pointer_gestures_v1_get_pinch_gesture(d->pointergestures, *pointer);
99  if (d->queue) {
100  d->queue->addProxy(w);
101  }
102  p->setup(w);
103  return p;
104 }
105 
106 class Q_DECL_HIDDEN PointerSwipeGesture::Private
107 {
108 public:
109  Private(PointerSwipeGesture *q);
110 
111  void setup(zwp_pointer_gesture_swipe_v1 *pg);
112 
113  WaylandPointer<zwp_pointer_gesture_swipe_v1, zwp_pointer_gesture_swipe_v1_destroy> pointerswipegesture;
114  quint32 fingerCount = 0;
115  QPointer<Surface> surface;
116 
117 private:
118  static void beginCallback(void *data,
119  zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1,
120  uint32_t serial,
121  uint32_t time,
122  wl_surface *surface,
123  uint32_t fingers);
124  static void updateCallback(void *data, zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1, uint32_t time, wl_fixed_t dx, wl_fixed_t dy);
125  static void endCallback(void *data, zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1, uint32_t serial, uint32_t time, int32_t cancelled);
126 
128  static const zwp_pointer_gesture_swipe_v1_listener s_listener;
129 };
130 
131 const zwp_pointer_gesture_swipe_v1_listener PointerSwipeGesture::Private::s_listener = {beginCallback, updateCallback, endCallback};
132 
133 void PointerSwipeGesture::Private::beginCallback(void *data,
134  zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1,
135  uint32_t serial,
136  uint32_t time,
137  wl_surface *surface,
138  uint32_t fingers)
139 {
140  auto p = reinterpret_cast<PointerSwipeGesture::Private *>(data);
141  Q_ASSERT(p->pointerswipegesture == zwp_pointer_gesture_swipe_v1);
142  p->fingerCount = fingers;
143  p->surface = QPointer<Surface>(Surface::get(surface));
144  Q_EMIT p->q->started(serial, time);
145 }
146 
147 void PointerSwipeGesture::Private::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 {
153  auto p = reinterpret_cast<PointerSwipeGesture::Private *>(data);
154  Q_ASSERT(p->pointerswipegesture == zwp_pointer_gesture_swipe_v1);
155  Q_EMIT p->q->updated(QSizeF(wl_fixed_to_double(dx), wl_fixed_to_double(dy)), time);
156 }
157 
158 void PointerSwipeGesture::Private::endCallback(void *data,
159  zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1,
160  uint32_t serial,
161  uint32_t time,
162  int32_t cancelled)
163 {
164  auto p = reinterpret_cast<PointerSwipeGesture::Private *>(data);
165  Q_ASSERT(p->pointerswipegesture == zwp_pointer_gesture_swipe_v1);
166  if (cancelled) {
167  Q_EMIT p->q->cancelled(serial, time);
168  } else {
169  Q_EMIT p->q->ended(serial, time);
170  }
171  p->fingerCount = 0;
172  p->surface.clear();
173 }
174 
175 PointerSwipeGesture::Private::Private(PointerSwipeGesture *q)
176  : q(q)
177 {
178 }
179 
180 PointerSwipeGesture::PointerSwipeGesture(QObject *parent)
181  : QObject(parent)
182  , d(new Private(this))
183 {
184 }
185 
186 PointerSwipeGesture::~PointerSwipeGesture()
187 {
188  release();
189 }
190 
192 {
193  return d->fingerCount;
194 }
195 
197 {
198  return d->surface;
199 }
200 
201 void PointerSwipeGesture::Private::setup(zwp_pointer_gesture_swipe_v1 *pg)
202 {
203  Q_ASSERT(pg);
204  Q_ASSERT(!pointerswipegesture);
205  pointerswipegesture.setup(pg);
206  zwp_pointer_gesture_swipe_v1_add_listener(pointerswipegesture, &s_listener, this);
207 }
208 
209 void PointerSwipeGesture::setup(zwp_pointer_gesture_swipe_v1 *pointerswipegesture)
210 {
211  d->setup(pointerswipegesture);
212 }
213 
215 {
216  d->pointerswipegesture.release();
217 }
218 
220 {
221  d->pointerswipegesture.destroy();
222 }
223 
224 PointerSwipeGesture::operator zwp_pointer_gesture_swipe_v1 *()
225 {
226  return d->pointerswipegesture;
227 }
228 
229 PointerSwipeGesture::operator zwp_pointer_gesture_swipe_v1 *() const
230 {
231  return d->pointerswipegesture;
232 }
233 
235 {
236  return d->pointerswipegesture.isValid();
237 }
238 
239 class Q_DECL_HIDDEN PointerPinchGesture::Private
240 {
241 public:
242  Private(PointerPinchGesture *q);
243 
244  void setup(zwp_pointer_gesture_pinch_v1 *pg);
245 
246  WaylandPointer<zwp_pointer_gesture_pinch_v1, zwp_pointer_gesture_pinch_v1_destroy> pointerpinchgesture;
247  quint32 fingerCount = 0;
248  QPointer<Surface> surface;
249 
250 private:
251  static void beginCallback(void *data,
252  zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1,
253  uint32_t serial,
254  uint32_t time,
255  wl_surface *surface,
256  uint32_t fingers);
257  static void updateCallback(void *data,
258  zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1,
259  uint32_t time,
260  wl_fixed_t dx,
261  wl_fixed_t dy,
262  wl_fixed_t scale,
263  wl_fixed_t rotation);
264  static void endCallback(void *data, zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, int32_t cancelled);
265 
267  static const zwp_pointer_gesture_pinch_v1_listener s_listener;
268 };
269 
270 const zwp_pointer_gesture_pinch_v1_listener PointerPinchGesture::Private::s_listener = {beginCallback, updateCallback, endCallback};
271 
272 void PointerPinchGesture::Private::beginCallback(void *data,
273  zwp_pointer_gesture_pinch_v1 *pg,
274  uint32_t serial,
275  uint32_t time,
276  wl_surface *surface,
277  uint32_t fingers)
278 {
279  auto p = reinterpret_cast<PointerPinchGesture::Private *>(data);
280  Q_ASSERT(p->pointerpinchgesture == pg);
281  p->fingerCount = fingers;
282  p->surface = QPointer<Surface>(Surface::get(surface));
283  Q_EMIT p->q->started(serial, time);
284 }
285 
286 void PointerPinchGesture::Private::updateCallback(void *data,
287  zwp_pointer_gesture_pinch_v1 *pg,
288  uint32_t time,
289  wl_fixed_t dx,
290  wl_fixed_t dy,
291  wl_fixed_t scale,
292  wl_fixed_t rotation)
293 {
294  auto p = reinterpret_cast<PointerPinchGesture::Private *>(data);
295  Q_ASSERT(p->pointerpinchgesture == pg);
296  Q_EMIT p->q->updated(QSizeF(wl_fixed_to_double(dx), wl_fixed_to_double(dy)), wl_fixed_to_double(scale), wl_fixed_to_double(rotation), time);
297 }
298 
299 void PointerPinchGesture::Private::endCallback(void *data, zwp_pointer_gesture_pinch_v1 *pg, uint32_t serial, uint32_t time, int32_t cancelled)
300 {
301  auto p = reinterpret_cast<PointerPinchGesture::Private *>(data);
302  Q_ASSERT(p->pointerpinchgesture == pg);
303  if (cancelled) {
304  Q_EMIT p->q->cancelled(serial, time);
305  } else {
306  Q_EMIT p->q->ended(serial, time);
307  }
308  p->fingerCount = 0;
309  p->surface.clear();
310 }
311 
312 PointerPinchGesture::Private::Private(PointerPinchGesture *q)
313  : q(q)
314 {
315 }
316 
317 PointerPinchGesture::PointerPinchGesture(QObject *parent)
318  : QObject(parent)
319  , d(new Private(this))
320 {
321 }
322 
323 PointerPinchGesture::~PointerPinchGesture()
324 {
325  release();
326 }
327 
328 void PointerPinchGesture::Private::setup(zwp_pointer_gesture_pinch_v1 *pg)
329 {
330  Q_ASSERT(pg);
331  Q_ASSERT(!pointerpinchgesture);
332  pointerpinchgesture.setup(pg);
333  zwp_pointer_gesture_pinch_v1_add_listener(pointerpinchgesture, &s_listener, this);
334 }
335 
336 void PointerPinchGesture::setup(zwp_pointer_gesture_pinch_v1 *pointerpinchgesture)
337 {
338  d->setup(pointerpinchgesture);
339 }
340 
342 {
343  d->pointerpinchgesture.release();
344 }
345 
347 {
348  d->pointerpinchgesture.destroy();
349 }
350 
351 PointerPinchGesture::operator zwp_pointer_gesture_pinch_v1 *()
352 {
353  return d->pointerpinchgesture;
354 }
355 
356 PointerPinchGesture::operator zwp_pointer_gesture_pinch_v1 *() const
357 {
358  return d->pointerpinchgesture;
359 }
360 
362 {
363  return d->pointerpinchgesture.isValid();
364 }
365 
367 {
368  return d->fingerCount;
369 }
370 
372 {
373  return d->surface;
374 }
375 
376 }
377 }
void destroy()
Destroys the data held by this PointerPinchGesture.
void release()
Releases the zwp_pointer_gesture_swipe_v1 interface.
static Surface * get(wl_surface *native)
Definition: surface.cpp:212
void setup(zwp_pointer_gesture_pinch_v1 *pointerpinchgesture)
Setup this PointerPinchGesture to manage the pointerpinchgesture.
QPointer< Surface > surface() const
The Surface on which this gesture is performed.
quint32 fingerCount() const
The number of fingers taking part in this gesture.
void release()
Releases the zwp_pointer_gestures_v1 interface.
This class is a wrapper for the zwp_pointer_gesture_swipe_v1 protocol.
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:54
PointerPinchGesture * createPinchGesture(Pointer *pointer, QObject *parent=nullptr)
Creates a PointerPinchGesture for the given pointer with the parent.
QPointer< Surface > surface() const
The Surface on which this gesture is performed.
This class is a wrapper for the zwp_pointer_gesture_pinch_v1 protocol.
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating objects with this PointerGestures.
quint32 fingerCount() const
The number of fingers taking part in this gesture.
Wrapper for the wl_pointer interface.
Definition: pointer.h:31
PointerSwipeGesture * createSwipeGesture(Pointer *pointer, QObject *parent=nullptr)
Creates a PointerSwipeGesture for the given pointer with the parent.
void release()
Releases the zwp_pointer_gesture_pinch_v1 interface.
void destroy()
Destroys the data held by this PointerGestures.
void setup(zwp_pointer_gestures_v1 *pointergestures)
Setup this PointerGestures to manage the pointergestures.
PointerGestures(QObject *parent=nullptr)
Creates a new PointerGestures.
void setup(zwp_pointer_gesture_swipe_v1 *pointerswipegesture)
Setup this PointerSwipeGesture to manage the pointerswipegesture.
void destroy()
Destroys the data held by this PointerSwipeGesture.
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:56:22 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.