Crate window_observer

Crate window_observer 

Source
Expand description

§window-observer-rs

This crate provides an observer that receives events such as window movement and resizing. It is designed to receive window events on Windows and macOS for cross-platform applications.

Crates.io Version docs.rs

§Example

use window_observer::{EventFilter, WindowObserver};

#[tokio::main]
async fn main() {
    let pid = std::env::var("PID")
        .map(|v| v.parse().unwrap())
        .expect("Please give me the env `PID` of application that has window.");

    let (event_tx, mut event_rx) = tokio::sync::mpsc::unbounded_channel();
    let event_filter = EventFilter::all();

    let _window_observer = WindowObserver::start(pid, event_tx, event_filter)
        .await
        .unwrap();

    while let Some(event) = event_rx.recv().await {
        match event {
            Ok(event) => println!("new event: {event:#?}"),
            Err(e) => eprintln!("Error occurred during handling event: {e:#?}"),
        }
    }
}

§Platform supports

  • macOS
  • Windows
  • Linux?

I have no plans to make this at this time due to my inexperienced knowledge about Linux. But I’d be happy to receive pull requests.

§Acknowledgements

§License

This project is licensed under the MIT License.

Re-exports§

pub use window::Position;
pub use window::Size;
pub use window::Window;
pub use window_getter;
pub use ::tokio;

Modules§

platform_impl
window

Structs§

EventFilter
Represents a filter for window events.
WindowObserver
Observes window events.

Enums§

Error
Represents errors that can occur in the library.
Event
Represents events that can be observed on a window.
MaybeWindowAvailable
Represents a window that may or may not be available.

Type Aliases§

EventResult
A type alias for the result of an event. Err means that the event could not be processed, and Ok contains the event.
EventRx
A type alias for the window event reception channel.
EventTx
A type alias for the window event transmission channel.