|
|
@@ -1,12 +1,11 @@ |
| 1 |
1 |
use crate::Config; |
| 2 |
2 |
use crate::bar::Bar; |
|
3 |
+use crate::errors::WmError; |
| 3 |
4 |
use crate::keyboard::{self, Arg, KeyAction, handlers}; |
| 4 |
5 |
use crate::layout::GapConfig; |
| 5 |
6 |
use crate::layout::Layout; |
| 6 |
7 |
use crate::layout::tiling::TilingLayout; |
| 7 |
|
-use anyhow::Result; |
| 8 |
8 |
use std::collections::HashSet; |
| 9 |
|
-use std::path::PathBuf; |
| 10 |
9 |
use x11rb::cursor::Handle as CursorHandle; |
| 11 |
10 |
|
| 12 |
11 |
use x11rb::connection::Connection; |
|
|
@@ -36,8 +35,10 @@ pub struct WindowManager { |
| 36 |
35 |
bar: Bar, |
| 37 |
36 |
} |
| 38 |
37 |
|
|
38 |
+type WmResult<T> = Result<T, WmError>; |
|
39 |
+ |
| 39 |
40 |
impl WindowManager { |
| 40 |
|
- pub fn new(config: Config) -> Result<Self> { |
|
41 |
+ pub fn new(config: Config) -> WmResult<Self> { |
| 41 |
42 |
let (connection, screen_number) = x11rb::connect(None)?; |
| 42 |
43 |
let root = connection.setup().roots[screen_number].root; |
| 43 |
44 |
let screen = connection.setup().roots[screen_number].clone(); |
|
|
@@ -121,7 +122,7 @@ impl WindowManager { |
| 121 |
122 |
connection: &RustConnection, |
| 122 |
123 |
root: Window, |
| 123 |
124 |
tag_count: usize, |
| 124 |
|
- ) -> Result<TagMask> { |
|
125 |
+ ) -> WmResult<TagMask> { |
| 125 |
126 |
let net_current_desktop = connection |
| 126 |
127 |
.intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
| 127 |
128 |
.reply()? |
|
|
@@ -151,7 +152,7 @@ impl WindowManager { |
| 151 |
152 |
Ok(tag_mask(0)) |
| 152 |
153 |
} |
| 153 |
154 |
|
| 154 |
|
- fn scan_existing_windows(&mut self) -> Result<()> { |
|
155 |
+ fn scan_existing_windows(&mut self) -> WmResult<()> { |
| 155 |
156 |
let tree = self.connection.query_tree(self.root)?.reply()?; |
| 156 |
157 |
let net_client_info = self |
| 157 |
158 |
.connection |
|
|
@@ -218,7 +219,7 @@ impl WindowManager { |
| 218 |
219 |
Ok(()) |
| 219 |
220 |
} |
| 220 |
221 |
|
| 221 |
|
- fn get_saved_tag(&self, window: Window, net_client_info: Atom) -> Result<TagMask> { |
|
222 |
+ fn get_saved_tag(&self, window: Window, net_client_info: Atom) -> WmResult<TagMask> { |
| 222 |
223 |
match self |
| 223 |
224 |
.connection |
| 224 |
225 |
.get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)? |
|
|
@@ -245,7 +246,7 @@ impl WindowManager { |
| 245 |
246 |
Ok(self.selected_tags) |
| 246 |
247 |
} |
| 247 |
248 |
|
| 248 |
|
- fn save_client_tag(&self, window: Window, tag: TagMask) -> Result<()> { |
|
249 |
+ fn save_client_tag(&self, window: Window, tag: TagMask) -> WmResult<()> { |
| 249 |
250 |
let net_client_info = self |
| 250 |
251 |
.connection |
| 251 |
252 |
.intern_atom(false, b"_NET_CLIENT_INFO")? |
|
|
@@ -268,7 +269,7 @@ impl WindowManager { |
| 268 |
269 |
Ok(()) |
| 269 |
270 |
} |
| 270 |
271 |
|
| 271 |
|
- fn set_wm_state(&self, window: Window, state: u32) -> Result<()> { |
|
272 |
+ fn set_wm_state(&self, window: Window, state: u32) -> WmResult<()> { |
| 272 |
273 |
let wm_state_atom = self |
| 273 |
274 |
.connection |
| 274 |
275 |
.intern_atom(false, b"WM_STATE")? |
|
|
@@ -292,14 +293,14 @@ impl WindowManager { |
| 292 |
293 |
Ok(()) |
| 293 |
294 |
} |
| 294 |
295 |
|
| 295 |
|
- pub fn run(&mut self) -> Result<bool> { |
|
296 |
+ pub fn run(&mut self) -> WmResult<bool> { |
| 296 |
297 |
println!("oxwm started on display {}", self.screen_number); |
| 297 |
298 |
|
| 298 |
299 |
keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?; |
| 299 |
300 |
self.update_bar()?; |
| 300 |
301 |
|
| 301 |
302 |
loop { |
| 302 |
|
- self.bar.update_blocks()?; |
|
303 |
+ self.bar.update_blocks(); |
| 303 |
304 |
|
| 304 |
305 |
if let Ok(Some(event)) = self.connection.poll_for_event() { |
| 305 |
306 |
if let Some(should_restart) = self.handle_event(event)? { |
|
|
@@ -315,7 +316,7 @@ impl WindowManager { |
| 315 |
316 |
} |
| 316 |
317 |
} |
| 317 |
318 |
|
| 318 |
|
- fn toggle_floating(&mut self) -> Result<()> { |
|
319 |
+ fn toggle_floating(&mut self) -> WmResult<()> { |
| 319 |
320 |
if let Some(focused) = self.focused_window { |
| 320 |
321 |
if self.floating_windows.contains(&focused) { |
| 321 |
322 |
self.floating_windows.remove(&focused); |
|
|
@@ -333,7 +334,7 @@ impl WindowManager { |
| 333 |
334 |
Ok(()) |
| 334 |
335 |
} |
| 335 |
336 |
|
| 336 |
|
- fn toggle_fullscreen(&mut self) -> Result<()> { |
|
337 |
+ fn toggle_fullscreen(&mut self) -> WmResult<()> { |
| 337 |
338 |
if let Some(focused) = self.focused_window { |
| 338 |
339 |
if self.fullscreen_window == Some(focused) { |
| 339 |
340 |
self.fullscreen_window = None; |
|
|
@@ -367,7 +368,7 @@ impl WindowManager { |
| 367 |
368 |
Ok(()) |
| 368 |
369 |
} |
| 369 |
370 |
|
| 370 |
|
- fn update_bar(&mut self) -> Result<()> { |
|
371 |
+ fn update_bar(&mut self) -> WmResult<()> { |
| 371 |
372 |
let mut occupied_tags: TagMask = 0; |
| 372 |
373 |
for &tags in self.window_tags.values() { |
| 373 |
374 |
occupied_tags |= tags; |
|
|
@@ -379,7 +380,7 @@ impl WindowManager { |
| 379 |
380 |
Ok(()) |
| 380 |
381 |
} |
| 381 |
382 |
|
| 382 |
|
- fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> Result<()> { |
|
383 |
+ fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> { |
| 383 |
384 |
match action { |
| 384 |
385 |
KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, |
| 385 |
386 |
KeyAction::KillClient => { |
|
|
@@ -453,7 +454,7 @@ impl WindowManager { |
| 453 |
454 |
.collect() |
| 454 |
455 |
} |
| 455 |
456 |
|
| 456 |
|
- fn update_window_visibility(&self) -> Result<()> { |
|
457 |
+ fn update_window_visibility(&self) -> WmResult<()> { |
| 457 |
458 |
for &window in &self.windows { |
| 458 |
459 |
if self.is_window_visible(window) { |
| 459 |
460 |
self.connection.map_window(window)?; |
|
|
@@ -465,7 +466,7 @@ impl WindowManager { |
| 465 |
466 |
Ok(()) |
| 466 |
467 |
} |
| 467 |
468 |
|
| 468 |
|
- pub fn view_tag(&mut self, tag_index: usize) -> Result<()> { |
|
469 |
+ pub fn view_tag(&mut self, tag_index: usize) -> WmResult<()> { |
| 469 |
470 |
if tag_index >= self.config.tags.len() { |
| 470 |
471 |
return Ok(()); |
| 471 |
472 |
} |
|
|
@@ -489,7 +490,7 @@ impl WindowManager { |
| 489 |
490 |
Ok(()) |
| 490 |
491 |
} |
| 491 |
492 |
|
| 492 |
|
- fn save_selected_tags(&self) -> Result<()> { |
|
493 |
+ fn save_selected_tags(&self) -> WmResult<()> { |
| 493 |
494 |
let net_current_desktop = self |
| 494 |
495 |
.connection |
| 495 |
496 |
.intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
|
|
@@ -513,7 +514,7 @@ impl WindowManager { |
| 513 |
514 |
Ok(()) |
| 514 |
515 |
} |
| 515 |
516 |
|
| 516 |
|
- pub fn move_to_tag(&mut self, tag_index: usize) -> Result<()> { |
|
517 |
+ pub fn move_to_tag(&mut self, tag_index: usize) -> WmResult<()> { |
| 517 |
518 |
if tag_index >= self.config.tags.len() { |
| 518 |
519 |
return Ok(()); |
| 519 |
520 |
} |
|
|
@@ -532,7 +533,7 @@ impl WindowManager { |
| 532 |
533 |
Ok(()) |
| 533 |
534 |
} |
| 534 |
535 |
|
| 535 |
|
- pub fn cycle_focus(&mut self, direction: i32) -> Result<()> { |
|
536 |
+ pub fn cycle_focus(&mut self, direction: i32) -> WmResult<()> { |
| 536 |
537 |
let visible = self.visible_windows(); |
| 537 |
538 |
|
| 538 |
539 |
if visible.is_empty() { |
|
|
@@ -558,7 +559,7 @@ impl WindowManager { |
| 558 |
559 |
Ok(()) |
| 559 |
560 |
} |
| 560 |
561 |
|
| 561 |
|
- pub fn set_focus(&mut self, window: Option<Window>) -> Result<()> { |
|
562 |
+ pub fn set_focus(&mut self, window: Option<Window>) -> WmResult<()> { |
| 562 |
563 |
self.focused_window = window; |
| 563 |
564 |
|
| 564 |
565 |
if let Some(win) = window { |
|
|
@@ -571,7 +572,7 @@ impl WindowManager { |
| 571 |
572 |
Ok(()) |
| 572 |
573 |
} |
| 573 |
574 |
|
| 574 |
|
- fn update_focus_visuals(&self) -> Result<()> { |
|
575 |
+ fn update_focus_visuals(&self) -> WmResult<()> { |
| 575 |
576 |
for &window in &self.windows { |
| 576 |
577 |
let (border_color, border_width) = if self.focused_window == Some(window) { |
| 577 |
578 |
(self.config.border_focused, self.config.border_width) |
|
|
@@ -593,7 +594,7 @@ impl WindowManager { |
| 593 |
594 |
Ok(()) |
| 594 |
595 |
} |
| 595 |
596 |
|
| 596 |
|
- fn move_mouse(&mut self, window: Window) -> Result<()> { |
|
597 |
+ fn move_mouse(&mut self, window: Window) -> WmResult<()> { |
| 597 |
598 |
self.floating_windows.insert(window); |
| 598 |
599 |
|
| 599 |
600 |
let geometry = self.connection.get_geometry(window)?.reply()?; |
|
|
@@ -646,7 +647,7 @@ impl WindowManager { |
| 646 |
647 |
Ok(()) |
| 647 |
648 |
} |
| 648 |
649 |
|
| 649 |
|
- fn resize_mouse(&mut self, window: Window) -> Result<()> { |
|
650 |
+ fn resize_mouse(&mut self, window: Window) -> WmResult<()> { |
| 650 |
651 |
self.floating_windows.insert(window); |
| 651 |
652 |
|
| 652 |
653 |
let geometry = self.connection.get_geometry(window)?.reply()?; |
|
|
@@ -710,7 +711,7 @@ impl WindowManager { |
| 710 |
711 |
Ok(()) |
| 711 |
712 |
} |
| 712 |
713 |
|
| 713 |
|
- fn handle_event(&mut self, event: Event) -> Result<Option<bool>> { |
|
714 |
+ fn handle_event(&mut self, event: Event) -> WmResult<Option<bool>> { |
| 714 |
715 |
match event { |
| 715 |
716 |
Event::MapRequest(event) => { |
| 716 |
717 |
let attrs = match self.connection.get_window_attributes(event.window)?.reply() { |
|
|
@@ -760,7 +761,7 @@ impl WindowManager { |
| 760 |
761 |
} |
| 761 |
762 |
} |
| 762 |
763 |
Event::KeyPress(event) => { |
| 763 |
|
- let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings)?; |
|
764 |
+ let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings); |
| 764 |
765 |
match action { |
| 765 |
766 |
KeyAction::Quit => return Ok(Some(false)), |
| 766 |
767 |
KeyAction::Restart => return Ok(Some(true)), |
|
|
@@ -793,7 +794,7 @@ impl WindowManager { |
| 793 |
794 |
Ok(None) |
| 794 |
795 |
} |
| 795 |
796 |
|
| 796 |
|
- fn apply_layout(&self) -> Result<()> { |
|
797 |
+ fn apply_layout(&self) -> WmResult<()> { |
| 797 |
798 |
if self.fullscreen_window.is_some() { |
| 798 |
799 |
return Ok(()); |
| 799 |
800 |
} |
|
|
@@ -849,7 +850,7 @@ impl WindowManager { |
| 849 |
850 |
Ok(()) |
| 850 |
851 |
} |
| 851 |
852 |
|
| 852 |
|
- fn remove_window(&mut self, window: Window) -> Result<()> { |
|
853 |
+ fn remove_window(&mut self, window: Window) -> WmResult<()> { |
| 853 |
854 |
let initial_count = self.windows.len(); |
| 854 |
855 |
self.windows.retain(|&w| w != window); |
| 855 |
856 |
self.window_tags.remove(&window); |