Open
Conversation
Closes nikitabobko#12 Implement the inverse of the existing mouse-follows-focus feature: hovering the cursor over a window automatically focuses it. This is a commonly requested feature from users of i3/Sway/Yabai. The feature is controlled by a new boolean config option `focus-follows-mouse` (default: false). When enabled, a global NSEvent monitor for .mouseMoved events resolves which window is under the cursor and focuses it via runLightSession. Window resolution uses CGWindowListCopyWindowInfo, which returns the proper stacking order as determined by macOS. The first AeroSpace-managed window whose kCGWindowBounds contains the cursor is the target. This should handle the following z-order scenarios: - tiled over floating - floating over tiled - multiple overlapping floating CGWindowListCopyWindowInfo is a public CoreGraphics API already used in windowLevelCache.swift. The following edge cases are also considered: - Focus changes are suppressed while the left mouse button is held (drag operations). - The handler is a no-op when AeroSpace is disabled (RunSessionGuard check). - No feedback loop occurs with mouse-follows-focus because move-mouse monitor-lazy-center is a no-op when the cursor is already inside the target, The monitor is installed at startup (GlobalObserver.initObserver) and reinstalled on config reload (ReloadConfigCommand) so toggling the option should effect immediately without restarting.
|
I would love seeing this merged. I've been working with Omarchy, which provides this functionality out of the box, and I felt a bit disconnected when returning to my MacBook. 🩵 Thanks for the PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
My third attempt at closing: #12
The following cases are handled with CGWindowListCopyWindowInfo
- tiled over floating
- floating over tiled
- multiple overlapping floating
CGWindowListCopyWindowInfo is a public CoreGraphics API already used in windowLevelCache.swift so hopefully it is ok to use in this context.
The following edge cases are also considered:
- Focus changes are suppressed while the left mouse button is held (drag operations).
- The handler is a no-op when AeroSpace is disabled (RunSessionGuard check).
- No feedback loop occurs with mouse-follows-focus because move-mouse monitor-lazy-center is a no-op when the cursor is already inside the target,