focus_by_cursor

Crates.iofocus_by_cursor
lib.rsfocus_by_cursor
version0.1.0
created_at2025-05-29 11:08:27.670103+00
updated_at2025-05-29 11:08:27.670103+00
descriptionAutomatically focuses the yabai window under the mouse cursor, without clicks. Works exclusively on macOS.
homepage
repository
max_upload_size
id1693686
size19,539
(kastastin)

documentation

README

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:

    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:

    git clone https://github.com/kastastin/focus_by_cursor.git
    cd focus_by_cursor
    
  • Build in release mode:

    cargo build --release
    
  • Install to your PATH:

    sudo mv target/release/focus_by_cursor /usr/local/bin/focus_by_cursor
    sudo chmod +x /usr/local/bin/focus_by_cursor
    
  • Verify installation:

    which focus_by_cursor  # should print /usr/local/bin/focus_by_cursor
    

Usage

  • Run the listener:

    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>.
Commit count: 0

cargo fmt