#window #active #title #position #current

active-win-pos-rs

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

13 releases (7 breaking)

0.8.3 Nov 29, 2023
0.8.1 May 18, 2023
0.7.1 Sep 20, 2022
0.5.0 Jul 9, 2022
0.4.1 Feb 22, 2022

#29 in macOS and iOS APIs

Download history 297/week @ 2024-07-19 277/week @ 2024-07-26 218/week @ 2024-08-02 243/week @ 2024-08-09 208/week @ 2024-08-16 138/week @ 2024-08-23 208/week @ 2024-08-30 280/week @ 2024-09-06 148/week @ 2024-09-13 264/week @ 2024-09-20 213/week @ 2024-09-27 174/week @ 2024-10-04 492/week @ 2024-10-11 255/week @ 2024-10-18 391/week @ 2024-10-25 308/week @ 2024-11-01

1,463 downloads per month
Used in 2 crates

MIT/Apache

31KB
677 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.8"

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.

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,
    },
}

Dependencies

~0–38MB
~532K SLoC