#active-window #window-title #window-position #current #position

active-win-pos-rs

Get position, size, title and a few other properties of the active window on Windows, MacOS and Linux

18 releases (9 breaking)

new 0.10.1 Apr 19, 2026
0.10.0 Mar 13, 2026
0.9.1 Aug 11, 2025
0.9.0 Dec 31, 2024
0.4.1 Feb 22, 2022

#64 in GUI

Download history 1341/week @ 2025-12-29 1440/week @ 2026-01-05 1038/week @ 2026-01-12 1178/week @ 2026-01-19 947/week @ 2026-01-26 1556/week @ 2026-02-02 1258/week @ 2026-02-09 1035/week @ 2026-02-16 1242/week @ 2026-02-23 1852/week @ 2026-03-02 1670/week @ 2026-03-09 1444/week @ 2026-03-16 3597/week @ 2026-03-23 3381/week @ 2026-03-30 4600/week @ 2026-04-06 2689/week @ 2026-04-13

14,564 downloads per month
Used in 11 crates

MIT/Apache

34KB
727 lines

active-win-pos-rs

Build status

A small Rust library that lets you get position, size, title and a few other properties of the active window on Windows, MacOS and Linux

Usage

Add to Cargo.toml:

[dependencies]
active-win-pos-rs = "0.10"

Use:

use active_win_pos_rs::get_active_window;

fn main() {
    match get_active_window() {
        Ok(active_window) => {
            println!("active window: {:#?}", active_window);
        },
        Err(()) => {
            println!("error occurred while getting the active window");
        }
    }
}

Would give you an instance of ActiveWindow struct with unique window id, process id, window position and window title.

Or use active_win_pos_rs::get_position to get the WindowPosition only.

Window title on MacOS

On MacOS title property will always return an empty string unless you Enable Screen Recording permission for your app.

Wayland support on Linux

On Linux, the library now supports both X11 and Wayland. When running on Wayland (detected via the WAYLAND_DISPLAY environment variable), the library will attempt to get the active window information from the following compositors, in order:

  • KDE Plasma (KWin) (via kdotool)

If all Wayland backends fail, or if WAYLAND_DISPLAY is not set, the library falls back to X11/XCB, maintaining full backward compatibility.

Linux build dependencies

To build on Linux, install these system packages first:

  • libxcb-ewmh-dev
  • libxcb-randr0-dev
  • libdbus-1-dev
  • pkg-config

On Debian/Ubuntu:

sudo apt-get update
sudo apt-get install -y libxcb-ewmh-dev libxcb-randr0-dev libdbus-1-dev pkg-config

Build

% git clone https://github.com/dimusic/active-win-pos-rs.git
% cd active-win-pos-rs
% cargo build

Example

% cargo run --example active-window

Output:

active window: ActiveWindow {
    title: "cmd - cargo  run --example active-window",
    process_path: "C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_1.16.10262.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe",
    app_name: "WindowsTerminal",
    window_id: "HWND(9700584)",
    process_id: 8460,
    position: WindowPosition {
        x: 6.0,
        y: 296.0,
        width: 1129.0,
        height: 635.0,
    },
}

Project Support

This project is supported by a few maker-focused businesses I run and actively use in my workflow. If you work with laser cutting, CNC, or digital art, you might find them useful too.

  • MyLaserTools tools and resources for laser cutting, CNC machining, and 3D printing.
  • YXE Creations Craft Hub a laser craft supply store for acrylic, plywood, and maker materials.
  • Lumicry digital luminous neon and acrylic art powered by LEDs and custom electronics.

Dependencies

~0–44MB
~623K SLoC