summaryrefslogtreecommitdiff
path: root/src/gui/macos_trackpad.m
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 10:15:21 -0300
committerGabriel Schneider <[email protected]>2026-11-05 10:15:21 -0300
commit22973a2a05649c2cc55135aacb4e366037335a3a (patch)
tree2b2a2a2e9faaa79a9156886cd075ec0462c6f351 /src/gui/macos_trackpad.m
parenta41360e3b9699268d73d598c6eb0155875d3a149 (diff)
downloadpardes-macos.tar.gz
pardes-macos.zip
Support continuous macOS history swipes with command-only hapticsmacos
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.
Diffstat (limited to 'src/gui/macos_trackpad.m')
-rw-r--r--src/gui/macos_trackpad.m44
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;
}