summaryrefslogtreecommitdiff
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
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.
-rw-r--r--docs/typ/guide.typ5
-rw-r--r--src/gui/macos_trackpad.m44
-rw-r--r--test/macos_trackpad.m37
3 files changed, 59 insertions, 27 deletions
diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ
index 4ac039c2..70f968de 100644
--- a/docs/typ/guide.typ
+++ b/docs/typ/guide.typ
@@ -85,8 +85,9 @@ pinch changes the window's font size at reduced gain; small pinch noise during
a twist is ignored. Rotation in normal mode steps through search matches,
with a haptic notch for each step. Horizontal page swipes, as configured in
macOS, run #word("Back") and #word("Forward") through the jump history, with a
-haptic cue approaching the short swipe threshold and another pulse when
-navigation is triggered. Shift or Option keeps horizontal
+single haptic pulse when navigation is triggered. Keep your fingers down to continue through history:
+after the first jump, shorter movements step again in either direction.
+Holding still does not repeat; lifting ends the gesture. Shift or Option keeps horizontal
scrolling instead of history swipes.
#btn("B3") on `src/bar.c:12:5:` in a compiler's error opens `src/bar.c` at
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;
}
diff --git a/test/macos_trackpad.m b/test/macos_trackpad.m
index 03c9d311..b37533ef 100644
--- a/test/macos_trackpad.m
+++ b/test/macos_trackpad.m
@@ -44,6 +44,7 @@ static BOOL swipe_enabled(id receiver, SEL selector)
@property BOOL precise;
@property BOOL horizontal, cancelled;
@property CGFloat progress, discreteDirection;
+@property NSArray<NSNumber *> *progressSequence;
@end
@implementation TrackpadEvent
- (NSPoint)locationInWindow { return NSMakePoint(25, 40); }
@@ -58,14 +59,18 @@ static BOOL swipe_enabled(id receiver, SEL selector)
dampenAmountThresholdMin:(CGFloat)min max:(CGFloat)max
usingHandler:(void (^)(CGFloat, NSEventPhase, BOOL, BOOL *))handler
{
- (void)options; assert(min == -1 && max == 1);
+ assert(options == 0 && min == -100 && max == 100);
BOOL stop = NO;
- handler(0.13, NSEventPhaseChanged, NO, &stop);
- handler(0.18, NSEventPhaseChanged, NO, &stop);
+ NSArray<NSNumber *> *samples = self.progressSequence ?: @[@0.13, @0.18];
+ for (NSNumber *sample in samples) {
+ handler(sample.doubleValue, NSEventPhaseChanged, NO, &stop);
+ assert(!stop); // a jump must not end physical tracking
+ }
if (self.cancelled) handler(self.progress, NSEventPhaseCancelled, NO, &stop);
- else handler(self.progress, NSEventPhaseChanged, NO, &stop);
+ else if (!self.progressSequence) handler(self.progress, NSEventPhaseChanged, NO, &stop);
if (!stop) handler(0, NSEventPhaseEnded, NO, &stop);
- if (!stop) handler(1, NSEventPhaseNone, YES, &stop);
+ assert(stop); // no native completion animation can cause another jump
+
}
- (NSInteger)stage { return 2; }
- (float)rotation { return 12; }
@@ -127,7 +132,7 @@ int main(void)
event.testPhase = NSEventPhaseBegan;
[view scrollWheel:event];
assert(count == 8);
- assert(haptic_spy.pulses == 1); // one early cue despite multiple progress events
+ assert(haptic_spy.pulses == 0); // command dispatch owns the haptic, never progress
assert(((UITrackpadEvent *)&queued[7])->kind == UI_TRACKPAD_HISTORY);
assert(((UITrackpadEvent *)&queued[7])->a == 1);
event.cancelled = YES;
@@ -154,7 +159,27 @@ int main(void)
event.testPhase = NSEventPhaseNone;
[view scrollWheel:event];
assert(count == 11); // remaining movement/momentum cannot jump twice
+ event.testPhase = NSEventPhaseBegan;
+ event.progressSequence = @[@0.13, @0.25, @0.25, @0.26, @0.38, @0.50,
+ @0.50, @0.37, @0.24, @0.12, @-0.01];
+ unsigned continuous_start = count;
+ [view scrollWheel:event];
+ assert(count == continuous_start + 7);
+ const int directions[] = {1, 1, 1, -1, -1, -1, -1};
+ for (unsigned i = 0; i < 7; ++i)
+ assert(((UITrackpadEvent *)&queued[continuous_start + i])->a == directions[i]);
+ // Lift resets the larger initial threshold for the next gesture.
+ event.progressSequence = @[@0.13, @0.20];
+ [view scrollWheel:event];
+ assert(count == continuous_start + 7);
+ event.progressSequence = @[@-0.13, @-0.25, @-0.25, @-0.26, @-0.38, @-0.50,
+ @-0.50, @-0.37, @-0.24, @-0.12, @0.01];
+ [view scrollWheel:event];
+ assert(count == continuous_start + 14);
+ for (unsigned i = 0; i < 7; ++i)
+ assert(((UITrackpadEvent *)&queued[continuous_start + 7 + i])->a == -directions[i]);
method_setImplementation(preference, old_preference);
+ assert(haptic_spy.pulses == 0); // no preview pulses, even across repeated/reversed swipes
NSUInteger before = haptic_spy.pulses;
ui_macos_trackpad_haptic();
method_setImplementation(performer, original);