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 "pointer.h"
8 #include "event_queue.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 
21 class Q_DECL_HIDDEN PointerGestures::Private
22 {
23 public:
24  Private() = default;
25 
26  WaylandPointer<zwp_pointer_gestures_v1, zwp_pointer_gestures_v1_destroy> pointergestures;
27  EventQueue *queue = nullptr;
28 };
29 
31  : QObject(parent)
32  , d(new Private)
33 {
34 }
35 
36 PointerGestures::~PointerGestures()
37 {
38  release();
39 }
40 
41 void PointerGestures::setup(zwp_pointer_gestures_v1 *pointergestures)
42 {
43  Q_ASSERT(pointergestures);
44  Q_ASSERT(!d->pointergestures);
45  d->pointergestures.setup(pointergestures);
46 }
47 
49 {
50  d->pointergestures.release();
51 }
52 
54 {
55  d->pointergestures.destroy();
56 }
57 
58 PointerGestures::operator zwp_pointer_gestures_v1*() {
59  return d->pointergestures;
60 }
61 
62 PointerGestures::operator zwp_pointer_gestures_v1*() const {
63  return d->pointergestures;
64 }
65 
67 {
68  return d->pointergestures.isValid();
69 }
70 
72 {
73  d->queue = queue;
74 }
75 
77 {
78  return d->queue;
79 }
80 
82 {
83  Q_ASSERT(isValid());
85  auto w = zwp_pointer_gestures_v1_get_swipe_gesture(d->pointergestures, *pointer);
86  if (d->queue) {
87  d->queue->addProxy(w);
88  }
89  p->setup(w);
90  return p;
91 }
92 
94 {
95  Q_ASSERT(isValid());
97  auto w = zwp_pointer_gestures_v1_get_pinch_gesture(d->pointergestures, *pointer);
98  if (d->queue) {
99  d->queue->addProxy(w);
100  }
101  p->setup(w);
102  return p;
103 }
104 
105 class Q_DECL_HIDDEN PointerSwipeGesture::Private
106 {
107 public:
108  Private(PointerSwipeGesture *q);
109 
110  void setup(zwp_pointer_gesture_swipe_v1 *pg);
111 
112  WaylandPointer<zwp_pointer_gesture_swipe_v1, zwp_pointer_gesture_swipe_v1_destroy> pointerswipegesture;
113  quint32 fingerCount = 0;
114  QPointer<Surface> surface;
115 
116 private:
117  static void beginCallback(void *data, zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1, uint32_t serial, uint32_t time, wl_surface *surface, uint32_t fingers);
118  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);
119  static void endCallback(void *data, zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1, uint32_t serial, uint32_t time, int32_t cancelled);
120 
121  PointerSwipeGesture *q;
122  static const zwp_pointer_gesture_swipe_v1_listener s_listener;
123 };
124 
125 const zwp_pointer_gesture_swipe_v1_listener PointerSwipeGesture::Private::s_listener = {
126  beginCallback,
127  updateCallback,
128  endCallback
129 };
130 
131 void PointerSwipeGesture::Private::beginCallback(void *data, zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1, uint32_t serial, uint32_t time, wl_surface *surface, uint32_t fingers)
132 {
133  auto p = reinterpret_cast<PointerSwipeGesture::Private*>(data);
134  Q_ASSERT(p->pointerswipegesture == zwp_pointer_gesture_swipe_v1);
135  p->fingerCount = fingers;
136  p->surface = QPointer<Surface>(Surface::get(surface));
137  emit p->q->started(serial, time);
138 }
139 
140 void PointerSwipeGesture::Private::updateCallback(void *data, zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1, uint32_t time, wl_fixed_t dx, wl_fixed_t dy)
141 {
142  auto p = reinterpret_cast<PointerSwipeGesture::Private*>(data);
143  Q_ASSERT(p->pointerswipegesture == zwp_pointer_gesture_swipe_v1);
144  emit p->q->updated(QSizeF(wl_fixed_to_double(dx), wl_fixed_to_double(dy)), time);
145 }
146 
147 void PointerSwipeGesture::Private::endCallback(void *data, zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1, uint32_t serial, uint32_t time, int32_t cancelled)
148 {
149  auto p = reinterpret_cast<PointerSwipeGesture::Private*>(data);
150  Q_ASSERT(p->pointerswipegesture == zwp_pointer_gesture_swipe_v1);
151  if (cancelled) {
152  emit p->q->cancelled(serial, time);
153  } else {
154  emit p->q->ended(serial, time);
155  }
156  p->fingerCount = 0;
157  p->surface.clear();
158 }
159 
160 PointerSwipeGesture::Private::Private(PointerSwipeGesture *q)
161  : q(q)
162 {
163 }
164 
165 PointerSwipeGesture::PointerSwipeGesture(QObject *parent)
166  : QObject(parent)
167  , d(new Private(this))
168 {
169 }
170 
171 PointerSwipeGesture::~PointerSwipeGesture()
172 {
173  release();
174 }
175 
177 {
178  return d->fingerCount;
179 }
180 
182 {
183  return d->surface;
184 }
185 
186 void PointerSwipeGesture::Private::setup(zwp_pointer_gesture_swipe_v1 *pg)
187 {
188  Q_ASSERT(pg);
189  Q_ASSERT(!pointerswipegesture);
190  pointerswipegesture.setup(pg);
191  zwp_pointer_gesture_swipe_v1_add_listener(pointerswipegesture, &s_listener, this);
192 }
193 
194 void PointerSwipeGesture::setup(zwp_pointer_gesture_swipe_v1 *pointerswipegesture)
195 {
196  d->setup(pointerswipegesture);
197 }
198 
200 {
201  d->pointerswipegesture.release();
202 }
203 
205 {
206  d->pointerswipegesture.destroy();
207 }
208 
209 PointerSwipeGesture::operator zwp_pointer_gesture_swipe_v1*() {
210  return d->pointerswipegesture;
211 }
212 
213 PointerSwipeGesture::operator zwp_pointer_gesture_swipe_v1*() const {
214  return d->pointerswipegesture;
215 }
216 
218 {
219  return d->pointerswipegesture.isValid();
220 }
221 
222 class Q_DECL_HIDDEN PointerPinchGesture::Private
223 {
224 public:
225  Private(PointerPinchGesture *q);
226 
227  void setup(zwp_pointer_gesture_pinch_v1 *pg);
228 
229  WaylandPointer<zwp_pointer_gesture_pinch_v1, zwp_pointer_gesture_pinch_v1_destroy> pointerpinchgesture;
230  quint32 fingerCount = 0;
231  QPointer<Surface> surface;
232 
233 private:
234  static void beginCallback(void *data, zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, wl_surface *surface, uint32_t fingers);
235  static void updateCallback(void *data, zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1, uint32_t time, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t scale, wl_fixed_t rotation);
236  static void endCallback(void *data, zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, int32_t cancelled);
237 
238  PointerPinchGesture *q;
239  static const zwp_pointer_gesture_pinch_v1_listener s_listener;
240 };
241 
242 const zwp_pointer_gesture_pinch_v1_listener PointerPinchGesture::Private::s_listener = {
243  beginCallback,
244  updateCallback,
245  endCallback
246 };
247 
248 void PointerPinchGesture::Private::beginCallback(void *data, zwp_pointer_gesture_pinch_v1 *pg, uint32_t serial, uint32_t time, wl_surface *surface, uint32_t fingers)
249 {
250  auto p = reinterpret_cast<PointerPinchGesture::Private*>(data);
251  Q_ASSERT(p->pointerpinchgesture == pg);
252  p->fingerCount = fingers;
253  p->surface = QPointer<Surface>(Surface::get(surface));
254  emit p->q->started(serial, time);
255 }
256 
257 void PointerPinchGesture::Private::updateCallback(void *data, zwp_pointer_gesture_pinch_v1 *pg, uint32_t time, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t scale, wl_fixed_t rotation)
258 {
259  auto p = reinterpret_cast<PointerPinchGesture::Private*>(data);
260  Q_ASSERT(p->pointerpinchgesture == pg);
261  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);
262 }
263 
264 void PointerPinchGesture::Private::endCallback(void *data, zwp_pointer_gesture_pinch_v1 *pg, uint32_t serial, uint32_t time, int32_t cancelled)
265 {
266  auto p = reinterpret_cast<PointerPinchGesture::Private*>(data);
267  Q_ASSERT(p->pointerpinchgesture == pg);
268  if (cancelled) {
269  emit p->q->cancelled(serial, time);
270  } else {
271  emit p->q->ended(serial, time);
272  }
273  p->fingerCount = 0;
274  p->surface.clear();
275 }
276 
277 PointerPinchGesture::Private::Private(PointerPinchGesture *q)
278  : q(q)
279 {
280 }
281 
282 PointerPinchGesture::PointerPinchGesture(QObject *parent)
283  : QObject(parent)
284  , d(new Private(this))
285 {
286 }
287 
288 PointerPinchGesture::~PointerPinchGesture()
289 {
290  release();
291 }
292 
293 void PointerPinchGesture::Private::setup(zwp_pointer_gesture_pinch_v1 *pg)
294 {
295  Q_ASSERT(pg);
296  Q_ASSERT(!pointerpinchgesture);
297  pointerpinchgesture.setup(pg);
298  zwp_pointer_gesture_pinch_v1_add_listener(pointerpinchgesture, &s_listener, this);
299 }
300 
301 void PointerPinchGesture::setup(zwp_pointer_gesture_pinch_v1 *pointerpinchgesture)
302 {
303  d->setup(pointerpinchgesture);
304 }
305 
307 {
308  d->pointerpinchgesture.release();
309 }
310 
312 {
313  d->pointerpinchgesture.destroy();
314 }
315 
316 PointerPinchGesture::operator zwp_pointer_gesture_pinch_v1*() {
317  return d->pointerpinchgesture;
318 }
319 
320 PointerPinchGesture::operator zwp_pointer_gesture_pinch_v1*() const {
321  return d->pointerpinchgesture;
322 }
323 
325 {
326  return d->pointerpinchgesture.isValid();
327 }
328 
330 {
331  return d->fingerCount;
332 }
333 
335 {
336  return d->surface;
337 }
338 
339 }
340 }
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating objects with this PointerGestures.
PointerGestures(QObject *parent=nullptr)
Creates a new PointerGestures.
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:55
void release()
Releases the zwp_pointer_gesture_pinch_v1 interface.
QPointer< Surface > surface() const
The Surface on which this gesture is performed.
This class is a wrapper for the zwp_pointer_gesture_swipe_v1 protocol.
void release()
Releases the zwp_pointer_gesture_swipe_v1 interface.
void setup(zwp_pointer_gesture_swipe_v1 *pointerswipegesture)
Setup this PointerSwipeGesture to manage the pointerswipegesture.
void destroy()
Destroys the data held by this PointerSwipeGesture.
QPointer< Surface > surface() const
The Surface on which this gesture is performed.
PointerPinchGesture * createPinchGesture(Pointer *pointer, QObject *parent=nullptr)
Creates a PointerPinchGesture for the given pointer with the parent.
This class is a wrapper for the zwp_pointer_gesture_pinch_v1 protocol.
Wrapper for the wl_pointer interface.
Definition: pointer.h:32
quint32 fingerCount() const
The number of fingers taking part in this gesture.
quint32 fingerCount() const
The number of fingers taking part in this gesture.
QObject(QObject *parent)
void setup(zwp_pointer_gestures_v1 *pointergestures)
Setup this PointerGestures to manage the pointergestures.
void setup(zwp_pointer_gesture_pinch_v1 *pointerpinchgesture)
Setup this PointerPinchGesture to manage the pointerpinchgesture.
PointerSwipeGesture * createSwipeGesture(Pointer *pointer, QObject *parent=nullptr)
Creates a PointerSwipeGesture for the given pointer with the parent.
void destroy()
Destroys the data held by this PointerPinchGesture.
void destroy()
Destroys the data held by this PointerGestures.
static Surface * get(wl_surface *native)
Definition: surface.cpp:286
void release()
Releases the zwp_pointer_gestures_v1 interface.
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 14 2020 22:49:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.