tauri_winutils/
commands.rs1use tauri::State;
2use crate::window_manager::{WindowManager, ManagedWindow};
3use crate::workspace::Workspace;
4use crate::layout::LayoutType;
5use crate::config::Config;
6use crate::system_window::SystemWindow;
7
8#[tauri::command]
9pub fn get_windows(wm: State<WindowManager>) -> Vec<ManagedWindow> {
10 wm.get_windows()
11}
12
13#[tauri::command]
14pub fn add_window_to_manager(
15 wm: State<WindowManager>,
16 handle: u64, title: String,
18 app_name: String
19) -> Result<String, String> {
20 wm.add_window(handle, title, app_name)
21}
22
23#[tauri::command]
24pub fn remove_window_from_manager(
25 wm: State<WindowManager>,
26 window_id: String
27) -> Result<(), String> {
28 wm.remove_window(&window_id)
29}
30
31#[tauri::command]
32pub fn create_workspace(
33 wm: State<WindowManager>,
34 name: String,
35 layout: String
36) -> Result<String, String> {
37 let layout_type = match layout.as_str() {
38 "tiling" => LayoutType::Tiling,
39 "floating" => LayoutType::Floating,
40 "monocle" => LayoutType::Monocle,
41 _ => return Err("Invalid layout type".to_string()),
42 };
43 Ok(wm.create_workspace(name, layout_type))
44}
45
46#[tauri::command]
47pub fn switch_workspace(
48 wm: State<WindowManager>,
49 workspace_id: String
50) -> Result<(), String> {
51 wm.switch_workspace(&workspace_id)
52}
53
54#[tauri::command]
55pub fn get_workspaces(wm: State<WindowManager>) -> Vec<Workspace> {
56 wm.get_workspaces()
57}
58
59#[tauri::command]
60pub fn arrange_windows(
61 wm: State<WindowManager>,
62 workspace_id: String
63) -> Result<(), String> {
64 wm.arrange_workspace(&workspace_id)
65}
66
67#[tauri::command]
68pub fn close_window(
69 wm: State<WindowManager>,
70 window_id: String
71) -> Result<(), String> {
72 let handle = {
74 let map = wm.windows.lock().unwrap();
75 map.get(&window_id)
76 .ok_or("Window not found".to_string())?
77 .handle
78 };
79 wm.close_system_window(handle)?;
80 wm.remove_window(&window_id)
81}
82
83#[tauri::command]
84pub fn minimize_window(
85 wm: State<WindowManager>,
86 window_id: String
87) -> Result<(), String> {
88 let handle = {
89 let map = wm.windows.lock().unwrap();
90 map.get(&window_id)
91 .ok_or("Window not found".to_string())?
92 .handle
93 };
94 wm.minimize_system_window(handle)?;
95 if let Some(w) = wm.windows.lock().unwrap().get_mut(&window_id) {
96 w.state = crate::window_manager::WindowState::Minimized;
97 }
98 Ok(())
99}
100
101#[tauri::command]
102pub fn maximize_window(
103 wm: State<WindowManager>,
104 window_id: String
105) -> Result<(), String> {
106 let handle = {
107 let map = wm.windows.lock().unwrap();
108 map.get(&window_id)
109 .ok_or("Window not found".to_string())?
110 .handle
111 };
112 wm.maximize_system_window(handle)?;
113 if let Some(w) = wm.windows.lock().unwrap().get_mut(&window_id) {
114 w.state = crate::window_manager::WindowState::Maximized;
115 }
116 Ok(())
117}
118
119#[tauri::command]
120pub fn focus_window(
121 wm: State<WindowManager>,
122 window_id: String
123) -> Result<(), String> {
124 wm.focus_window(&window_id)
125}
126
127#[tauri::command]
128pub fn get_config(wm: State<WindowManager>) -> Config {
129 wm.config.lock().unwrap().clone()
130}
131
132#[tauri::command]
133pub fn update_config(
134 wm: State<WindowManager>,
135 config: Config
136) -> Result<(), String> {
137 *wm.config.lock().unwrap() = config;
138 Ok(())
139}
140
141#[tauri::command]
143pub fn get_system_windows(
144 wm: State<WindowManager>
145) -> Result<Vec<SystemWindow>, String> {
146 wm.get_system_windows()
147}
148
149#[tauri::command]
150pub fn move_system_window(
151 wm: State<WindowManager>,
152 handle: u64,
153 x: i32,
154 y: i32
155) -> Result<(), String> {
156 wm.move_system_window(handle, x, y)
157}
158
159#[tauri::command]
160pub fn resize_system_window(
161 wm: State<WindowManager>,
162 handle: u64,
163 width: u32,
164 height: u32
165) -> Result<(), String> {
166 wm.resize_system_window(handle, width, height)
167}
168
169#[tauri::command]
170pub fn set_system_window_bounds(
171 wm: State<WindowManager>,
172 handle: u64,
173 x: i32,
174 y: i32,
175 width: u32,
176 height: u32
177) -> Result<(), String> {
178 wm.set_system_window_bounds(handle, x, y, width, height)
179}
180
181#[tauri::command]
182pub fn minimize_system_window(
183 wm: State<WindowManager>,
184 handle: u64
185) -> Result<(), String> {
186 wm.minimize_system_window(handle)
187}
188
189#[tauri::command]
190pub fn maximize_system_window(
191 wm: State<WindowManager>,
192 handle: u64
193) -> Result<(), String> {
194 wm.maximize_system_window(handle)
195}
196
197#[tauri::command]
198pub fn restore_system_window(
199 wm: State<WindowManager>,
200 handle: u64
201) -> Result<(), String> {
202 wm.restore_system_window(handle)
203}
204
205#[tauri::command]
206pub fn close_system_window(
207 wm: State<WindowManager>,
208 handle: u64
209) -> Result<(), String> {
210 wm.close_system_window(handle)
211}
212
213#[tauri::command]
214pub fn focus_system_window(
215 wm: State<WindowManager>,
216 handle: u64
217) -> Result<(), String> {
218 wm.focus_system_window(handle)
219}
220
221#[tauri::command]
222pub fn hide_system_window(
223 wm: State<WindowManager>,
224 handle: u64
225) -> Result<(), String> {
226 wm.hide_system_window(handle)
227}
228
229#[tauri::command]
230pub fn show_system_window(
231 wm: State<WindowManager>,
232 handle: u64
233) -> Result<(), String> {
234 wm.show_system_window(handle)
235}
236
237#[tauri::command]
238pub fn arrange_system_windows(
239 wm: State<WindowManager>,
240 window_handles: Vec<u64>
241) -> Result<(), String> {
242 wm.arrange_system_windows(&window_handles)
243}