From fca50c5985ba54d0faaa2e87d4f67a605fd7a352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 23 Dec 2021 14:26:35 +0100 Subject: [PATCH] macOS: Sanitize scroll deltas for NSEventPhaseCancelled On macOS 12.1 the NSEventPhaseCancelled phase can in some situations report deltas, which causes the scroll to "jump". This happens for example when initiating a momentum-scroll, and then putting two fingers on the trackpad to cancel the momentum phase, which starts a new NSEventPhaseMayBegin phase. When then lifting the two fingers again, we get an NSEventPhaseCancelled event with deltas, but the deltas seem like uninitialized data (has a x-value, after doing a purely vertical scroll e.g.). Task-number: QTBUG-97841 Change-Id: I14e765b6111e53e7d3d0da219d4ac7fefe5243d0 Reviewed-by: Volker Hilsheimer (cherry picked from commit 2c3198ab5facdb5d36bd1513deeb15046fb61495) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/cocoa/qnsview_mouse.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm index 07edfab89cf..106092750b1 100644 --- a/src/plugins/platforms/cocoa/qnsview_mouse.mm +++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm @@ -737,6 +737,16 @@ static const QPointingDevice *pointingDeviceFor(qint64 deviceID) Q_ASSERT(theEvent.momentumPhase != NSEventPhaseStationary); } + // Sanitize deltas for events that should not result in scrolling. + // On macOS 12.1 this phase has been observed to report deltas. + if (theEvent.phase == NSEventPhaseCancelled) { + if (!pixelDelta.isNull() || !angleDelta.isNull()) { + qCInfo(lcQpaMouse) << "Ignoring unexpected delta for" << theEvent; + pixelDelta = QPoint(); + angleDelta = QPoint(); + } + } + // Prevent keyboard modifier state from changing during scroll event streams. // A two-finger trackpad flick generates a stream of scroll events. We want // the keyboard modifier state to be the state at the beginning of the