From 22973a2a05649c2cc55135aacb4e366037335a3a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 10:15:21 -0300 Subject: Support continuous macOS history swipes with command-only haptics Keep tracking after each history jump, use a shorter threshold for subsequent steps, and allow reversals without lifting. Stationary fingers and post-gesture momentum do not repeat commands. Remove preview haptic pulses so feedback accompanies navigation only. Update the guide and adapter regressions for repeated steps, reversals, cancellation, threshold reset and absence of preview pulses. Validated with the native adapter tests, macOS GUI release build, remote session rendering and digest checks, and user trackpad testing. --- src/gui/macos_trackpad.m | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'src/gui') 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; } -- cgit v1.3