WindowEnumerator

Struct WindowEnumerator 

Source
pub struct WindowEnumerator { /* private fields */ }
Expand description

The main window enumeration and inspection interface.

This struct provides methods to discover, filter, and sort Windows windows with various criteria. It serves as the primary entry point for the library.

Implementations§

Source§

impl WindowEnumerator

Source

pub fn new() -> Self

Creates a new window enumerator.

The enumerator starts with no windows loaded. Call enumerate_all_windows to populate it with the current system windows.

§Examples
use window_enumerator::WindowEnumerator;

let enumerator = WindowEnumerator::new();
Source

pub fn enumerate_all_windows(&mut self) -> Result<()>

Enumerates all visible windows on the system.

This method populates the internal window list with all currently visible, non-child windows. Each window is assigned a 1-based index.

§Errors

Returns WindowError::WindowsApiError if the Windows API call fails.

§Examples
use window_enumerator::WindowEnumerator;

let mut enumerator = WindowEnumerator::new();
enumerator.enumerate_all_windows().unwrap();
Source

pub fn find_by_title(&self, title_substring: &str) -> Vec<WindowInfo>

Finds windows by title containing the specified string (case-insensitive).

This is a convenience method for simple title-based filtering.

§Arguments
  • title_substring - The substring to search for in window titles
§Returns

A vector containing windows whose titles contain the specified substring.

§Examples
use window_enumerator::WindowEnumerator;

let mut enumerator = WindowEnumerator::new();
enumerator.enumerate_all_windows().unwrap();

let chrome_windows = enumerator.find_by_title("Chrome");
for window in chrome_windows {
    window.print_compact();
}
Source

pub fn filter_windows(&self, criteria: &FilterCriteria) -> Vec<WindowInfo>

Filters windows based on the specified criteria.

§Arguments
  • criteria - The filter criteria to apply
§Returns

A vector containing only the windows that match all criteria.

§Examples
use window_enumerator::{WindowEnumerator, FilterCriteria};

let mut enumerator = WindowEnumerator::new();
enumerator.enumerate_all_windows().unwrap();

let criteria = FilterCriteria {
    title_contains: Some("Chrome".to_string()),
    ..Default::default()
};
let chrome_windows = enumerator.filter_windows(&criteria);
Source

pub fn filter_and_sort_windows( &self, criteria: &FilterCriteria, sort_criteria: &SortCriteria, ) -> Vec<WindowInfo>

Filters and sorts windows based on the specified criteria.

Requires the sorting feature.

§Arguments
  • criteria - The filter criteria to apply
  • sort_criteria - The sort criteria to apply
§Returns

A vector containing the filtered and sorted windows.

Source

pub fn filter_windows_with_selection( &self, criteria: &FilterCriteria, selection: &Selection, ) -> Vec<WindowInfo>

Filters windows with selection criteria.

Requires the selection feature.

§Arguments
  • criteria - The filter criteria to apply
  • selection - The selection criteria to apply
§Returns

A vector containing the selected windows that match the filter criteria.

Source

pub fn filter_sort_windows_with_selection( &self, criteria: &FilterCriteria, sort_criteria: &SortCriteria, selection: &Selection, ) -> Vec<WindowInfo>

Filters, sorts, and selects windows based on the specified criteria.

Requires both sorting and selection features.

§Arguments
  • criteria - The filter criteria to apply
  • sort_criteria - The sort criteria to apply
  • selection - The selection criteria to apply
§Returns

A vector containing the filtered, sorted, and selected windows.

Source

pub fn get_windows(&self) -> &[WindowInfo]

Returns a reference to all enumerated windows.

§Returns

A slice containing all windows that were enumerated.

Source

pub fn get_window_by_index(&self, index: usize) -> Option<&WindowInfo>

Retrieves a window by its 1-based index.

§Arguments
  • index - The 1-based index of the window to retrieve
§Returns

Some(&WindowInfo) if a window with the given index exists, None otherwise.

Source

pub fn print_windows_with_indices(&self)

Prints all enumerated windows with their indices in a formatted table.

This is useful for debugging and for users to see available windows before making selections.

§Examples
use window_enumerator::WindowEnumerator;

let mut enumerator = WindowEnumerator::new();
enumerator.enumerate_all_windows().unwrap();
enumerator.print_windows_with_indices();

Trait Implementations§

Source§

impl Default for WindowEnumerator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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