Skip to content

Skip raise when frontmost app has overlay window at cursor#275

Open
candrabeqx wants to merge 1 commit intosbmpost:masterfrom
candrabeqx:fix/skip-raise-over-frontmost-app-overlay
Open

Skip raise when frontmost app has overlay window at cursor#275
candrabeqx wants to merge 1 commit intosbmpost:masterfrom
candrabeqx:fix/skip-raise-over-frontmost-app-overlay

Conversation

@candrabeqx
Copy link

Problem

When an app displays a custom overlay window (non-layer-0) that extends beyond its main window bounds, moving the cursor to the overlay area outside the main window causes AutoRaise to activate the wrong window.

Example: Telegram for macOS uses a custom NSWindow at .screenSaver window level for its right-click context menu (Reply, Copy Text, Translate, Save As, etc.). When the context menu extends past the main Telegram window:

  1. AXUIElementCopyElementAtPosition either skips the overlay (menu-role elements are filtered) or sees through it
  2. topwindow() fallback only considers layer-0 windows, so it finds the window behind the overlay
  3. AutoRaise activates that background window, stealing focus from Telegram and closing the context menu

This affects any app that uses high-level custom windows for popups, context menus, or floating panels that extend beyond the main window bounds.

Solution

Before committing to a raise, check whether the frontmost app owns any non-layer-0 (overlay) window that contains the cursor position. If the cursor is over a different app's layer-0 window and the frontmost app has an overlay at that position, suppress the raise.

The check is intentionally narrow:

  • Only triggers when mouseWindow_pid != frontmost_pid (different app under cursor)
  • Only checks non-layer-0 windows (overlays/popups, not normal windows)
  • No impact on normal focus-follows-mouse behavior

Test plan

  • Normal focus-follows-mouse between windows works as before
  • Right-click context menu in Telegram (or any app with custom overlay menus) that extends past the main window — hovering the overflow area no longer steals focus
  • Tooltips, floating panels, and other overlay windows from the frontmost app don't trigger unwanted raises
  • No performance regression (CGWindowListCopyWindowInfo only called when needs_raise is true and mouseWindow_pid != frontmost_pid)

✨ Generated with Claude Code (claude.ai/claude-code) 2.1.50 (claude-opus-4-6)

When an app displays a high-level overlay window (e.g. a custom context
menu) that extends beyond its main window bounds, the cursor may land
over a different app's layer-0 window while the overlay is visually on
top. AutoRaise would then activate that background window, stealing
focus and closing the overlay.

This adds a check before raising: if the window under the cursor belongs
to a different process than the frontmost app, and the frontmost app owns
a non-layer-0 (overlay) window containing the cursor position, the raise
is suppressed.

Affected apps include Telegram for macOS which uses a custom NSWindow at
screenSaver level for its context menu (Reply, Copy Text, Translate, etc).

✨ Generated with Claude Code (claude.ai/claude-code) 2.1.50 (Claude Code) (claude-opus-4-6)
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.

1 participant