focus_monitor

Crates.iofocus_monitor
lib.rsfocus_monitor
version0.1.4
sourcesrc
created_at2022-11-28 05:48:50.269918
updated_at2023-05-07 22:51:16.962144
descriptionLibrary for iterating over the focused window each time it changes
homepagehttps://github.com/zd4y/focus_monitor/
repositoryhttps://github.com/zd4y/focus_monitor/
max_upload_size
id724137
size10,009
(zd4y)

documentation

README

Iterator over focused window change on Linux

Example usage:

The following will print the window that gets focused every time the active window changes.

window can be None if there is no active window.

use focus_monitor::FocusMonitor;

fn main() -> anyhow::Result<()> {
    let focus_monitor = FocusMonitor::try_new()?;
    for window in focus_monitor {
        let window = window?;
        println!("{:?}", window);
    }

    Ok(())
}

Async

To enable AsyncFocusMonitor use features=["tokio"] in Cargo.toml:

focus_monitor = { version = "0.1", features = ["tokio"] }

And you can use it like this:

use focus_monitor::AsyncFocusMonitor;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut focus_monitor = AsyncFocusMonitor::try_new()?;
    let window = focus_monitor.recv().await?;
    println!("{:?}", window);
}
Commit count: 13

cargo fmt