KWaylandServer

pointergestures_v1_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Martin Gräßlin <[email protected]>
3  SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 
8 #include "pointergestures_v1_interface.h"
9 #include "clientconnection.h"
10 #include "display.h"
11 #include "pointer_interface_p.h"
12 #include "pointergestures_v1_interface_p.h"
13 #include "seat_interface.h"
14 #include "surface_interface.h"
15 
16 namespace KWaylandServer
17 {
18 static const int s_version = 2;
19 
20 PointerGesturesV1InterfacePrivate::PointerGesturesV1InterfacePrivate(Display *display)
21  : QtWaylandServer::zwp_pointer_gestures_v1(*display, s_version)
22 {
23 }
24 
25 void PointerGesturesV1InterfacePrivate::zwp_pointer_gestures_v1_get_swipe_gesture(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource)
26 {
27  PointerInterface *pointer = PointerInterface::get(pointer_resource);
28  if (!pointer) {
29  wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, "invalid pointer");
30  return;
31  }
32 
33  PointerSwipeGestureV1Interface *swipeGesture = PointerSwipeGestureV1Interface::get(pointer);
34  swipeGesture->add(resource->client(), id, resource->version());
35 }
36 
37 void PointerGesturesV1InterfacePrivate::zwp_pointer_gestures_v1_get_pinch_gesture(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource)
38 {
39  PointerInterface *pointer = PointerInterface::get(pointer_resource);
40  if (!pointer) {
41  wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, "invalid pointer");
42  return;
43  }
44 
45  PointerPinchGestureV1Interface *pinchGesture = PointerPinchGestureV1Interface::get(pointer);
46  pinchGesture->add(resource->client(), id, resource->version());
47 }
48 
49 void PointerGesturesV1InterfacePrivate::zwp_pointer_gestures_v1_release(Resource *resource)
50 {
51  wl_resource_destroy(resource->handle);
52 }
53 
54 PointerGesturesV1Interface::PointerGesturesV1Interface(Display *display, QObject *parent)
55  : QObject(parent)
56  , d(new PointerGesturesV1InterfacePrivate(display))
57 {
58 }
59 
60 PointerGesturesV1Interface::~PointerGesturesV1Interface()
61 {
62 }
63 
64 PointerSwipeGestureV1Interface::PointerSwipeGestureV1Interface(PointerInterface *pointer)
65  : pointer(pointer)
66 {
67 }
68 
69 PointerSwipeGestureV1Interface *PointerSwipeGestureV1Interface::get(PointerInterface *pointer)
70 {
71  if (pointer) {
72  PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer);
73  return pointerPrivate->swipeGesturesV1.data();
74  }
75  return nullptr;
76 }
77 
78 void PointerSwipeGestureV1Interface::zwp_pointer_gesture_swipe_v1_destroy(Resource *resource)
79 {
80  wl_resource_destroy(resource->handle);
81 }
82 
83 void PointerSwipeGestureV1Interface::sendBegin(quint32 serial, quint32 fingerCount)
84 {
85  if (focusedClient) {
86  return;
87  }
88  if (!pointer->focusedSurface()) {
89  return;
90  }
91 
92  const SurfaceInterface *focusedSurface = pointer->focusedSurface();
93  focusedClient = focusedSurface->client();
94  SeatInterface *seat = pointer->seat();
95 
96  const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client());
97  for (Resource *swipeResource : swipeResources) {
98  if (swipeResource->client() == focusedClient->client()) {
99  send_begin(swipeResource->handle, serial, seat->timestamp(), focusedSurface->resource(), fingerCount);
100  }
101  }
102 }
103 
104 void PointerSwipeGestureV1Interface::sendUpdate(const QSizeF &delta)
105 {
106  if (!focusedClient) {
107  return;
108  }
109 
110  SeatInterface *seat = pointer->seat();
111 
112  const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client());
113  for (Resource *swipeResource : swipeResources) {
114  if (swipeResource->client() == focusedClient->client()) {
115  send_update(swipeResource->handle, seat->timestamp(), wl_fixed_from_double(delta.width()), wl_fixed_from_double(delta.height()));
116  }
117  }
118 }
119 
120 void PointerSwipeGestureV1Interface::sendEnd(quint32 serial)
121 {
122  if (!focusedClient) {
123  return;
124  }
125 
126  SeatInterface *seat = pointer->seat();
127 
128  const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client());
129  for (Resource *swipeResource : swipeResources) {
130  if (swipeResource->client() == focusedClient->client()) {
131  send_end(swipeResource->handle, serial, seat->timestamp(), false);
132  }
133  }
134 
135  // The gesture session has been just finished, reset the cached focused client.
136  focusedClient = nullptr;
137 }
138 
139 void PointerSwipeGestureV1Interface::sendCancel(quint32 serial)
140 {
141  if (!focusedClient) {
142  return;
143  }
144 
145  SeatInterface *seat = pointer->seat();
146 
147  const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client());
148  for (Resource *swipeResource : swipeResources) {
149  if (swipeResource->client() == focusedClient->client()) {
150  send_end(swipeResource->handle, serial, seat->timestamp(), true);
151  }
152  }
153 
154  // The gesture session has been just finished, reset the cached focused client.
155  focusedClient = nullptr;
156 }
157 
158 PointerPinchGestureV1Interface::PointerPinchGestureV1Interface(PointerInterface *pointer)
159  : pointer(pointer)
160 {
161 }
162 
163 PointerPinchGestureV1Interface *PointerPinchGestureV1Interface::get(PointerInterface *pointer)
164 {
165  if (pointer) {
166  PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer);
167  return pointerPrivate->pinchGesturesV1.data();
168  }
169  return nullptr;
170 }
171 
172 void PointerPinchGestureV1Interface::zwp_pointer_gesture_pinch_v1_destroy(Resource *resource)
173 {
174  wl_resource_destroy(resource->handle);
175 }
176 
177 void PointerPinchGestureV1Interface::sendBegin(quint32 serial, quint32 fingerCount)
178 {
179  if (focusedClient) {
180  return; // gesture is already active
181  }
182  if (!pointer->focusedSurface()) {
183  return;
184  }
185 
186  const SurfaceInterface *focusedSurface = pointer->focusedSurface();
187  focusedClient = focusedSurface->client();
188  SeatInterface *seat = pointer->seat();
189 
190  const QList<Resource *> pinchResources = resourceMap().values(*focusedClient);
191  for (Resource *pinchResource : pinchResources) {
192  if (pinchResource->client() == focusedClient->client()) {
193  send_begin(pinchResource->handle, serial, seat->timestamp(), focusedSurface->resource(), fingerCount);
194  }
195  }
196 }
197 
198 void PointerPinchGestureV1Interface::sendUpdate(const QSizeF &delta, qreal scale, qreal rotation)
199 {
200  if (!focusedClient) {
201  return;
202  }
203 
204  SeatInterface *seat = pointer->seat();
205 
206  const QList<Resource *> pinchResources = resourceMap().values(*focusedClient);
207  for (Resource *pinchResource : pinchResources) {
208  if (pinchResource->client() == focusedClient->client()) {
209  send_update(pinchResource->handle,
210  seat->timestamp(),
211  wl_fixed_from_double(delta.width()),
212  wl_fixed_from_double(delta.height()),
213  wl_fixed_from_double(scale),
214  wl_fixed_from_double(rotation));
215  }
216  }
217 }
218 
219 void PointerPinchGestureV1Interface::sendEnd(quint32 serial)
220 {
221  if (!focusedClient) {
222  return;
223  }
224 
225  SeatInterface *seat = pointer->seat();
226 
227  const QList<Resource *> pinchResources = resourceMap().values(*focusedClient);
228  for (Resource *pinchResource : pinchResources) {
229  if (pinchResource->client() == focusedClient->client()) {
230  send_end(pinchResource->handle, serial, seat->timestamp(), false);
231  }
232  }
233 
234  // The gesture session has been just finished, reset the cached focused client.
235  focusedClient = nullptr;
236 }
237 
238 void PointerPinchGestureV1Interface::sendCancel(quint32 serial)
239 {
240  if (!focusedClient) {
241  return;
242  }
243 
244  SeatInterface *seat = pointer->seat();
245 
246  const QList<Resource *> pinchResources = resourceMap().values(*focusedClient);
247  for (Resource *pinchResource : pinchResources) {
248  if (pinchResource->client() == focusedClient->client()) {
249  send_end(pinchResource->handle, serial, seat->timestamp(), true);
250  }
251  }
252 
253  // The gesture session has been just finished, reset the cached focused client.
254  focusedClient = nullptr;
255 }
256 
257 } // namespace KWaylandServer
static PointerInterface * get(wl_resource *native)
qreal height() const const
QObject * parent() const const
qreal width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Oct 21 2021 23:10:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.