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 "display.h"
7 #include "pointer_interface_p.h"
8 #include "pointergestures_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 class PointerGesturesUnstableV1Interface::Private : public PointerGesturesInterface::Private
20 {
21 public:
22  Private(PointerGesturesUnstableV1Interface *q, Display *d);
23 
24 private:
25  void bind(wl_client *client, uint32_t version, uint32_t id) override;
26 
27  static void unbind(wl_resource *resource);
28  static Private *cast(wl_resource *r)
29  {
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 = {getSwipeGestureCallback, getPinchGestureCallback};
45 #endif
46 
47 void PointerGesturesUnstableV1Interface::Private::getSwipeGestureCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *pointer)
48 {
49  PointerInterface *p = PointerInterface::get(pointer);
50  if (!p) {
51  // TODO: raise error?
52  return;
53  }
54  auto m = cast(resource);
55  auto *g = new PointerSwipeGestureUnstableV1Interface(m->q, resource, p);
56  g->d->create(m->display->getConnection(client), version, id);
57  p->d_func()->registerSwipeGesture(g);
58 }
59 
60 void PointerGesturesUnstableV1Interface::Private::getPinchGestureCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *pointer)
61 {
62  PointerInterface *p = PointerInterface::get(pointer);
63  if (!p) {
64  // TODO: raise error?
65  return;
66  }
67  auto m = cast(resource);
68  auto *g = new PointerPinchGestureUnstableV1Interface(m->q, resource, p);
69  g->d->create(m->display->getConnection(client), version, id);
70  p->d_func()->registerPinchGesture(g);
71 }
72 
73 PointerGesturesUnstableV1Interface::Private::Private(PointerGesturesUnstableV1Interface *q, Display *d)
74  : PointerGesturesInterface::Private(PointerGesturesInterfaceVersion::UnstableV1, q, d, &zwp_pointer_gestures_v1_interface, s_version)
75  , q(q)
76 {
77 }
78 
79 void PointerGesturesUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
80 {
81  auto c = display->getConnection(client);
82  wl_resource *resource = c->createResource(&zwp_pointer_gestures_v1_interface, qMin(version, s_version), id);
83  if (!resource) {
84  wl_client_post_no_memory(client);
85  return;
86  }
87  wl_resource_set_implementation(resource, &s_interface, this, unbind);
88  // TODO: should we track?
89 }
90 
91 void PointerGesturesUnstableV1Interface::Private::unbind(wl_resource *resource)
92 {
93  Q_UNUSED(resource)
94  // TODO: implement?
95 }
96 
97 PointerGesturesUnstableV1Interface::PointerGesturesUnstableV1Interface(Display *display, QObject *parent)
98  : PointerGesturesInterface(new Private(this, display), parent)
99 {
100 }
101 
102 PointerGesturesUnstableV1Interface::~PointerGesturesUnstableV1Interface() = default;
103 
104 class PointerSwipeGestureUnstableV1Interface::Private : public PointerSwipeGestureInterface::Private
105 {
106 public:
107  Private(PointerSwipeGestureUnstableV1Interface *q, PointerGesturesUnstableV1Interface *c, wl_resource *parentResource, PointerInterface *pointer);
108  ~Private() override;
109 
110  void end(quint32 serial, bool end);
111 
112 private:
113  PointerSwipeGestureUnstableV1Interface *q_func()
114  {
115  return reinterpret_cast<PointerSwipeGestureUnstableV1Interface *>(q);
116  }
117 
118  static const struct zwp_pointer_gesture_swipe_v1_interface s_interface;
119 };
120 
121 #ifndef K_DOXYGEN
122 const struct zwp_pointer_gesture_swipe_v1_interface PointerSwipeGestureUnstableV1Interface::Private::s_interface = {resourceDestroyedCallback};
123 #endif
124 
125 PointerSwipeGestureUnstableV1Interface::Private::Private(PointerSwipeGestureUnstableV1Interface *q,
126  PointerGesturesUnstableV1Interface *c,
127  wl_resource *parentResource,
128  PointerInterface *pointer)
129  : PointerSwipeGestureInterface::Private(q, c, parentResource, &zwp_pointer_gesture_swipe_v1_interface, &s_interface, pointer)
130 {
131 }
132 
133 PointerSwipeGestureUnstableV1Interface::Private::~Private() = default;
134 
135 PointerSwipeGestureUnstableV1Interface::PointerSwipeGestureUnstableV1Interface(PointerGesturesUnstableV1Interface *parent,
136  wl_resource *parentResource,
137  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(), wl_fixed_from_double(delta.width()), wl_fixed_from_double(delta.height()));
165 }
166 
167 void PointerSwipeGestureUnstableV1Interface::Private::end(quint32 serial, bool cancel)
168 {
169  SeatInterface *seat = qobject_cast<SeatInterface *>(pointer->global());
170  if (!seat) {
171  return;
172  }
173  zwp_pointer_gesture_swipe_v1_send_end(resource, serial, seat->timestamp(), uint32_t(cancel));
174 }
175 
176 void PointerSwipeGestureUnstableV1Interface::end(quint32 serial)
177 {
178  Q_D();
179  d->end(serial, false);
180 }
181 
182 void PointerSwipeGestureUnstableV1Interface::cancel(quint32 serial)
183 {
184  Q_D();
185  d->end(serial, true);
186 }
187 
188 PointerSwipeGestureUnstableV1Interface::Private *PointerSwipeGestureUnstableV1Interface::d_func() const
189 {
190  return reinterpret_cast<Private *>(d.data());
191 }
192 
193 class PointerPinchGestureUnstableV1Interface::Private : public PointerPinchGestureInterface::Private
194 {
195 public:
196  Private(PointerPinchGestureUnstableV1Interface *q, PointerGesturesUnstableV1Interface *c, wl_resource *parentResource, PointerInterface *pointer);
197  ~Private() override;
198 
199  void end(quint32 serial, bool end);
200 
201 private:
202  PointerPinchGestureUnstableV1Interface *q_func()
203  {
204  return reinterpret_cast<PointerPinchGestureUnstableV1Interface *>(q);
205  }
206 
207  static const struct zwp_pointer_gesture_pinch_v1_interface s_interface;
208 };
209 
210 #ifndef K_DOXYGEN
211 const struct zwp_pointer_gesture_pinch_v1_interface PointerPinchGestureUnstableV1Interface::Private::s_interface = {resourceDestroyedCallback};
212 #endif
213 
214 PointerPinchGestureUnstableV1Interface::Private::Private(PointerPinchGestureUnstableV1Interface *q,
215  PointerGesturesUnstableV1Interface *c,
216  wl_resource *parentResource,
217  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,
225  wl_resource *parentResource,
226  PointerInterface *pointer)
227  : PointerPinchGestureInterface(new Private(this, parent, parentResource, pointer))
228 {
229 }
230 
231 PointerPinchGestureUnstableV1Interface::~PointerPinchGestureUnstableV1Interface() = default;
232 
233 void PointerPinchGestureUnstableV1Interface::start(quint32 serial, quint32 fingerCount)
234 {
235  Q_D();
236  SeatInterface *seat = qobject_cast<SeatInterface *>(d->pointer->global());
237  if (!seat) {
238  return;
239  }
240  if (!seat->focusedPointerSurface()) {
241  return;
242  }
243  zwp_pointer_gesture_pinch_v1_send_begin(resource(), serial, seat->timestamp(), seat->focusedPointerSurface()->resource(), fingerCount);
244 }
245 
246 void PointerPinchGestureUnstableV1Interface::update(const QSizeF &delta, qreal scale, qreal rotation)
247 {
248  Q_D();
249  SeatInterface *seat = qobject_cast<SeatInterface *>(d->pointer->global());
250  if (!seat) {
251  return;
252  }
253  zwp_pointer_gesture_pinch_v1_send_update(resource(),
254  seat->timestamp(),
255  wl_fixed_from_double(delta.width()),
256  wl_fixed_from_double(delta.height()),
257  wl_fixed_from_double(scale),
258  wl_fixed_from_double(rotation));
259 }
260 
261 void PointerPinchGestureUnstableV1Interface::Private::end(quint32 serial, bool cancel)
262 {
263  SeatInterface *seat = qobject_cast<SeatInterface *>(pointer->global());
264  if (!seat) {
265  return;
266  }
267  zwp_pointer_gesture_pinch_v1_send_end(resource, serial, seat->timestamp(), uint32_t(cancel));
268 }
269 
270 void PointerPinchGestureUnstableV1Interface::end(quint32 serial)
271 {
272  Q_D();
273  d->end(serial, false);
274 }
275 
276 void PointerPinchGestureUnstableV1Interface::cancel(quint32 serial)
277 {
278  Q_D();
279  d->end(serial, true);
280 }
281 
282 PointerPinchGestureUnstableV1Interface::Private *PointerPinchGestureUnstableV1Interface::d_func() const
283 {
284  return reinterpret_cast<Private *>(d.data());
285 }
286 
287 }
288 }
qreal height() const const
static PointerInterface * get(wl_resource *native)
Q_SCRIPTABLE Q_NOREPLY void start()
PointerGesturesInterfaceVersion
Enum describing the interface versions the PointerGesturesInterface can support.
const QList< QKeySequence > & end()
Q_D(Todo)
qreal width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Jan 30 2023 03:56:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.