File indexing completed on 2024-11-10 04:57:31
0001 /* 0002 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org> 0003 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include "pointergestures_v1.h" 0009 #include "clientconnection.h" 0010 #include "display.h" 0011 #include "pointer_p.h" 0012 #include "pointergestures_v1_p.h" 0013 #include "seat.h" 0014 #include "surface.h" 0015 0016 namespace KWin 0017 { 0018 static const int s_version = 3; 0019 0020 PointerGesturesV1InterfacePrivate::PointerGesturesV1InterfacePrivate(Display *display) 0021 : QtWaylandServer::zwp_pointer_gestures_v1(*display, s_version) 0022 { 0023 } 0024 0025 void PointerGesturesV1InterfacePrivate::zwp_pointer_gestures_v1_get_swipe_gesture(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource) 0026 { 0027 PointerInterface *pointer = PointerInterface::get(pointer_resource); 0028 if (!pointer) { 0029 wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, "invalid pointer"); 0030 return; 0031 } 0032 0033 PointerSwipeGestureV1Interface *swipeGesture = PointerSwipeGestureV1Interface::get(pointer); 0034 swipeGesture->add(resource->client(), id, resource->version()); 0035 } 0036 0037 void PointerGesturesV1InterfacePrivate::zwp_pointer_gestures_v1_get_pinch_gesture(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource) 0038 { 0039 PointerInterface *pointer = PointerInterface::get(pointer_resource); 0040 if (!pointer) { 0041 wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, "invalid pointer"); 0042 return; 0043 } 0044 0045 PointerPinchGestureV1Interface *pinchGesture = PointerPinchGestureV1Interface::get(pointer); 0046 pinchGesture->add(resource->client(), id, resource->version()); 0047 } 0048 0049 void PointerGesturesV1InterfacePrivate::zwp_pointer_gestures_v1_get_hold_gesture(Resource *resource, uint32_t id, struct ::wl_resource *pointer_resource) 0050 { 0051 PointerInterface *pointer = PointerInterface::get(pointer_resource); 0052 if (!pointer) { 0053 wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, 0054 "invalid pointer"); 0055 return; 0056 } 0057 0058 PointerHoldGestureV1Interface *holdGesture = PointerHoldGestureV1Interface::get(pointer); 0059 holdGesture->add(resource->client(), id, resource->version()); 0060 } 0061 0062 void PointerGesturesV1InterfacePrivate::zwp_pointer_gestures_v1_release(Resource *resource) 0063 { 0064 wl_resource_destroy(resource->handle); 0065 } 0066 0067 PointerGesturesV1Interface::PointerGesturesV1Interface(Display *display, QObject *parent) 0068 : QObject(parent) 0069 , d(new PointerGesturesV1InterfacePrivate(display)) 0070 { 0071 } 0072 0073 PointerGesturesV1Interface::~PointerGesturesV1Interface() 0074 { 0075 } 0076 0077 PointerSwipeGestureV1Interface::PointerSwipeGestureV1Interface(PointerInterface *pointer) 0078 : pointer(pointer) 0079 { 0080 } 0081 0082 PointerSwipeGestureV1Interface *PointerSwipeGestureV1Interface::get(PointerInterface *pointer) 0083 { 0084 if (pointer) { 0085 PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer); 0086 return pointerPrivate->swipeGesturesV1.get(); 0087 } 0088 return nullptr; 0089 } 0090 0091 void PointerSwipeGestureV1Interface::zwp_pointer_gesture_swipe_v1_destroy(Resource *resource) 0092 { 0093 wl_resource_destroy(resource->handle); 0094 } 0095 0096 void PointerSwipeGestureV1Interface::sendBegin(quint32 serial, quint32 fingerCount) 0097 { 0098 if (focusedClient) { 0099 return; 0100 } 0101 if (!pointer->focusedSurface()) { 0102 return; 0103 } 0104 0105 const SurfaceInterface *focusedSurface = pointer->focusedSurface(); 0106 focusedClient = focusedSurface->client(); 0107 SeatInterface *seat = pointer->seat(); 0108 0109 const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client()); 0110 for (Resource *swipeResource : swipeResources) { 0111 send_begin(swipeResource->handle, serial, seat->timestamp().count(), focusedSurface->resource(), fingerCount); 0112 } 0113 } 0114 0115 void PointerSwipeGestureV1Interface::sendUpdate(const QPointF &delta) 0116 { 0117 if (!focusedClient) { 0118 return; 0119 } 0120 0121 SeatInterface *seat = pointer->seat(); 0122 0123 const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client()); 0124 for (Resource *swipeResource : swipeResources) { 0125 send_update(swipeResource->handle, seat->timestamp().count(), wl_fixed_from_double(delta.x()), wl_fixed_from_double(delta.y())); 0126 } 0127 } 0128 0129 void PointerSwipeGestureV1Interface::sendEnd(quint32 serial) 0130 { 0131 if (!focusedClient) { 0132 return; 0133 } 0134 0135 SeatInterface *seat = pointer->seat(); 0136 0137 const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client()); 0138 for (Resource *swipeResource : swipeResources) { 0139 send_end(swipeResource->handle, serial, seat->timestamp().count(), false); 0140 } 0141 0142 // The gesture session has been just finished, reset the cached focused client. 0143 focusedClient = nullptr; 0144 } 0145 0146 void PointerSwipeGestureV1Interface::sendCancel(quint32 serial) 0147 { 0148 if (!focusedClient) { 0149 return; 0150 } 0151 0152 SeatInterface *seat = pointer->seat(); 0153 0154 const QList<Resource *> swipeResources = resourceMap().values(focusedClient->client()); 0155 for (Resource *swipeResource : swipeResources) { 0156 send_end(swipeResource->handle, serial, seat->timestamp().count(), true); 0157 } 0158 0159 // The gesture session has been just finished, reset the cached focused client. 0160 focusedClient = nullptr; 0161 } 0162 0163 PointerPinchGestureV1Interface::PointerPinchGestureV1Interface(PointerInterface *pointer) 0164 : pointer(pointer) 0165 { 0166 } 0167 0168 PointerPinchGestureV1Interface *PointerPinchGestureV1Interface::get(PointerInterface *pointer) 0169 { 0170 if (pointer) { 0171 PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer); 0172 return pointerPrivate->pinchGesturesV1.get(); 0173 } 0174 return nullptr; 0175 } 0176 0177 void PointerPinchGestureV1Interface::zwp_pointer_gesture_pinch_v1_destroy(Resource *resource) 0178 { 0179 wl_resource_destroy(resource->handle); 0180 } 0181 0182 void PointerPinchGestureV1Interface::sendBegin(quint32 serial, quint32 fingerCount) 0183 { 0184 if (focusedClient) { 0185 return; // gesture is already active 0186 } 0187 if (!pointer->focusedSurface()) { 0188 return; 0189 } 0190 0191 const SurfaceInterface *focusedSurface = pointer->focusedSurface(); 0192 focusedClient = focusedSurface->client(); 0193 SeatInterface *seat = pointer->seat(); 0194 0195 const QList<Resource *> pinchResources = resourceMap().values(*focusedClient); 0196 for (Resource *pinchResource : pinchResources) { 0197 send_begin(pinchResource->handle, serial, seat->timestamp().count(), focusedSurface->resource(), fingerCount); 0198 } 0199 } 0200 0201 void PointerPinchGestureV1Interface::sendUpdate(const QPointF &delta, qreal scale, qreal rotation) 0202 { 0203 if (!focusedClient) { 0204 return; 0205 } 0206 0207 SeatInterface *seat = pointer->seat(); 0208 0209 const QList<Resource *> pinchResources = resourceMap().values(*focusedClient); 0210 for (Resource *pinchResource : pinchResources) { 0211 send_update(pinchResource->handle, 0212 seat->timestamp().count(), 0213 wl_fixed_from_double(delta.x()), 0214 wl_fixed_from_double(delta.y()), 0215 wl_fixed_from_double(scale), 0216 wl_fixed_from_double(rotation)); 0217 } 0218 } 0219 0220 void PointerPinchGestureV1Interface::sendEnd(quint32 serial) 0221 { 0222 if (!focusedClient) { 0223 return; 0224 } 0225 0226 SeatInterface *seat = pointer->seat(); 0227 0228 const QList<Resource *> pinchResources = resourceMap().values(*focusedClient); 0229 for (Resource *pinchResource : pinchResources) { 0230 send_end(pinchResource->handle, serial, seat->timestamp().count(), false); 0231 } 0232 0233 // The gesture session has been just finished, reset the cached focused client. 0234 focusedClient = nullptr; 0235 } 0236 0237 void PointerPinchGestureV1Interface::sendCancel(quint32 serial) 0238 { 0239 if (!focusedClient) { 0240 return; 0241 } 0242 0243 SeatInterface *seat = pointer->seat(); 0244 0245 const QList<Resource *> pinchResources = resourceMap().values(*focusedClient); 0246 for (Resource *pinchResource : pinchResources) { 0247 send_end(pinchResource->handle, serial, seat->timestamp().count(), true); 0248 } 0249 0250 // The gesture session has been just finished, reset the cached focused client. 0251 focusedClient = nullptr; 0252 } 0253 0254 PointerHoldGestureV1Interface::PointerHoldGestureV1Interface(PointerInterface *pointer) 0255 : pointer(pointer) 0256 { 0257 } 0258 0259 PointerHoldGestureV1Interface *PointerHoldGestureV1Interface::get(PointerInterface *pointer) 0260 { 0261 if (pointer) { 0262 PointerInterfacePrivate *pointerPrivate = PointerInterfacePrivate::get(pointer); 0263 return pointerPrivate->holdGesturesV1.get(); 0264 } 0265 return nullptr; 0266 } 0267 0268 void PointerHoldGestureV1Interface::zwp_pointer_gesture_hold_v1_destroy(Resource *resource) 0269 { 0270 wl_resource_destroy(resource->handle); 0271 } 0272 0273 void PointerHoldGestureV1Interface::sendBegin(quint32 serial, quint32 fingerCount) 0274 { 0275 if (focusedClient) { 0276 return; // gesture is already active 0277 } 0278 if (!pointer->focusedSurface()) { 0279 return; 0280 } 0281 0282 const SurfaceInterface *focusedSurface = pointer->focusedSurface(); 0283 focusedClient = focusedSurface->client(); 0284 SeatInterface *seat = pointer->seat(); 0285 0286 const QList<Resource *> holdResources = resourceMap().values(*focusedClient); 0287 for (Resource *holdResource : holdResources) { 0288 send_begin(holdResource->handle, serial, seat->timestamp().count(), focusedSurface->resource(), fingerCount); 0289 } 0290 } 0291 0292 void PointerHoldGestureV1Interface::sendEnd(quint32 serial) 0293 { 0294 if (!focusedClient) { 0295 return; 0296 } 0297 0298 SeatInterface *seat = pointer->seat(); 0299 0300 const QList<Resource *> holdResources = resourceMap().values(*focusedClient); 0301 for (Resource *holdResource : holdResources) { 0302 send_end(holdResource->handle, serial, seat->timestamp().count(), false); 0303 } 0304 0305 // The gesture session has been just finished, reset the cached focused client. 0306 focusedClient = nullptr; 0307 } 0308 0309 void PointerHoldGestureV1Interface::sendCancel(quint32 serial) 0310 { 0311 if (!focusedClient) { 0312 return; 0313 } 0314 0315 SeatInterface *seat = pointer->seat(); 0316 0317 const QList<Resource *> holdResources = resourceMap().values(*focusedClient); 0318 for (Resource *holdResource : holdResources) { 0319 send_end(holdResource->handle, serial, seat->timestamp().count(), true); 0320 } 0321 0322 // The gesture session has been just finished, reset the cached focused client. 0323 focusedClient = nullptr; 0324 } 0325 0326 } // namespace KWin 0327 0328 #include "moc_pointergestures_v1.cpp"