window_enumerator/
types.rs

1use std::path::PathBuf;
2
3/// Represents a window's position and dimensions on the screen.
4#[derive(Debug, Clone, Copy, Default)] // ← 添加 Default derive
5pub struct WindowPosition {
6    /// The x-coordinate of the window's top-left corner in screen coordinates.
7    pub x: i32,
8    /// The y-coordinate of the window's top-left corner in screen coordinates.
9    pub y: i32,
10    /// The width of the window in pixels.
11    pub width: i32,
12    /// The height of the window in pixels.
13    pub height: i32,
14}
15
16// 删除手动实现的 Default for WindowPosition
17
18/// Comprehensive information about a Windows window.
19#[derive(Debug, Clone)]
20pub struct WindowInfo {
21    /// The window handle (HWND) as an isize.
22    pub hwnd: isize,
23    /// The process ID (PID) that owns the window.
24    pub pid: u32,
25    /// The window title text.
26    pub title: String,
27    /// The window class name.
28    pub class_name: String,
29    /// The name of the process executable.
30    pub process_name: String,
31    /// The full path to the process executable file.
32    pub process_file: PathBuf,
33    /// The 1-based index of this window in enumeration results.
34    pub index: usize,
35    /// The position and dimensions of the window.
36    pub position: WindowPosition,
37}
38
39/// Criteria for filtering windows during enumeration.
40#[derive(Debug, Clone, Default)]
41pub struct FilterCriteria {
42    /// Filter by exact process ID match.
43    pub pid: Option<u32>,
44    /// Filter by title containing the specified string (case-insensitive).
45    pub title_contains: Option<String>,
46    /// Filter by class name containing the specified string (case-insensitive).
47    pub class_name_contains: Option<String>,
48    /// Filter by process name containing the specified string (case-insensitive).
49    pub process_name_contains: Option<String>,
50    /// Filter by process file path containing the specified string (case-insensitive).
51    pub process_file_contains: Option<String>,
52}
53
54#[cfg(feature = "selection")]
55/// Selection criteria for choosing specific windows from enumeration results.
56#[derive(Debug, Clone)]
57pub enum Selection {
58    /// Select all windows that match the filter criteria.
59    All,
60    /// Select windows by their 1-based indices.
61    Indices(Vec<usize>),
62}
63
64#[cfg(feature = "sorting")]
65/// Position-based sorting criteria for windows.
66#[derive(Debug, Clone)]
67pub enum PositionSort {
68    /// Sort by X coordinate only.
69    X(i8), // 1: ascending, -1: descending
70    /// Sort by Y coordinate only.
71    Y(i8), // 1: ascending, -1: descending
72    /// Sort by X coordinate first, then Y coordinate.
73    XY(i8, i8), // (x_order, y_order)
74}
75
76#[cfg(feature = "sorting")]
77/// Criteria for sorting window enumeration results.
78#[derive(Debug, Clone, Default)] // ← 添加 Default derive
79pub struct SortCriteria {
80    /// Sort by process ID (1: ascending, -1: descending, 0: no sorting).
81    pub pid: i8,
82    /// Sort by window title (1: ascending, -1: descending, 0: no sorting).
83    pub title: i8,
84    /// Sort by window position (None: no sorting, Some: position-based sorting).
85    pub position: Option<PositionSort>,
86}
87
88// 删除手动实现的 Default for SortCriteria