Window

Struct Window 

Source
pub struct Window(/* private fields */);
Expand description

A wrapper around a platform-specific window. This struct provides a cross-platform interface to interact with window properties.

Implementations§

Source§

impl Window

Source

pub fn new(inner: PlatformWindow) -> Self

Creates a new Window instance from a platform-specific window.

§Notes

You can get a Window instance by using the get_window function or get_windows function so you don’t need to create it manually in most use cases.

Source

pub fn platform_window(&self) -> &PlatformWindow

Retrieves the underlying platform-specific window.

Source

pub fn into_platform_window(self) -> PlatformWindow

Consumes the Window and returns the underlying platform-specific window.

Examples found in repository?
examples/windows_various_rect.rs (line 9)
7fn main() {
8    for window in window_getter::get_windows().unwrap() {
9        let window = window.into_platform_window();
10
11        println!("\n{:?} ({:?})", window.title(), window.hwnd());
12        println!("\tGetWindowRect: {:?}", window.rect());
13        println!(
14            "\tDwmGetWindowAttribute with DWMWA_EXTENDED_FRAME_BOUNDS: {:?}",
15            window.extended_frame_bounds()
16        );
17    }
18}
Source

pub fn id(&self) -> WindowId

Returns the unique identifier of the window.

Examples found in repository?
examples/print_windows.rs (line 6)
1fn main() {
2    let windows = window_getter::get_windows().unwrap();
3    println!("Found {} windows:", windows.len());
4
5    for window in windows {
6        println!("\n{:?} ({})", window.title(), window.id().as_u32());
7        println!("\tBounds: {:?}", window.bounds());
8        println!("\tProcess id: {}", window.owner_pid().unwrap());
9        println!("\tProcess name: {:?}", window.owner_name());
10    }
11}
Source

pub fn title(&self) -> Result<Option<String>, Error>

Returns the title of the window.

§Platform-specific
  • Windows: If you don’t have permission to access the title, it will return Error::PermissionDenied.
  • macOS: It will always return Ok. Apple’s documentation does not explicitly state this, but it returns None when the permission is not granted.
Examples found in repository?
examples/print_windows.rs (line 6)
1fn main() {
2    let windows = window_getter::get_windows().unwrap();
3    println!("Found {} windows:", windows.len());
4
5    for window in windows {
6        println!("\n{:?} ({})", window.title(), window.id().as_u32());
7        println!("\tBounds: {:?}", window.bounds());
8        println!("\tProcess id: {}", window.owner_pid().unwrap());
9        println!("\tProcess name: {:?}", window.owner_name());
10    }
11}
More examples
Hide additional examples
examples/get_window.rs (line 11)
3fn main() {
4    let raw = std::env::var("WINDOW_ID")
5        .expect("`WINDOW_ID` environment variable not set")
6        .parse::<u32>()
7        .expect("`WINDOW_ID` must be a valid `u32`");
8    let id = WindowId::from(raw);
9
10    if let Some(window) = window_getter::get_window(id).unwrap() {
11        println!("title: {:?}", window.title());
12    } else {
13        println!("No window found with the given ID.");
14    };
15}
Source

pub fn bounds(&self) -> Result<Bounds, Error>

Returns the bounds of the window.

Examples found in repository?
examples/print_windows.rs (line 7)
1fn main() {
2    let windows = window_getter::get_windows().unwrap();
3    println!("Found {} windows:", windows.len());
4
5    for window in windows {
6        println!("\n{:?} ({})", window.title(), window.id().as_u32());
7        println!("\tBounds: {:?}", window.bounds());
8        println!("\tProcess id: {}", window.owner_pid().unwrap());
9        println!("\tProcess name: {:?}", window.owner_name());
10    }
11}
Source

pub fn owner_pid(&self) -> Result<i32, Error>

Returns the process ID of the window’s owner.

§Platform-specific
  • macOS: It will always return Ok.
Examples found in repository?
examples/print_windows.rs (line 8)
1fn main() {
2    let windows = window_getter::get_windows().unwrap();
3    println!("Found {} windows:", windows.len());
4
5    for window in windows {
6        println!("\n{:?} ({})", window.title(), window.id().as_u32());
7        println!("\tBounds: {:?}", window.bounds());
8        println!("\tProcess id: {}", window.owner_pid().unwrap());
9        println!("\tProcess name: {:?}", window.owner_name());
10    }
11}
Source

pub fn owner_name(&self) -> Result<Option<String>, Error>

Returns the name of the process that owns the window.

§Platform-specific
  • Windows: If you don’t have permission to access the owner name, it will return Error::PermissionDenied. Also, it will return the name of the executable file when owner name is available.
  • macOS: It will always return Ok.
Examples found in repository?
examples/print_windows.rs (line 9)
1fn main() {
2    let windows = window_getter::get_windows().unwrap();
3    println!("Found {} windows:", windows.len());
4
5    for window in windows {
6        println!("\n{:?} ({})", window.title(), window.id().as_u32());
7        println!("\tBounds: {:?}", window.bounds());
8        println!("\tProcess id: {}", window.owner_pid().unwrap());
9        println!("\tProcess name: {:?}", window.owner_name());
10    }
11}

Trait Implementations§

Source§

impl Clone for Window

Source§

fn clone(&self) -> Window

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Window

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Window

§

impl RefUnwindSafe for Window

§

impl Send for Window

§

impl Sync for Window

§

impl Unpin for Window

§

impl UnwindSafe for Window

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.