Skip to content

Add focus follows mouse without raising windows - #1419

Merged
lujjjh merged 2 commits into
mainfrom
feature/focus-follows-pointer
Oct 3, 2026
Merged

lujjjh merged 2 commits into
mainfrom
feature/focus-follows-pointer

Conversation

@lujjjh

@lujjjh lujjjh commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a “Focus windows on hover” option to pointer settings, configurable per device and application.

Focuses the window under the pointer without bringing it to the front, with support for multiple displays. Hold Control to pause.

Summary by CodeRabbit

  • New Features

    • Added an optional “Focus windows on hover” setting. When enabled, hovering over an eligible window focuses it without intentionally raising it or replaying a click.
    • Hold Control to pause hover focus. App-specific settings apply to the hovered window.
    • Automatic focus pauses during certain system states and skips unsupported or ineligible windows.
  • Documentation

    • Added setup guidance, behavior details, and localized descriptions for the new setting.

Closes #671.
Closes #1296.

Related to #1006.

@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: fdca2cc0-c786-4e93-9acc-ed187867b9b2
📥 Commits

Reviewing files that changed from the base of the PR and between 63b53cd and 13a9336.

📒 Files selected for processing (23)
  • Documentation/Configuration.d.ts
  • Documentation/Configuration.json
  • Documentation/Configuration.md
  • LinearMouse/Device/DeviceManager.swift
  • LinearMouse/Device/EventDeviceSnapshot.swift
  • LinearMouse/EventTap/GlobalEventTap.swift
  • LinearMouse/EventTransformer/EventTransformerManager.swift
  • LinearMouse/Localizable.xcstrings
  • LinearMouse/Model/Configuration/Scheme/Pointer.swift
  • LinearMouse/ScreenManager/ScreenManager.swift
  • LinearMouse/ThirdPartyNotices/yabai.txt
  • LinearMouse/UI/PointerSettings/PointerSettings.swift
  • LinearMouse/UI/PointerSettings/PointerSettingsState.swift
  • LinearMouse/WindowFocus/FocusFollowsMouseController.swift
  • LinearMouse/WindowFocus/HoverFocusState.swift
  • LinearMouse/WindowFocus/HoverFocusSystemObserver.swift
  • LinearMouse/WindowFocus/HoverWindowQuery.swift
  • LinearMouse/WindowFocus/WindowFocus.swift
  • LinearMouseUnitTests/Device/EventDeviceSnapshotTests.swift
  • LinearMouseUnitTests/WindowFocus/HoverFocusConfigurationTests.swift
  • LinearMouseUnitTests/WindowFocus/HoverFocusStateTests.swift
  • LinearMouseUnitTests/WindowFocus/HoverWindowQueryTests.swift
  • LinearMouseUnitTests/WindowFocus/WindowFocusTests.swift

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


📝 Walkthrough

Walkthrough

This change adds an optional, default-off setting to focus eligible windows under the pointer. It adds window and device lookup, focus operations, event handling, system suspension behavior, UI controls, documentation, localization, and tests.

Changes

Hover Focus

Layer / File(s) Summary
Configuration and settings
LinearMouse/Model/Configuration/Scheme/Pointer.swift, Documentation/Configuration.*, LinearMouse/UI/PointerSettings/*, LinearMouse/Localizable.xcstrings, LinearMouseUnitTests/WindowFocus/HoverFocusConfigurationTests.swift
Adds the optional focusFollowsMouse pointer setting, scheme merging, a settings toggle, localized labels, configuration documentation, and tests for defaults, overrides, and serialization.
Window targeting and focus execution
LinearMouse/Device/*, LinearMouse/ScreenManager/ScreenManager.swift, LinearMouse/WindowFocus/HoverWindowQuery.swift, LinearMouse/WindowFocus/WindowFocus.swift, LinearMouse/ThirdPartyNotices/yabai.txt, LinearMouseUnitTests/Device/EventDeviceSnapshotTests.swift, LinearMouseUnitTests/WindowFocus/HoverWindowQueryTests.swift, LinearMouseUnitTests/WindowFocus/WindowFocusTests.swift
Adds strict sender-ID and display lookup, exact hovered-window eligibility checks, and dynamically resolved focus operations. Tests cover device lookup, target validation, focus transitions, and suspension reasons.
Event capture and focus controller
LinearMouse/WindowFocus/FocusFollowsMouseController.swift, LinearMouse/WindowFocus/HoverFocusState.swift, LinearMouse/WindowFocus/HoverFocusSystemObserver.swift, LinearMouse/EventTap/GlobalEventTap.swift, LinearMouse/EventTransformer/EventTransformerManager.swift, LinearMouseUnitTests/WindowFocus/HoverFocusStateTests.swift
Captures eligible mouse-motion events, polls the latest input, checks target and focus state, and coordinates event-tap lifecycle, configuration updates, and system suspension.

Priority: ➖ Normal

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant GlobalEventTap
  participant FocusFollowsMouseController
  participant DeviceManager
  participant HoverWindowQuery
  participant WindowFocus
  GlobalEventTap->>FocusFollowsMouseController: observe pointer event
  FocusFollowsMouseController->>DeviceManager: identify sender device
  FocusFollowsMouseController->>HoverWindowQuery: resolve and validate hovered target
  FocusFollowsMouseController->>WindowFocus: perform focus for valid target
Loading

Merge Risk: ⚪ Minimal · up to 13a93

No confirmed issue blocks merging. Hover focus remains optional and off by default; the unverified transformed-event behavior does not establish a failure.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 13a93

The feature is opt-in and checks both the physical device and the exact hovered window before changing focus. Exposure is limited to local window interactions. Remaining risk concerns interrupted focus changes and undocumented macOS behavior; unauthorized focus or privilege escalation has not been demonstrated.

Retained concerns

  • Low · reliability · inferred: Failed or interrupted focus changes can finish after successful earlier focus-affecting calls, without reconciling the resulting state. The hover entry is already consumed, so failure alone does not cause a retry. This limits failure containment for focus state, although the observable macOS consequences remain uncertain. Blindly restoring the previous window is not a safe remedy because it could override newer user input.
Security review details

Security Blast Radius

  • inferred — The supported exposure is local focus changes among eligible regular applications, including cross-application changes where the matched scheme enables them. The event tap requires existing Accessibility permission. The inspected path does not demonstrate elevated execution authority, remote reachability or cross-user access.

Security Findings and Attack Paths

  • inferred — A local application can influence window placement and eligibility information consumed by this flow, but must still become the exact eligible hit under accepted pointer input and satisfy configuration. No bypass to another window or unauthorized focus target was established. Operating-system identity consistency and private event-provenance guarantees remain unresolved.

Trust Boundaries and Controls

  • observed — Accepted input must be mouse movement, not marked as LinearMouse synthetic, report source PID zero and contain a nonzero HID sender. Strict device lookup never borrows the last active device. Before focus, the controller also checks live modifier and button state, running/enabled status and suspension/revision state. These are concrete filters, not proof of unforgeable event provenance.

Resilience and Maintainability Implications

  • observed — Sleep, inactive-session, display-sleep and Mission Control notifications suspend the controller and invalidate pending input. Same-application focus switches recheck currency after their compatibility wait. Avoiding unconditional restoration protects newer user actions, but leaves partial-transition recovery dependent on subsequent interaction and undocumented macOS behavior.

Hardening Proposals

  • proposed — Validate externally visible focus outcomes on supported macOS versions after cancellation following deactivation and failure at each activation step. If recovery is needed, reconcile observed focus without restoring an obsolete window or overriding newer user input.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 64 functions across 19 files. (4 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding focus-follows-mouse behavior without raising windows.
Full details: Docstring Coverage

Explanation

Docstring coverage is 9.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 64 functions across 19 files. (4 skipped: 4 unsupported.)

  • 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 added the enhancement New feature or request label Oct 3, 2026
@lujjjh
lujjjh merged commit 7fb8521 into main Oct 3, 2026
2 checks passed
@lujjjh
lujjjh deleted the feature/focus-follows-pointer branch October 3, 2026 10:57
@lujjjh lujjjh mentioned this pull request Oct 3, 2026
@abc2mit

abc2mit commented Oct 6, 2026 •

Copy link
Copy Markdown

Hi @lujjjh , so I'm testing the change and it's not always switching when the mouse is on a different window. It does sometimes, but not always. I'm testing this on Chrome. The window modification buttons (Close, Minimize, Maximize) should turn color when the focus is on that window, but it doesn't always seem to happen.

I also tested moving from the LinearMouse settings window to Chrome and it doesn't change focus.

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.

Focus Follows Mouse Focus of apps or windows follows the Mouse

2 participants