focus_by_cursor 0.1.0

Automatically focuses the yabai window under the mouse cursor, without clicks. Works exclusively on macOS.
Documentation
  • Coverage
  • 30%
    3 out of 10 items documented0 out of 3 items with examples
  • Size
  • Source code size: 19.53 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 420.27 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 25s Average build duration of successful builds.
  • all releases: 25s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kastastin

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>.