KWayland

pointergestures_interface_v1.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_interface_p.h"
7 #include "display.h"
8 #include "pointer_interface_p.h"
9 #include "resource_p.h"
10 #include "seat_interface.h"
11 #include "surface_interface.h"
12 
13 #include <wayland-pointer-gestures-unstable-v1-server-protocol.h>
14 
15 namespace KWayland
16 {
17 namespace Server
18 {
19 
20 class PointerGesturesUnstableV1Interface::Private : public PointerGesturesInterface::Private
21 {
22 public:
23  Private(PointerGesturesUnstableV1Interface *q, Display *d);
24 
25 private:
26  void bind(wl_client *client, uint32_t version, uint32_t id) override;
27 
28  static void unbind(wl_resource *resource);
29  static Private *cast(wl_resource *r) {
30  return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
31  }
32 
33  static void getSwipeGestureCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * pointer);
34  static void getPinchGestureCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * pointer);
35 
36  PointerGesturesUnstableV1Interface *q;
37  static const struct zwp_pointer_gestures_v1_interface s_interface;
38  static const quint32 s_version;
39 };
40 
41 const quint32 PointerGesturesUnstableV1Interface::Private::s_version = 1;
42 
43 #ifndef K_DOXYGEN
44 const struct zwp_pointer_gestures_v1_interface PointerGesturesUnstableV1Interface::Private::s_interface = {
45  getSwipeGestureCallback,
46  getPinchGestureCallback
47 };
48 #endif
49 
50 void PointerGesturesUnstableV1Interface::Private::getSwipeGestureCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *pointer)
51 {
52  PointerInterface *p = PointerInterface::get(pointer);
53  if (!p) {
54  // TODO: raise error?
55  return;
56  }
57  auto m = cast(resource);
58  auto *g = new PointerSwipeGestureUnstableV1Interface(m->q, resource, p);
59  g->d->create(m->display->getConnection(client), version, id);
60  p->d_func()->registerSwipeGesture(g);
61 }
62 
63 void PointerGesturesUnstableV1Interface::Private::getPinchGestureCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * pointer)
64 {
65  PointerInterface *p = PointerInterface::get(pointer);
66  if (!p) {
67  // TODO: raise error?
68  return;
69  }
70  auto m = cast(resource);
71  auto *g = new PointerPinchGestureUnstableV1Interface(m->q, resource, p);
72  g->d->create(m->display->getConnection(client), version, id);
73  p->d_func()->registerPinchGesture(g);
74 }
75 
76 PointerGesturesUnstableV1Interface::Private::Private(PointerGesturesUnstableV1Interface *q, Display *d)
77  : PointerGesturesInterface::Private(PointerGesturesInterfaceVersion::UnstableV1, q, d, &zwp_pointer_gestures_v1_interface, s_version)
78  , q(q)
79 {
80 }
81 
82 void PointerGesturesUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
83 {
84  auto c = display->getConnection(client);
85  wl_resource *resource = c->createResource(&zwp_pointer_gestures_v1_interface, qMin(version, s_version), id);
86  if (!resource) {
87  wl_client_post_no_memory(client);
88  return;
89  }
90  wl_resource_set_implementation(resource, &s_interface, this, unbind);
91  // TODO: should we track?
92 }
93 
94 void PointerGesturesUnstableV1Interface::Private::unbind(wl_resource *resource)
95 {
96  Q_UNUSED(resource)
97  // TODO: implement?
98 }
99 
100 PointerGesturesUnstableV1Interface::PointerGesturesUnstableV1Interface(Display *display, QObject *parent)
101  : PointerGesturesInterface(new Private(this, display), parent)
102 {
103 }
104 
105 PointerGesturesUnstableV1Interface::~PointerGesturesUnstableV1Interface() = default;
106 
107 class PointerSwipeGestureUnstableV1Interface::Private : public PointerSwipeGestureInterface::Private
108 {
109 public:
110  Private(PointerSwipeGestureUnstableV1Interface *q, PointerGesturesUnstableV1Interface *c, wl_resource *parentResource, PointerInterface *pointer);
111  ~Private();
112 
113  void end(quint32 serial, bool end);
114 
115 private:
116 
117  PointerSwipeGestureUnstableV1Interface *q_func() {
118  return reinterpret_cast<PointerSwipeGestureUnstableV1Interface *>(q);
119  }
120 
121  static const struct zwp_pointer_gesture_swipe_v1_interface s_interface;
122 };
123 
124 #ifndef K_DOXYGEN
125 const struct zwp_pointer_gesture_swipe_v1_interface PointerSwipeGestureUnstableV1Interface::Private::s_interface = {
126  resourceDestroyedCallback
127 };
128 #endif
129 
130 PointerSwipeGestureUnstableV1Interface::Private::Private(PointerSwipeGestureUnstableV1Interface *q, PointerGesturesUnstableV1Interface *c, wl_resource *parentResource, PointerInterface *pointer)
131  : PointerSwipeGestureInterface::Private(q, c, parentResource, &zwp_pointer_gesture_swipe_v1_interface, &s_interface, pointer)
132 {
133 }
134 
135 PointerSwipeGestureUnstableV1Interface::Private::~Private() = default;
136 
137 PointerSwipeGestureUnstableV1Interface::PointerSwipeGestureUnstableV1Interface(PointerGesturesUnstableV1Interface *parent, wl_resource *parentResource, PointerInterface *pointer)
138  : PointerSwipeGestureInterface(new Private(this, parent, parentResource, pointer))
139 {
140 }
141 
142 PointerSwipeGestureUnstableV1Interface::~PointerSwipeGestureUnstableV1Interface() = default;
143 
144 void PointerSwipeGestureUnstableV1Interface::start(quint32 serial, quint32 fingerCount)
145 {
146  Q_D();
147  SeatInterface *seat = qobject_cast<SeatInterface*>(d->pointer->global());
148  if (!seat) {
149  return;
150  }
151  if (!seat->focusedPointerSurface()) {
152  return;
153  }
154  zwp_pointer_gesture_swipe_v1_send_begin(resource(), serial, seat->timestamp(), seat->focusedPointerSurface()->resource(), fingerCount);
155 }
156 
157 void PointerSwipeGestureUnstableV1Interface::update(const QSizeF &delta)
158 {
159  Q_D();
160  SeatInterface *seat = qobject_cast<SeatInterface*>(d->pointer->global());
161  if (!seat) {
162  return;
163  }
164  zwp_pointer_gesture_swipe_v1_send_update(resource(), seat->timestamp(),
165  wl_fixed_from_double(delta.width()), wl_fixed_from_double(delta.height()));
166 }
167 
168 void PointerSwipeGestureUnstableV1Interface::Private::end(quint32 serial, bool cancel)
169 {
170  SeatInterface *seat = qobject_cast<SeatInterface*>(pointer->global());
171  if (!seat) {
172  return;
173  }
174  zwp_pointer_gesture_swipe_v1_send_end(resource, serial, seat->timestamp(), uint32_t(cancel));
175 }
176 
177 void PointerSwipeGestureUnstableV1Interface::end(quint32 serial)
178 {
179  Q_D();
180  d->end(serial, false);
181 }
182 
183 void PointerSwipeGestureUnstableV1Interface::cancel(quint32 serial)
184 {
185  Q_D();
186  d->end(serial, true);
187 }
188 
189 PointerSwipeGestureUnstableV1Interface::Private *PointerSwipeGestureUnstableV1Interface::d_func() const
190 {
191  return reinterpret_cast<Private*>(d.data());
192 }
193 
194 class PointerPinchGestureUnstableV1Interface::Private : public PointerPinchGestureInterface::Private
195 {
196 public:
197  Private(PointerPinchGestureUnstableV1Interface *q, PointerGesturesUnstableV1Interface *c, wl_resource *parentResource, PointerInterface *pointer);
198  ~Private();
199 
200  void end(quint32 serial, bool end);
201 
202 private:
203 
204  PointerPinchGestureUnstableV1Interface *q_func() {
205  return reinterpret_cast<PointerPinchGestureUnstableV1Interface *>(q);
206  }
207 
208  static const struct zwp_pointer_gesture_pinch_v1_interface s_interface;
209 };
210 
211 #ifndef K_DOXYGEN
212 const struct zwp_pointer_gesture_pinch_v1_interface PointerPinchGestureUnstableV1Interface::Private::s_interface = {
213  resourceDestroyedCallback
214 };
215 #endif
216 
217 PointerPinchGestureUnstableV1Interface::Private::Private(PointerPinchGestureUnstableV1Interface *q, PointerGesturesUnstableV1Interface *c, wl_resource *parentResource, PointerInterface *pointer)
218  : PointerPinchGestureInterface::Private(q, c, parentResource, &zwp_pointer_gesture_pinch_v1_interface, &s_interface, pointer)
219 {
220 }
221 
222 PointerPinchGestureUnstableV1Interface::Private::~Private() = default;
223 
224 PointerPinchGestureUnstableV1Interface::PointerPinchGestureUnstableV1Interface(PointerGesturesUnstableV1Interface *parent, wl_resource *parentResource, PointerInterface *pointer)
225  : PointerPinchGestureInterface(new Private(this, parent, parentResource, pointer))
226 {
227 }
228 
229 PointerPinchGestureUnstableV1Interface::~PointerPinchGestureUnstableV1Interface() = default;
230 
231 void PointerPinchGestureUnstableV1Interface::start(quint32 serial, quint32 fingerCount)
232 {
233  Q_D();
234  SeatInterface *seat = qobject_cast<SeatInterface*>(d->pointer->global());
235  if (!seat) {
236  return;
237  }
238  if (!seat->focusedPointerSurface()) {
239  return;
240  }
241  zwp_pointer_gesture_pinch_v1_send_begin(resource(), serial, seat->timestamp(), seat->focusedPointerSurface()->resource(), fingerCount);
242 }
243 
244 void PointerPinchGestureUnstableV1Interface::update(const QSizeF &delta, qreal scale, qreal rotation)
245 {
246  Q_D();
247  SeatInterface *seat = qobject_cast<SeatInterface*>(d->pointer->global());
248  if (!seat) {
249  return;
250  }
251  zwp_pointer_gesture_pinch_v1_send_update(resource(), seat->timestamp(),
252  wl_fixed_from_double(delta.width()), wl_fixed_from_double(delta.height()),
253  wl_fixed_from_double(scale), wl_fixed_from_double(rotation));
254 }
255 
256 void PointerPinchGestureUnstableV1Interface::Private::end(quint32 serial, bool cancel)
257 {
258  SeatInterface *seat = qobject_cast<SeatInterface*>(pointer->global());
259  if (!seat) {
260  return;
261  }
262  zwp_pointer_gesture_pinch_v1_send_end(resource, serial, seat->timestamp(), uint32_t(cancel));
263 }
264 
265 void PointerPinchGestureUnstableV1Interface::end(quint32 serial)
266 {
267  Q_D();
268  d->end(serial, false);
269 }
270 
271 void PointerPinchGestureUnstableV1Interface::cancel(quint32 serial)
272 {
273  Q_D();
274  d->end(serial, true);
275 }
276 
277 PointerPinchGestureUnstableV1Interface::Private *PointerPinchGestureUnstableV1Interface::d_func() const
278 {
279  return reinterpret_cast<Private*>(d.data());
280 }
281 
282 }
283 }
ClientConnection * getConnection(wl_client *client)
Gets the ClientConnection for the given client.
Definition: display.cpp:592
static PointerInterface * get(wl_resource *native)
PointerGesturesInterfaceVersion
Enum describing the interface versions the PointerGesturesInterface can support.
T * data() const const
wl_resource * createResource(const wl_interface *interface, quint32 version, quint32 id)
Creates a new wl_resource for the provided interface.
const QList< QKeySequence > & end()
Display * display()
Definition: global.cpp:79
qreal height() const const
T qobject_cast(QObject *object)
QObject * parent() const const
qreal width() const const
KDB_EXPORT KDbVersionInfo version()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.