From 2e1191845679b937bed5f04979287c26e5578e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 5 Jan 2022 15:34:58 +0100 Subject: [PATCH] macOS: Handle momentum scroll NSEventPhaseBegan when scroll had ended We use nextEventMatchingMask to look for future momentum scroll events when the non-momentum scroll ends, to continue the scroll uninterrupted from the perspective of client code. But we're not guaranteed to find a future momentum scroll event, as observed on macOS 12.1, so if we then see a momentum NSEventPhaseBegan we need to treat it as a scroll begin from Qt's perspective. Fixes: QTBUG-97841 Pick-to: 6.3 6.2 5.15 Change-Id: I412abe0891660eda32a42a08d7dc7dee9eaa73aa Reviewed-by: Shawn Rutledge Reviewed-by: Timur Pocheptsov Reviewed-by: Volker Hilsheimer --- src/plugins/platforms/cocoa/qnsview_mouse.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm index a82955b1f3..d977867890 100644 --- a/src/plugins/platforms/cocoa/qnsview_mouse.mm +++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm @@ -721,7 +721,11 @@ static const QPointingDevice *pointingDeviceFor(qint64 deviceID) } } else if (theEvent.momentumPhase == NSEventPhaseBegan) { Q_ASSERT(!pixelDelta.isNull() && !angleDelta.isNull()); - phase = Qt::ScrollUpdate; // Send as update, it has a delta + // If we missed finding a momentum NSEventPhaseBegan when the non-momentum + // phase ended we need to treat this as a scroll begin, to not confuse client + // code. Otherwise we treat it as a continuation of the existing scroll. + phase = m_scrolling ? Qt::ScrollUpdate : Qt::ScrollBegin; + m_scrolling = true; } else if (theEvent.momentumPhase == NSEventPhaseChanged) { phase = Qt::ScrollMomentum; } else if (theEvent.phase == NSEventPhaseCancelled