focus_by_cursor
macOS only: This tool works exclusively on macOS with yabai installed.
Automatically focuses the yabai window under your mouse cursor, without clicks.
Getting Started
Prerequisites
-
Homebrew installed (see https://brew.sh).
-
yabai (tiling window manager) installed and running:
-
Accessibility permissions for
yabai:- Open System Settings → Privacy & Security → Accessibility.
- Click +, press Cmd+Shift+G, enter
/opt/homebrew/bin/yabai, and click Open. - Ensure the checkbox next to yabai is checked.
-
Input Monitoring permissions for
focus_by_cursorbinary:- Build and install the binary (see below).
- Open System Settings → Privacy & Security → Input Monitoring.
- Click +, press Cmd+Shift+G, enter
/usr/local/bin/focus_by_cursor, and click Open. - Ensure the checkbox is checked.
Build & Install
-
Clone the repository:
-
Build in release mode:
-
Install to your PATH:
-
Verify installation:
Usage
-
Run the listener:
-
The program will listen for mouse moves and focus windows under the cursor.
-
Press Ctrl+C to stop.
How It Works
- Listens to global mouse-move events via
rdev. - Debounces events to fire at most once every 50 ms.
- Queries
yabaifor all windows (yabai -m query --windows). - Parses JSON output to find which window contains the cursor point.
- Focuses that window via
yabai -m window --focus <id>.