From 388e6659a7a00a659456ac8f36c0523096a27684 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 5 Jun 2023 15:57:49 +0100 Subject: [PATCH] client: Guard against client destruction in gestures Client code can delete a window at any point. Any gesture events, including a "begin" event can be already in flight before the compositor is aware of the window destruction. It's up to the client code to handle either the focus not being initially found or the QPointer resetting and no-op. Task-number: QTBUG-113145 Pick-to: 6.6 6.5 Change-Id: Ie2c01799bd38c6f295159876a1bcd018abe60188 Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../wayland/qwaylandpointergestures.cpp | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandpointergestures.cpp b/src/plugins/platforms/wayland/qwaylandpointergestures.cpp index df43c31e907..1cdd97edde0 100644 --- a/src/plugins/platforms/wayland/qwaylandpointergestures.cpp +++ b/src/plugins/platforms/wayland/qwaylandpointergestures.cpp @@ -41,8 +41,11 @@ void QWaylandPointerGestureSwipe::zwp_pointer_gesture_swipe_v1_begin(uint32_t se uint32_t fingers) { #ifndef QT_NO_GESTURES - mParent->mSerial = serial; mFocus = QWaylandWindow::fromWlSurface(surface); + if (!mFocus) { + return; + } + mParent->mSerial = serial; mFingers = fingers; const auto* pointer = mParent->pointer(); @@ -62,6 +65,9 @@ void QWaylandPointerGestureSwipe::zwp_pointer_gesture_swipe_v1_update(uint32_t t wl_fixed_t dx, wl_fixed_t dy) { #ifndef QT_NO_GESTURES + if (!mFocus) { + return; + } const auto* pointer = mParent->pointer(); const QPointF delta = QPointF(wl_fixed_to_double(dx), wl_fixed_to_double(dy)); @@ -79,6 +85,9 @@ void QWaylandPointerGestureSwipe::zwp_pointer_gesture_swipe_v1_end(uint32_t seri int32_t cancelled) { #ifndef QT_NO_GESTURES + if (!mFocus) { + return; + } mParent->mSerial = serial; const auto* pointer = mParent->pointer(); @@ -113,11 +122,13 @@ void QWaylandPointerGesturePinch::zwp_pointer_gesture_pinch_v1_begin(uint32_t se uint32_t fingers) { #ifndef QT_NO_GESTURES - mParent->mSerial = serial; mFocus = QWaylandWindow::fromWlSurface(surface); + if (!mFocus) { + return; + } + mParent->mSerial = serial; mFingers = fingers; mLastScale = 1; - const auto* pointer = mParent->pointer(); qCDebug(lcQpaWaylandInput) << "zwp_pointer_gesture_pinch_v1_begin @ " @@ -137,6 +148,9 @@ void QWaylandPointerGesturePinch::zwp_pointer_gesture_pinch_v1_update(uint32_t t wl_fixed_t rotation) { #ifndef QT_NO_GESTURES + if (!mFocus) { + return; + } const auto* pointer = mParent->pointer(); const qreal rscale = wl_fixed_to_double(scale); @@ -161,6 +175,9 @@ void QWaylandPointerGesturePinch::zwp_pointer_gesture_pinch_v1_end(uint32_t seri int32_t cancelled) { #ifndef QT_NO_GESTURES + if (!mFocus) { + return; + } mParent->mSerial = serial; const auto* pointer = mParent->pointer();