Skip to content

Instantly share code, notes, and snippets.

@torarnv
Created December 11, 2017 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torarnv/419861f23ea7528ac52d677b129d4da7 to your computer and use it in GitHub Desktop.
Save torarnv/419861f23ea7528ac52d677b129d4da7 to your computer and use it in GitHub Desktop.
commit ae32c14edccae744c3a66d9384caa62b15e66194
Author: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Date: Mon Dec 11 16:17:30 2017 +0100
macOS: Transition to momentum-based wheel scrolling without Qt::ScrollEnd
We detect if there's an upcoming momentum phase, and if so skip sending
Qt::ScrollEnd. The event is not guaranteed to be in the queue, but in
practice it is. This is the same trick used by e.g. Mozilla in their
event handling.
See also http://bit.ly/2BA77uq
Task-number: QTBUG-63026
Change-Id: I80191a472f6fa892387004c199166a6350124274
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 2e64204fb7..0490dc90ee 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -1470,8 +1470,13 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
m_scrolling = true;
} else if (phase == NSEventPhaseEnded || phase == NSEventPhaseCancelled ||
momentumPhase == NSEventPhaseEnded || momentumPhase == NSEventPhaseCancelled) {
- ph = Qt::ScrollEnd;
- m_scrolling = false;
+ bool upcomingMomentumPhase = phase == NSEventPhaseEnded &&
+ [NSApp nextEventMatchingMask:NSScrollWheelMask untilDate:[NSDate distantPast]
+ inMode:@"QtMomementumEventSearchMode" dequeue:NO].momentumPhase == NSEventPhaseBegan;
+ if (!upcomingMomentumPhase) {
+ ph = Qt::ScrollEnd;
+ m_scrolling = false;
+ }
} else if (phase == NSEventPhaseNone && momentumPhase == NSEventPhaseNone) {
ph = Qt::NoScrollPhase;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment