Skip to content

Throttle scroll-triggered actions - #1414

Merged
lujjjh merged 1 commit into
mainfrom
fix/scroll-action-recognition
Oct 3, 2026
Merged

lujjjh merged 1 commit into
mainfrom
fix/scroll-action-recognition

Conversation

@lujjjh

@lujjjh lujjjh commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Apply a shared 300 ms throttle to discrete scroll actions across both axes, including high-resolution wheels. Keep scroll-output mappings distance-based and preserve their momentum through route and modifier changes.

Validated with 1,017 unit tests.

Closes #1028

Summary by CodeRabbit

  • New Features

    • Scroll-wheel button mappings now respond consistently across discrete and high-resolution scrolling, with repeated actions based on scroll distance.
    • Scroll gestures and cooldowns are coordinated across display routes, preserving momentum behavior as gestures move between routes.
    • Zoom shortcuts share scroll cooldowns with mapped actions, and momentum scrolling no longer triggers extra zoom presses.
  • Bug Fixes

    • Improved handling of scroll direction, modifier changes, and interrupted gestures to prevent unintended or repeated actions.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5297dde4-4613-4101-b3b0-0943bd4eee95
📥 Commits

Reviewing files that changed from the base of the PR and between b5c65eb and 0ba15da.

📒 Files selected for processing (16)
  • LinearMouse/EventTransformer/ButtonMappingEngine.swift
  • LinearMouse/EventTransformer/ButtonMappingTransformer.swift
  • LinearMouse/EventTransformer/EventTransformerManager.swift
  • LinearMouse/EventTransformer/ModifierActionsTransformer.swift
  • LinearMouse/EventTransformer/ScrollActionRecognizer.swift
  • LinearMouse/EventTransformer/ScrollActionThrottle.swift
  • LinearMouse/EventTransformer/ScrollGestureOwnership.swift
  • LinearMouse/EventTransformer/ScrollGestureTransformer.swift
  • LinearMouse/EventTransformer/ScrollInput.swift
  • LinearMouse/EventTransformer/ScrollMovementAccumulator.swift
  • LinearMouseUnitTests/EventTransformer/ButtonMappingTransformerTests.swift
  • LinearMouseUnitTests/EventTransformer/ModifierActionsTransformerTests.swift
  • LinearMouseUnitTests/EventTransformer/ScrollActionRecognizerTests.swift
  • LinearMouseUnitTests/EventTransformer/ScrollActionStateTests.swift
  • LinearMouseUnitTests/EventTransformer/ScrollGestureTransformerTests.swift
  • LinearMouseUnitTests/EventTransformer/ScrollMomentumMappingTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Wheel actions now use normalized scroll input, movement accumulation, and per-axis throttling. Transformer routes share gesture ownership and throttle state by device, including for modifier zoom actions. Momentum handling retains or releases ownership according to gesture state.

Changes

Scroll action flow

Layer / File(s) Summary
Normalize scroll input and track state
LinearMouse/EventTransformer/ScrollInput.swift, LinearMouse/EventTransformer/ScrollMovementAccumulator.swift, LinearMouse/EventTransformer/ScrollActionThrottle.swift, LinearMouse/EventTransformer/ScrollGestureOwnership.swift, LinearMouseUnitTests/EventTransformer/ScrollActionStateTests.swift
Scroll events are normalized by axis and units. Movement is accumulated per axis, and action timestamps are throttled per axis. Gesture ownership and state behavior are covered by tests.
Recognize and coalesce mapped scroll actions
LinearMouse/EventTransformer/ButtonMappingEngine.swift, LinearMouse/EventTransformer/ButtonMappingTransformer.swift, LinearMouse/EventTransformer/ScrollActionRecognizer.swift, LinearMouseUnitTests/EventTransformer/ButtonMappingTransformerTests.swift, LinearMouseUnitTests/EventTransformer/ScrollActionRecognizerTests.swift, LinearMouseUnitTests/EventTransformer/ScrollMomentumMappingTests.swift
Button mappings submit normalized scroll input for recognition. Repeating wheel actions accumulate movement and produce coalesced output, while selected mappings record their index. Tests cover throttling, recognition, and retained momentum.
Share gesture state across routes and zoom actions
LinearMouse/EventTransformer/EventTransformerManager.swift, LinearMouse/EventTransformer/ScrollGestureTransformer.swift, LinearMouse/EventTransformer/ModifierActionsTransformer.swift, LinearMouseUnitTests/EventTransformer/ModifierActionsTransformerTests.swift, LinearMouseUnitTests/EventTransformer/ScrollGestureTransformerTests.swift
Routes share throttle and gesture ownership by device. Scroll gesture handling and modifier zoom actions use the shared state. Tests cover route changes, momentum, and zoom throttling.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant ScrollGestureTransformer
  participant ButtonMappingTransformer
  participant ScrollInput
  participant ButtonMappingEngine
  participant ScrollActionRecognizer
  participant ScrollActionThrottle
  participant ScrollMovementAccumulator
  ScrollGestureTransformer->>ButtonMappingTransformer: Forward direct scroll event
  ButtonMappingTransformer->>ScrollInput: Normalize event by axis and units
  ButtonMappingTransformer->>ButtonMappingEngine: Select configured wheel mapping
  ButtonMappingEngine->>ButtonMappingTransformer: Return action and mapping index
  ButtonMappingTransformer->>ScrollActionRecognizer: Submit normalized input and mapped action
  ScrollActionRecognizer->>ScrollActionThrottle: Check per-axis action time
  ScrollActionRecognizer->>ScrollMovementAccumulator: Accumulate repeating movement
  ScrollActionRecognizer->>ButtonMappingTransformer: Return consumed step count and coalesced action
Loading

Merge Risk: ⚪ Minimal · up to 0ba15

This change adds a shared 300 ms cooldown for scroll-triggered actions and ties momentum handling to whichever action owns the scroll gesture. Unit tests cover the cooldown, route changes, and zoom behavior. No concrete defect was identified, so the change appears ready to merge.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 0ba15

The inspected changes preserve existing input filtering and action-execution controls while improving scroll-state continuity. No introduced security violation was established. Residual uncertainty concerns device attribution during a gesture and behavior outside the inspected desktop input path.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected security-relevant scope is the local desktop input path and configured actions, including simulated keys and scroll output that can affect applications in the user's session. Input observation requires Accessibility permission.

Security Findings and Attack Paths

  • inferred — Recursive remapping of executor-posted scroll output was not established. Unmarked posting already existed in the inspected base, and posting at the session tap differs from observation at the HID tap. This is a bounded runtime uncertainty, not a verified PR-introduced vulnerability.

Trust Boundaries and Controls

  • observed — Marked synthetic events cannot begin recognition through the inspected mapping path. Unowned momentum cannot initiate a new mapping, while owned momentum uses the retained action rather than selecting another action from the current route.

Resilience and Maintainability Implications

  • observed — The production event tap is installed on the event thread's current run loop, and its callback resolves and invokes transformation synchronously. This provides serialization for the inspected shared-state execution path.
  • inferred — Unidentified and identified device selections use different ownership and cooldown entries without an observed migration mechanism. A mid-gesture attribution change could therefore lose continuity. Whether that transition occurs in production, and whether it worsens prior behavior, remain unresolved.

Hardening Proposals

  • proposed — Define an explicit gesture-identity policy for missing or changing device attribution. Any adoption mechanism should require unambiguous identity and prevent one physical device from inheriting another device's retained action.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.94% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 101 functions across 16 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: throttling actions triggered by scroll input.
Linked Issues check ✅ Passed Issue #1028 asks to reduce repeated scroll-to-action triggers and leaves the implementation open. ScrollActionRecognizer throttles non-scroll-output actions by input axis, and `ButtonMappingTransfor…
Out of Scope Changes check ✅ Passed The added shared gesture ownership, route-level state, modifier-action throttle integration, and momentum handling support consistent scroll-action throttling across routes and modifier changes. The r…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@lujjjh
lujjjh merged commit b11aafa into main Oct 3, 2026
2 checks passed
@lujjjh
lujjjh deleted the fix/scroll-action-recognition branch October 3, 2026 04:12
lujjjh added a commit that referenced this pull request Nov 1, 2026
…in (#1479)

Closes #1455

Since #1414, mappings from the scroll wheel to volume or brightness have
gone through the 300 ms cooldown meant for discrete commands. They now
fire at most about three times per second, so changing the volume takes
much more scrolling than it did in v0.12.0.

This change treats volume and brightness (display and keyboard) as
incremental controls rather than discrete commands:

- **Wheel detents:** the first step comes at half a detent, then one
step per full detent, with no cooldown. This is the same counting line
scrolling uses, so high-resolution wheels split into any number of
events still give one step per notch. Legacy wheels keep v0.12.0's one
step per event.
- **Continuous input (trackpad / Magic Mouse):** the first step comes at
16 pt, then one every 32 pt.
- **Momentum:** still consumed without triggering steps.
- **Safety bound:** a single event triggers at most 16 steps.
- **Shared cooldown:** these actions neither check nor advance it, so
throttled mappings like tab switching (#1028) behave as before.

Keyboard shortcuts, Mission Control, Spaces, and the other media keys
keep the 300 ms throttle.

## Testing

- Updated policy tests and added unit tests for stepping, event
splitting, cooldown isolation, continuous input, and the per-event
bound.
- Ran the scroll and button mapping test suites: 137 tests pass.
- Tested manually.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
lujjjh added a commit that referenced this pull request Nov 21, 2026
Closes #1518

Since #1414, zooming with a modifier key and the scroll wheel has shared
the 300 ms cooldown meant for discrete commands such as switching tabs.
Scroll input during the cooldown was dropped, so a continuous scroll
zoomed only once.

Zoom now steps with the movement, like volume and brightness:

- **Scroll wheels:** one step per wheel event, as in v0.12.0. With
smoothed scrolling, high-resolution wheels step once per detent.
- **Side wheels:** one step per event.
- **Trackpads and Magic Mouse:** the first step comes at 16 pt, then one
every 32 pt, instead of one per event.
- **Momentum:** still ignored.

Zooming no longer checks or advances the cooldown of mapped commands.

## Testing

- Replaced the zoom cooldown tests with tests for wheel, side wheel,
high-resolution and continuous input.
- Ran all unit tests: 1218 pass.
- Tested manually.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

throttle horizontal scroll

1 participant