KWin
Loading...
Searching...
No Matches
pointergestures_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
3 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
9#include "clientconnection.h"
10#include "display.h"
11#include "pointer_p.h"
13#include "seat.h"
14#include "surface.h"
15
16namespace KWin
17{
18static const int s_version = 3;
19
21 : QtWaylandServer::zwp_pointer_gestures_v1(*display, s_version)
22{
23}
24
25void 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
34 swipeGesture->add(resource->client(), id, resource->version());
35}
36
37void 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
46 pinchGesture->add(resource->client(), id, resource->version());
47}
48
49void PointerGesturesV1InterfacePrivate::zwp_pointer_gestures_v1_get_hold_gesture(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource)
50{
51 PointerInterface *pointer = PointerInterface::get(pointer_resource);
52 if (!pointer) {
53 wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT,
54 "invalid pointer");
55 return;
56 }
57
59 holdGesture->add(resource->client(), id, resource->version());
60}
61
63{
64 wl_resource_destroy(resource->handle);
65}
66
68 : QObject(parent)
69 , d(new PointerGesturesV1InterfacePrivate(display))
70{
71}
72
76
81
83{
84 if (pointer) {
86 return pointerPrivate->swipeGesturesV1.get();
87 }
88 return nullptr;
89}
90
92{
93 wl_resource_destroy(resource->handle);
94}
95
96void PointerSwipeGestureV1Interface::sendBegin(quint32 serial, quint32 fingerCount)
97{
98 if (focusedClient) {
99 return;
100 }
101 if (!pointer->focusedSurface()) {
102 return;
103 }
104
105 const SurfaceInterface *focusedSurface = pointer->focusedSurface();
106 focusedClient = focusedSurface->client();
107 SeatInterface *seat = pointer->seat();
108
109 const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client());
110 for (Resource *swipeResource : swipeResources) {
111 send_begin(swipeResource->handle, serial, seat->timestamp().count(), focusedSurface->resource(), fingerCount);
112 }
113}
114
116{
117 if (!focusedClient) {
118 return;
119 }
120
121 SeatInterface *seat = pointer->seat();
122
123 const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client());
124 for (Resource *swipeResource : swipeResources) {
125 send_update(swipeResource->handle, seat->timestamp().count(), wl_fixed_from_double(delta.x()), wl_fixed_from_double(delta.y()));
126 }
127}
128
130{
131 if (!focusedClient) {
132 return;
133 }
134
135 SeatInterface *seat = pointer->seat();
136
137 const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client());
138 for (Resource *swipeResource : swipeResources) {
139 send_end(swipeResource->handle, serial, seat->timestamp().count(), false);
140 }
141
142 // The gesture session has been just finished, reset the cached focused client.
143 focusedClient = nullptr;
144}
145
147{
148 if (!focusedClient) {
149 return;
150 }
151
152 SeatInterface *seat = pointer->seat();
153
154 const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client());
155 for (Resource *swipeResource : swipeResources) {
156 send_end(swipeResource->handle, serial, seat->timestamp().count(), true);
157 }
158
159 // The gesture session has been just finished, reset the cached focused client.
160 focusedClient = nullptr;
161}
162
167
169{
170 if (pointer) {
171 PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer);
172 return pointerPrivate->pinchGesturesV1.get();
173 }
174 return nullptr;
175}
176
178{
179 wl_resource_destroy(resource->handle);
180}
181
182void PointerPinchGestureV1Interface::sendBegin(quint32 serial, quint32 fingerCount)
183{
184 if (focusedClient) {
185 return; // gesture is already active
186 }
187 if (!pointer->focusedSurface()) {
188 return;
189 }
190
191 const SurfaceInterface *focusedSurface = pointer->focusedSurface();
192 focusedClient = focusedSurface->client();
193 SeatInterface *seat = pointer->seat();
194
195 const QList<Resource *> pinchResources = resourceMap().values(*focusedClient);
196 for (Resource *pinchResource : pinchResources) {
197 send_begin(pinchResource->handle, serial, seat->timestamp().count(), focusedSurface->resource(), fingerCount);
198 }
199}
200
201void PointerPinchGestureV1Interface::sendUpdate(const QPointF &delta, qreal scale, qreal rotation)
202{
203 if (!focusedClient) {
204 return;
205 }
206
207 SeatInterface *seat = pointer->seat();
208
209 const QList<Resource *> pinchResources = resourceMap().values(*focusedClient);
210 for (Resource *pinchResource : pinchResources) {
211 send_update(pinchResource->handle,
212 seat->timestamp().count(),
213 wl_fixed_from_double(delta.x()),
214 wl_fixed_from_double(delta.y()),
215 wl_fixed_from_double(scale),
216 wl_fixed_from_double(rotation));
217 }
218}
219
221{
222 if (!focusedClient) {
223 return;
224 }
225
226 SeatInterface *seat = pointer->seat();
227
228 const QList<Resource *> pinchResources = resourceMap().values(*focusedClient);
229 for (Resource *pinchResource : pinchResources) {
230 send_end(pinchResource->handle, serial, seat->timestamp().count(), false);
231 }
232
233 // The gesture session has been just finished, reset the cached focused client.
234 focusedClient = nullptr;
235}
236
238{
239 if (!focusedClient) {
240 return;
241 }
242
243 SeatInterface *seat = pointer->seat();
244
245 const QList<Resource *> pinchResources = resourceMap().values(*focusedClient);
246 for (Resource *pinchResource : pinchResources) {
247 send_end(pinchResource->handle, serial, seat->timestamp().count(), true);
248 }
249
250 // The gesture session has been just finished, reset the cached focused client.
251 focusedClient = nullptr;
252}
253
258
260{
261 if (pointer) {
262 PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer);
263 return pointerPrivate->holdGesturesV1.get();
264 }
265 return nullptr;
266}
267
269{
270 wl_resource_destroy(resource->handle);
271}
272
273void PointerHoldGestureV1Interface::sendBegin(quint32 serial, quint32 fingerCount)
274{
275 if (focusedClient) {
276 return; // gesture is already active
277 }
278 if (!pointer->focusedSurface()) {
279 return;
280 }
281
282 const SurfaceInterface *focusedSurface = pointer->focusedSurface();
283 focusedClient = focusedSurface->client();
284 SeatInterface *seat = pointer->seat();
285
286 const QList<Resource *> holdResources = resourceMap().values(*focusedClient);
287 for (Resource *holdResource : holdResources) {
288 send_begin(holdResource->handle, serial, seat->timestamp().count(), focusedSurface->resource(), fingerCount);
289 }
290}
291
293{
294 if (!focusedClient) {
295 return;
296 }
297
298 SeatInterface *seat = pointer->seat();
299
300 const QList<Resource *> holdResources = resourceMap().values(*focusedClient);
301 for (Resource *holdResource : holdResources) {
302 send_end(holdResource->handle, serial, seat->timestamp().count(), false);
303 }
304
305 // The gesture session has been just finished, reset the cached focused client.
306 focusedClient = nullptr;
307}
308
310{
311 if (!focusedClient) {
312 return;
313 }
314
315 SeatInterface *seat = pointer->seat();
316
317 const QList<Resource *> holdResources = resourceMap().values(*focusedClient);
318 for (Resource *holdResource : holdResources) {
319 send_end(holdResource->handle, serial, seat->timestamp().count(), true);
320 }
321
322 // The gesture session has been just finished, reset the cached focused client.
323 focusedClient = nullptr;
324}
325
326} // namespace KWin
327
328#include "moc_pointergestures_v1.cpp"
Class holding the Wayland server display loop.
Definition display.h:34
PointerGesturesV1Interface(Display *display, QObject *parent=nullptr)
void zwp_pointer_gestures_v1_get_pinch_gesture(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource) override
void zwp_pointer_gestures_v1_get_swipe_gesture(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource) override
void zwp_pointer_gestures_v1_release(Resource *resource) override
void zwp_pointer_gestures_v1_get_hold_gesture(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource) override
void sendBegin(quint32 serial, quint32 fingerCount)
static PointerHoldGestureV1Interface * get(PointerInterface *pointer)
void zwp_pointer_gesture_hold_v1_destroy(Resource *resource) override
PointerHoldGestureV1Interface(PointerInterface *pointer)
SeatInterface * seat() const
Definition pointer.cpp:365
SurfaceInterface * focusedSurface() const
Definition pointer.cpp:158
static PointerInterface * get(wl_resource *native)
Definition pointer.cpp:370
std::unique_ptr< PointerHoldGestureV1Interface > holdGesturesV1
Definition pointer_p.h:73
std::unique_ptr< PointerSwipeGestureV1Interface > swipeGesturesV1
Definition pointer_p.h:71
std::unique_ptr< PointerPinchGestureV1Interface > pinchGesturesV1
Definition pointer_p.h:72
static PointerInterfacePrivate * get(PointerInterface *pointer)
Definition pointer.cpp:29
static PointerPinchGestureV1Interface * get(PointerInterface *pointer)
void zwp_pointer_gesture_pinch_v1_destroy(Resource *resource) override
PointerPinchGestureV1Interface(PointerInterface *pointer)
void sendUpdate(const QPointF &delta, qreal scale, qreal rotation)
void sendBegin(quint32 serial, quint32 fingerCount)
PointerSwipeGestureV1Interface(PointerInterface *pointer)
void sendBegin(quint32 serial, quint32 fingerCount)
static PointerSwipeGestureV1Interface * get(PointerInterface *pointer)
void zwp_pointer_gesture_swipe_v1_destroy(Resource *resource) override
Represents a Seat on the Wayland Display.
Definition seat.h:134
Resource representing a wl_surface.
Definition surface.h:80
ClientConnection * client() const
Definition surface.cpp:444
wl_resource * resource() const
Definition surface.cpp:449