diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui/macos_trackpad.m | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/gui/macos_trackpad.m b/src/gui/macos_trackpad.m index 64806b9e..76f6dba0 100644 --- a/src/gui/macos_trackpad.m +++ b/src/gui/macos_trackpad.m @@ -106,29 +106,35 @@ static void scroll(NSView *view, SEL selector, NSEvent *event) // the user's Swipe Between Pages preference. No guessed velocity. objc_setAssociatedObject(view, &swipe_key, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC); __weak NSView *weak_view = view; - __block BOOL cancelled = NO; - __block BOOL previewed = NO; - [event trackSwipeEventWithOptions:NSEventSwipeTrackingLockDirection | NSEventSwipeTrackingClampGestureAmount - dampenAmountThresholdMin:-1 max:1 + __block CGFloat origin = 0; + __block BOOL navigated = NO; + // Keep both directions available throughout the physical gesture. + // Wide dampening bounds avoid resistance after several steps. + [event trackSwipeEventWithOptions:0 + dampenAmountThresholdMin:-100 max:100 usingHandler:^(CGFloat amount, NSEventPhase phase, BOOL complete, BOOL *stop) { NSView *target = weak_view; if (!target) { *stop = YES; return; } - if (phase == NSEventPhaseCancelled) cancelled = YES; - // An early notch says the swipe is approaching the - // shorter commit distance, while the fingers still move. - if (!cancelled && !complete && !previewed && fabs(amount) >= 0.12) { - previewed = YES; - ui_macos_trackpad_haptic(); + if (phase == NSEventPhaseEnded || phase == NSEventPhaseCancelled || complete) { + objc_setAssociatedObject(target, &swipe_key, @NO, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + objc_setAssociatedObject(target, &suppress_momentum_key, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + *stop = YES; + return; + } + // Animation/momentum after the fingers lift never walks history. + if (phase == NSEventPhaseNone || !isfinite(amount)) return; + CGFloat distance = amount - origin; + CGFloat threshold = navigated ? 0.12 : 0.25; + // Retain the unspent distance; stationary callbacks do + // nothing, and reversing requires a deliberate short move. + while (fabs(distance) >= threshold) { + const NSInteger direction = distance > 0 ? 1 : -1; + send_gesture(target, event, UI_TRACKPAD_HISTORY, direction, 0, 0); + origin += direction * threshold; + navigated = YES; + threshold = 0.12; + distance = amount - origin; } - const BOOL commit = !cancelled && phase != NSEventPhaseNone && fabs(amount) >= 0.25; - if (!commit && !cancelled && phase != NSEventPhaseEnded && !complete) return; - objc_setAssociatedObject(target, &swipe_key, @NO, OBJC_ASSOCIATION_RETAIN_NONATOMIC); - objc_setAssociatedObject(target, &suppress_momentum_key, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC); - // Commit during the physical swipe. AppKit's later - // animation to +/-1 must not set our trigger distance. - *stop = YES; - if (commit) - send_gesture(target, event, UI_TRACKPAD_HISTORY, amount > 0 ? 1 : -1, 0, 0); }]; return; } |
