# 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](https://brew.sh)).
- **yabai** (tiling window manager) installed and running:
```bash
brew install koekeishiya/formulae/yabai
```
- **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_cursor` binary:
- 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**:
```bash
git clone https://github.com/kastastin/focus_by_cursor.git
cd focus_by_cursor
```
- **Build in release mode**:
```bash
cargo build --release
```
- **Install to your PATH**:
```bash
sudo mv target/release/focus_by_cursor /usr/local/bin/focus_by_cursor
sudo chmod +x /usr/local/bin/focus_by_cursor
```
- **Verify installation**:
```bash
which focus_by_cursor ```
## Usage
- Run the listener:
```bash
focus_by_cursor
```
- 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 `yabai` for 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>`.