window_enumerator_formatter/
models.rs1use serde::Serialize;
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, Serialize, Default)]
6pub struct WindowPosition {
7 pub x: i32,
9 pub y: i32,
11 pub width: i32,
13 pub height: i32,
15}
16
17#[derive(Debug, Clone, Serialize)]
19pub struct WindowInfo {
20 pub hwnd: isize,
22 pub pid: u32,
24 pub title: String,
26 pub class_name: String,
28 pub process_name: String,
30 pub process_file: PathBuf,
32 pub index: usize,
34 pub position: WindowPosition,
36}
37
38impl WindowInfo {
39 pub fn builder() -> WindowInfoBuilder {
41 WindowInfoBuilder::default()
42 }
43
44 }
46
47#[derive(Default)]
49pub struct WindowInfoBuilder {
50 hwnd: Option<isize>,
51 pid: Option<u32>,
52 title: Option<String>,
53 class_name: Option<String>,
54 process_name: Option<String>,
55 process_file: Option<PathBuf>,
56 index: Option<usize>,
57 position: Option<WindowPosition>,
58}
59
60impl WindowInfoBuilder {
61 pub fn hwnd(mut self, hwnd: isize) -> Self {
63 self.hwnd = Some(hwnd);
64 self
65 }
66
67 pub fn pid(mut self, pid: u32) -> Self {
69 self.pid = Some(pid);
70 self
71 }
72
73 pub fn title(mut self, title: String) -> Self {
75 self.title = Some(title);
76 self
77 }
78
79 pub fn class_name(mut self, class_name: String) -> Self {
81 self.class_name = Some(class_name);
82 self
83 }
84
85 pub fn process_name(mut self, process_name: String) -> Self {
87 self.process_name = Some(process_name);
88 self
89 }
90
91 pub fn process_file(mut self, process_file: PathBuf) -> Self {
93 self.process_file = Some(process_file);
94 self
95 }
96
97 pub fn index(mut self, index: usize) -> Self {
99 self.index = Some(index);
100 self
101 }
102
103 pub fn position(mut self, position: WindowPosition) -> Self {
105 self.position = Some(position);
106 self
107 }
108
109 pub fn build(self) -> WindowInfo {
111 WindowInfo {
112 hwnd: self.hwnd.unwrap_or(0),
113 pid: self.pid.unwrap_or(0),
114 title: self.title.unwrap_or_default(),
115 class_name: self.class_name.unwrap_or_default(),
116 process_name: self.process_name.unwrap_or_default(),
117 process_file: self.process_file.unwrap_or_default(),
118 index: self.index.unwrap_or(0),
119 position: self.position.unwrap_or_default(),
120 }
121 }
122}
123
124#[cfg(feature = "window-enumerator")]
126impl From<&window_enumerator::WindowInfo> for WindowInfo {
127 fn from(window: &window_enumerator::WindowInfo) -> Self {
128 Self::builder()
129 .hwnd(window.hwnd)
130 .pid(window.pid)
131 .title(window.title.clone())
132 .class_name(window.class_name.clone())
133 .process_name(window.process_name.clone())
134 .process_file(window.process_file.clone())
135 .index(window.index)
136 .position(WindowPosition {
137 x: window.position.x,
138 y: window.position.y,
139 width: window.position.width,
140 height: window.position.height,
141 })
142 .build()
143 }
144}
145
146#[cfg(feature = "window-enumerator")]
147impl From<window_enumerator::WindowInfo> for WindowInfo {
148 fn from(window: window_enumerator::WindowInfo) -> Self {
149 Self::from(&window)
150 }
151}