1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qwaylandpointergestures_p.h" |
5 | #include "qwaylanddisplay_p.h" |
6 | #include "qwaylandinputdevice_p.h" |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | namespace QtWaylandClient { |
11 | |
12 | QWaylandPointerGestures::QWaylandPointerGestures(QWaylandDisplay *display, uint id, uint version) |
13 | : zwp_pointer_gestures_v1(display->wl_registry(), id, qMin(version, uint(1))) |
14 | { |
15 | } |
16 | |
17 | QWaylandPointerGestures::~QWaylandPointerGestures() noexcept |
18 | { |
19 | if (version() >= ZWP_POINTER_GESTURES_V1_RELEASE_SINCE_VERSION) |
20 | release(); |
21 | else |
22 | zwp_pointer_gestures_v1_destroy(object()); |
23 | } |
24 | |
25 | QWaylandPointerGestureSwipe * |
26 | QWaylandPointerGestures::createPointerGestureSwipe(QWaylandInputDevice *device) |
27 | { |
28 | return new QWaylandPointerGestureSwipe(device); |
29 | } |
30 | |
31 | QWaylandPointerGesturePinch * |
32 | QWaylandPointerGestures::createPointerGesturePinch(QWaylandInputDevice *device) |
33 | { |
34 | return new QWaylandPointerGesturePinch(device); |
35 | } |
36 | |
37 | QWaylandPointerGestureSwipe::QWaylandPointerGestureSwipe(QWaylandInputDevice *p) |
38 | : mParent(p) |
39 | { |
40 | } |
41 | |
42 | QWaylandPointerGestureSwipe::~QWaylandPointerGestureSwipe() |
43 | { |
44 | destroy(); |
45 | } |
46 | |
47 | void QWaylandPointerGestureSwipe::zwp_pointer_gesture_swipe_v1_begin(uint32_t serial, uint32_t time, |
48 | struct ::wl_surface *surface, |
49 | uint32_t fingers) |
50 | { |
51 | #ifndef QT_NO_GESTURES |
52 | mFocus = QWaylandWindow::fromWlSurface(surface); |
53 | if (!mFocus) { |
54 | return; |
55 | } |
56 | mParent->mSerial = serial; |
57 | mFingers = fingers; |
58 | |
59 | const auto* pointer = mParent->pointer(); |
60 | |
61 | qCDebug(lcQpaWaylandInput) << "zwp_pointer_gesture_swipe_v1_begin @ " |
62 | << pointer->mSurfacePos << "fingers"<< fingers; |
63 | |
64 | auto e = QWaylandPointerGestureSwipeEvent(mFocus, Qt::GestureStarted, time, |
65 | pointer->mSurfacePos, pointer->mGlobalPos, mFingers, |
66 | QPointF()); |
67 | |
68 | mFocus->handleSwipeGesture(inputDevice: mParent, e); |
69 | #endif |
70 | } |
71 | |
72 | void QWaylandPointerGestureSwipe::zwp_pointer_gesture_swipe_v1_update(uint32_t time, |
73 | wl_fixed_t dx, wl_fixed_t dy) |
74 | { |
75 | #ifndef QT_NO_GESTURES |
76 | if (!mFocus) { |
77 | return; |
78 | } |
79 | const auto* pointer = mParent->pointer(); |
80 | |
81 | const QPointF delta = QPointF(wl_fixed_to_double(dx), wl_fixed_to_double(dy)); |
82 | qCDebug(lcQpaWaylandInput) << "zwp_pointer_gesture_swipe_v1_update @ " |
83 | << pointer->mSurfacePos << "delta"<< delta; |
84 | |
85 | auto e = QWaylandPointerGestureSwipeEvent(mFocus, Qt::GestureUpdated, time, |
86 | pointer->mSurfacePos, pointer->mGlobalPos, mFingers, delta); |
87 | |
88 | mFocus->handleSwipeGesture(inputDevice: mParent, e: e); |
89 | #endif |
90 | } |
91 | |
92 | void QWaylandPointerGestureSwipe::zwp_pointer_gesture_swipe_v1_end(uint32_t serial, uint32_t time, |
93 | int32_t cancelled) |
94 | { |
95 | #ifndef QT_NO_GESTURES |
96 | if (!mFocus) { |
97 | return; |
98 | } |
99 | mParent->mSerial = serial; |
100 | const auto* pointer = mParent->pointer(); |
101 | |
102 | qCDebug(lcQpaWaylandInput) << "zwp_pointer_gesture_swipe_v1_end @ " |
103 | << pointer->mSurfacePos << (cancelled ? "CANCELED": ""); |
104 | |
105 | auto gestureType = cancelled ? Qt::GestureFinished : Qt::GestureCanceled; |
106 | |
107 | auto e = QWaylandPointerGestureSwipeEvent(mFocus, gestureType, time, |
108 | pointer->mSurfacePos, pointer->mGlobalPos, mFingers, |
109 | QPointF()); |
110 | |
111 | mFocus->handleSwipeGesture(inputDevice: mParent, e); |
112 | |
113 | mFocus.clear(); |
114 | mFingers = 0; |
115 | #endif |
116 | } |
117 | |
118 | QWaylandPointerGesturePinch::QWaylandPointerGesturePinch(QWaylandInputDevice *p) |
119 | : mParent(p) |
120 | { |
121 | } |
122 | |
123 | QWaylandPointerGesturePinch::~QWaylandPointerGesturePinch() |
124 | { |
125 | destroy(); |
126 | } |
127 | |
128 | void QWaylandPointerGesturePinch::zwp_pointer_gesture_pinch_v1_begin(uint32_t serial, uint32_t time, |
129 | struct ::wl_surface *surface, |
130 | uint32_t fingers) |
131 | { |
132 | #ifndef QT_NO_GESTURES |
133 | mFocus = QWaylandWindow::fromWlSurface(surface); |
134 | if (!mFocus) { |
135 | return; |
136 | } |
137 | mParent->mSerial = serial; |
138 | mFingers = fingers; |
139 | mLastScale = 1; |
140 | const auto* pointer = mParent->pointer(); |
141 | |
142 | qCDebug(lcQpaWaylandInput) << "zwp_pointer_gesture_pinch_v1_begin @ " |
143 | << pointer->mSurfacePos << "fingers"<< fingers; |
144 | |
145 | auto e = QWaylandPointerGesturePinchEvent(mFocus, Qt::GestureStarted, time, |
146 | pointer->mSurfacePos, pointer->mGlobalPos, mFingers, |
147 | QPointF(), 0, 0); |
148 | |
149 | mFocus->handlePinchGesture(inputDevice: mParent, e); |
150 | #endif |
151 | } |
152 | |
153 | void QWaylandPointerGesturePinch::zwp_pointer_gesture_pinch_v1_update(uint32_t time, |
154 | wl_fixed_t dx, wl_fixed_t dy, |
155 | wl_fixed_t scale, |
156 | wl_fixed_t rotation) |
157 | { |
158 | #ifndef QT_NO_GESTURES |
159 | if (!mFocus) { |
160 | return; |
161 | } |
162 | const auto* pointer = mParent->pointer(); |
163 | |
164 | const qreal rscale = wl_fixed_to_double(scale); |
165 | const qreal rot = wl_fixed_to_double(rotation); |
166 | const QPointF delta = QPointF(wl_fixed_to_double(dx), wl_fixed_to_double(dy)); |
167 | qCDebug(lcQpaWaylandInput) << "zwp_pointer_gesture_pinch_v1_update @ " |
168 | << pointer->mSurfacePos << "delta"<< delta |
169 | << "scale"<< mLastScale << "->"<< rscale |
170 | << "delta"<< rscale - mLastScale << "rot"<< rot; |
171 | |
172 | auto e = QWaylandPointerGesturePinchEvent(mFocus, Qt::GestureUpdated, time, |
173 | pointer->mSurfacePos, pointer->mGlobalPos, mFingers, |
174 | delta, rscale - mLastScale, rot); |
175 | |
176 | mFocus->handlePinchGesture(inputDevice: mParent, e: e); |
177 | |
178 | mLastScale = rscale; |
179 | #endif |
180 | } |
181 | |
182 | void QWaylandPointerGesturePinch::zwp_pointer_gesture_pinch_v1_end(uint32_t serial, uint32_t time, |
183 | int32_t cancelled) |
184 | { |
185 | #ifndef QT_NO_GESTURES |
186 | if (!mFocus) { |
187 | return; |
188 | } |
189 | mParent->mSerial = serial; |
190 | const auto* pointer = mParent->pointer(); |
191 | |
192 | qCDebug(lcQpaWaylandInput) << "zwp_pointer_gesture_swipe_v1_end @ " |
193 | << pointer->mSurfacePos << (cancelled ? "CANCELED": ""); |
194 | |
195 | auto gestureType = cancelled ? Qt::GestureFinished : Qt::GestureCanceled; |
196 | |
197 | auto e = QWaylandPointerGesturePinchEvent(mFocus, gestureType, time, |
198 | pointer->mSurfacePos, pointer->mGlobalPos, mFingers, |
199 | QPointF(), 0, 0); |
200 | |
201 | mFocus->handlePinchGesture(inputDevice: mParent, e); |
202 | |
203 | mFocus.clear(); |
204 | mFingers = 0; |
205 | mLastScale = 1; |
206 | #endif |
207 | } |
208 | |
209 | } // namespace QtWaylandClient |
210 | |
211 | QT_END_NAMESPACE |
212 |
Definitions
- QWaylandPointerGestures
- ~QWaylandPointerGestures
- createPointerGestureSwipe
- createPointerGesturePinch
- QWaylandPointerGestureSwipe
- ~QWaylandPointerGestureSwipe
- zwp_pointer_gesture_swipe_v1_begin
- zwp_pointer_gesture_swipe_v1_update
- zwp_pointer_gesture_swipe_v1_end
- QWaylandPointerGesturePinch
- ~QWaylandPointerGesturePinch
- zwp_pointer_gesture_pinch_v1_begin
- zwp_pointer_gesture_pinch_v1_update
Learn Advanced QML with KDAB
Find out more