Skip to content

Focus windows on hover never moves focus away from VS Code #1471

Closed

Description

@EduRomoGO

LinearMouse: 0.13.0-beta.4
macOS: 27.0.1
Apps: Warp 0.2026.10.14.08.27.01, VS Code 1.139.1

Steps

  1. Enable "Focus windows on hover".
  2. Click inside VS Code, then move the pointer over a Warp window without clicking.
  3. Press Cmd+V.

Expected

Text is pasted into Warp.

Actual

Text is pasted into VS Code; Warp never gets focus.

The other direction works: after clicking in Warp and moving the pointer over VS Code, Cmd+V pastes into VS Code.

Activity

  1. changed the title [-]Focus windows on hover doesn't move focus from VS Code to Warp[/-] [+]Focus windows on hover never moves focus away from VS Code[/+] on Oct 21, 2026
  2. EduRomoGO commented on Oct 21, 2026

    @EduRomoGO
    ContributorAuthor

    More testing: with Warp, ChatGPT, Safari and VS Code (1.139.1) on the same screen, hover focus works between Warp, ChatGPT and Safari in every direction. Once VS Code has focus, hovering any other window leaves focus in VS Code (Cmd+V keeps pasting into VS Code). So the problem is leaving VS Code, not entering Warp. I've updated the title.

    Cause

    While VS Code is frontmost, the system-wide kAXFocusedApplicationAttribute query returns kAXErrorNoValue (-25212). With Safari, ChatGPT or Warp frontmost, the same query returns the right app. So HoverWindowQuery.currentFocus() returns nil, and FocusFollowsMouseController.poll() calls state.suspend() without ever attempting the focus change.

    Things I ruled out:

    • WindowFocus.focus() works from VS Code: running the same SkyLight sequence (_SLPSSetFrontProcessWithOptions + the two key records) outside LinearMouse with VS Code frontmost moved focus to Safari, and VS Code did not take it back within 2 s.
    • VS Code's window passes the other checks: the per-app queries return a focused window that is AXWindow/AXStandardWindow, not modal, with no sheets; no menu bar item is selected; all calls finish well under the 50 ms timeout.

    Possible fix

    Fall back to the frontmost application when the system-wide query returns nothing:

         func currentFocus() -> Focus? {
    -        guard let app = element(kAXFocusedApplicationAttribute, on: system) else {
    +        guard let app = focusedApplication() else {
                 return nil
             }
    @@
    +    /// Some Electron apps (e.g. VS Code) leave the system-wide focused application
    +    /// unanswered (kAXErrorNoValue) while frontmost. Fall back to the frontmost
    +    /// application, or hover focus could never leave them.
    +    private func focusedApplication() -> AXUIElement? {
    +        if let app = element(kAXFocusedApplicationAttribute, on: system) {
    +            return app
    +        }
    +        guard let pid = NSWorkspace.shared.frontmostApplication?.processIdentifier else {
    +            return nil
    +        }
    +        return AXUIElementCreateApplication(pid)
    +    }

    I compiled HoverWindowQuery.swift (original and patched) with WindowFocus.swift into a small test binary and called currentFocus() from a background queue, as poll() does, three times each:

    Frontmost Original Patched
    VS Code nil VS Code, its focused window
    Safari Safari, its focused window Safari, its focused window

    Not verified: I couldn't build LinearMouse itself (no Xcode here), so the full app with this change hasn't been tested end to end and hasn't been run through swiftformat/swiftlint. I'm also not sure reading NSWorkspace.frontmostApplication from the hover worker queue is fine, or whether you'd prefer a SkyLight call here (e.g. _SLPSGetFrontProcess) instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions