Skip to content

Auto Scroll keeps scrolling the window it started in after the cursor leaves it - #1482

Merged
lujjjh merged 1 commit into
mainfrom
auto-scroll-follows-anchor-window
Nov 1, 2026
Merged

lujjjh merged 1 commit into
mainfrom
auto-scroll-follows-anchor-window

Conversation

@lujjjh

@lujjjh lujjjh commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Partially addresses #1362 (scrolling stops when the cursor moves outside the app).

Problem

Auto Scroll posted its scroll events to the session event tap. Those go to whatever is under the cursor, so as soon as the pointer left the window where Auto Scroll started (for example, onto the menu bar or another app), scrolling stopped or moved to a different window. Setting the event location doesn't help: posting a located event to the session tap warps the cursor.

Changes

  • When Auto Scroll activates, resolve the window under the anchor (SLSFindWindowAndOwner, already used by WindowFocus), along with the anchor in window-local coordinates.
  • Every scroll event is then posted directly to that window's process with CGEvent.postToPid, stamped with:
    • the window number (field 51, which AppKit reads into NSEvent.windowNumber) and fields 91/92;
    • the window-local location, via the private CGEventSetWindowLocation;
    • the anchor as the global location.
      Without the window number and window-local location, AppKit drops pid-targeted mouse events. With them, the app hit-tests the anchor, so the scroll goes to the view where Auto Scroll started.
  • The existing cursor-following path is kept when:
    • CGEventSetWindowLocation can't be resolved;
    • the anchor is over one of LinearMouse's own windows;
    • the target app isn't a regular app (menu bar panels and other accessory or agent apps may ignore pid-targeted mouse events).
  • WindowFocus.windowHit(at:) now also returns the window-local point; window(at:) is unchanged for existing callers.
  • The target is resolved from the trigger's global (top-left origin) location, not the unflipped location Auto Scroll uses to measure pointer travel.

Behavior change

Scroll events posted to a process don't pass through LinearMouse's own event tap. Auto Scroll output therefore no longer gets the scroll pipeline of the last active device (reverse scrolling, smoothing, acceleration, scroll speed). Auto Scroll's direction comes from the pointer position and its speed from its own setting, so this also stops reverse scrolling from inverting Auto Scroll.

Testing

With the cursor outside the target window:

  • TextEdit (in the background): scrolls.
  • Mail, while covered by other windows: only the message list under the anchor scrolled; the sidebar and content pane did not.
  • Chrome, a page with two independent scroll containers: an anchor in the left container scrolled only that one, and likewise for the right.
  • Zen (Gecko): scrolls.

Also:

  • Manually tested Auto Scroll end to end.
  • Added a unit test that the target is resolved at the trigger's global location.
  • Full unit test suite passes.

Electron apps have not been tested yet; they share Chrome's engine, so they are expected to behave like Chrome.

🤖 Generated with Claude Code

Auto Scroll posted its scroll events to the session event tap, so they
went to whatever was under the cursor and stopped reaching the original
window once the pointer left it. Resolve the window under the anchor when
Auto Scroll starts and post each event directly to its process, stamped
with the window number and the window-local anchor so the app routes it to
the view that was under the anchor. Keep the cursor-following path for
accessory apps, LinearMouse's own windows, and systems where the private
CGEventSetWindowLocation symbol is unavailable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lujjjh lujjjh added the enhancement New feature or request label Nov 1, 2026
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between ef679a3 and 7487159.

Files selected for processing: 5
  • LinearMouse/EventTransformer/AutoScrollScrollTarget.swift
  • LinearMouse/EventTransformer/AutoScrollTransformer.swift
  • LinearMouse/EventTransformer/EventTransformerManager.swift
  • LinearMouse/WindowFocus/WindowFocus.swift
  • LinearMouseUnitTests/EventTransformer/AutoScrollTransformerTests.swift

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

Walkthrough

Auto-scroll now resolves a window at the activation location and routes generated scroll events to that process when a supported target is available. Window hit-testing also returns window-local coordinates. The existing fallback event sink remains available.

Changes: Auto-scroll target routing

Layer / File(s) Summary
Window hit data and target posting
LinearMouse/WindowFocus/WindowFocus.swift, LinearMouse/EventTransformer/AutoScrollScrollTarget.swift
Window hit-testing returns the target and its window-local coordinates. The scroll target records the process, window, and locations, then sets event location and window fields before posting to the target process.
Activation location and event routing
LinearMouse/EventTransformer/AutoScrollTransformer.swift, LinearMouse/EventTransformer/EventTransformerManager.swift, LinearMouseUnitTests/EventTransformer/AutoScrollTransformerTests.swift
Activation paths pass a target location to the resolver. The transformer retains a resolved target during activation and uses it to post scroll events, with the existing event sink as fallback. The manager supplies the resolver, and a test checks the trigger location.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant AutoScrollTransformer
  participant AutoScrollScrollTarget
  participant WindowFocus
  participant TargetApplicationProcess
  participant FallbackEventSink
  AutoScrollTransformer->>AutoScrollScrollTarget: Resolve target at activation location
  AutoScrollScrollTarget->>WindowFocus: Request window hit
  WindowFocus-->>AutoScrollScrollTarget: Return target and local point
  AutoScrollScrollTarget-->>AutoScrollTransformer: Return resolved target
  alt Target is available
    AutoScrollTransformer->>AutoScrollScrollTarget: Post generated scroll event
    AutoScrollScrollTarget->>TargetApplicationProcess: Set event fields and post
  else Target is unavailable
    AutoScrollTransformer->>FallbackEventSink: Post generated scroll event
  end
Loading

Possibly related PRs

  • linearmouse/linearmouse#1480: Changes Logitech activation anchor coordinates in the same activation paths that provide the location for target resolution.

Suggested labels: bug

Merge Risk: Minimal · up to 74871

No concrete merge-blocking issue was established.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: Auto Scroll continues targeting the original window after the cursor leaves it.
Description check Passed The description directly explains the problem, implementation, behavior change, and testing for keeping Auto Scroll directed at the original window.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@lujjjh
lujjjh merged commit 4dac67b into main Nov 1, 2026
2 checks passed
@lujjjh
lujjjh deleted the auto-scroll-follows-anchor-window branch November 1, 2026 06:51
@lujjjh lujjjh mentioned this pull request Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant