tony / oxwm

rename `WindowManagerError` -> `WmError` Browse files
emzywastaken committed 2025-10-13 parent 93868ba commit 0c27cae203f026d61bf77b04c8d9b5a760981ad3
Showing 1 changed file with 31 additions and 45 deletions. UnifiedSplit
+31 −45 src/window_manager.rs
@@ -37,7 +37,7 @@ pub struct WindowManager {
37 37 // TODO: Eliminate all library level `anyhow::Error`
38 38 #[derive(Debug)]
39 39 #[non_exhaustive]
40 -pub enum WindowManagerError {
40 +pub enum WmError {
41 41 X11(X11Error),
42 42 Io(std::io::Error),
43 43 Anyhow(anyhow::Error),
@@ -52,7 +52,7 @@ pub enum X11Error {
52 52 ReplyOrIdError(x11rb::errors::ReplyOrIdError),
53 53 }
54 54
55 -impl std::fmt::Display for WindowManagerError {
55 +impl std::fmt::Display for WmError {
56 56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 57 match self {
58 58 // Self::X11(x11_error) => write!(f, "{:?}", x11_error),
@@ -63,7 +63,7 @@ impl std::fmt::Display for WindowManagerError {
63 63 }
64 64 }
65 65
66 -impl std::error::Error for WindowManagerError {}
66 +impl std::error::Error for WmError {}
67 67
68 68 impl std::fmt::Display for X11Error {
69 69 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -76,44 +76,44 @@ impl std::fmt::Display for X11Error {
76 76 }
77 77 }
78 78
79 -impl From<X11Error> for WindowManagerError {
79 +impl From<X11Error> for WmError {
80 80 fn from(value: X11Error) -> Self {
81 81 Self::X11(value)
82 82 }
83 83 }
84 84
85 -impl From<x11rb::errors::ConnectError> for WindowManagerError {
85 +impl From<x11rb::errors::ConnectError> for WmError {
86 86 fn from(value: x11rb::errors::ConnectError) -> Self {
87 87 Self::X11(X11Error::ConnectError(value))
88 88 }
89 89 }
90 90
91 -impl From<x11rb::errors::ConnectionError> for WindowManagerError {
91 +impl From<x11rb::errors::ConnectionError> for WmError {
92 92 fn from(value: x11rb::errors::ConnectionError) -> Self {
93 93 Self::X11(X11Error::ConnectionError(value))
94 94 }
95 95 }
96 96
97 -impl From<x11rb::errors::ReplyError> for WindowManagerError {
97 +impl From<x11rb::errors::ReplyError> for WmError {
98 98 fn from(value: x11rb::errors::ReplyError) -> Self {
99 99 Self::X11(X11Error::ReplyError(value))
100 100 }
101 101 }
102 102
103 -impl From<x11rb::errors::ReplyOrIdError> for WindowManagerError {
103 +impl From<x11rb::errors::ReplyOrIdError> for WmError {
104 104 fn from(value: x11rb::errors::ReplyOrIdError) -> Self {
105 105 Self::X11(X11Error::ReplyOrIdError(value))
106 106 }
107 107 }
108 108
109 -impl From<anyhow::Error> for WindowManagerError {
109 +impl From<anyhow::Error> for WmError {
110 110 fn from(value: anyhow::Error) -> Self {
111 111 Self::Anyhow(value)
112 112 }
113 113 }
114 114
115 115 impl WindowManager {
116 - pub fn new(config: Config) -> std::result::Result<Self, WindowManagerError> {
116 + pub fn new(config: Config) -> std::result::Result<Self, WmError> {
117 117 let (connection, screen_number) = x11rb::connect(None)?;
118 118 let root = connection.setup().roots[screen_number].root;
119 119 let screen = connection.setup().roots[screen_number].clone();
@@ -200,7 +200,7 @@ impl WindowManager {
200 200 connection: &RustConnection,
201 201 root: Window,
202 202 tag_count: usize,
203 - ) -> std::result::Result<TagMask, WindowManagerError> {
203 + ) -> std::result::Result<TagMask, WmError> {
204 204 let net_current_desktop = connection
205 205 .intern_atom(false, b"_NET_CURRENT_DESKTOP")?
206 206 .reply()?
@@ -230,7 +230,7 @@ impl WindowManager {
230 230 Ok(tag_mask(0))
231 231 }
232 232
233 - fn scan_existing_windows(&mut self) -> std::result::Result<(), WindowManagerError> {
233 + fn scan_existing_windows(&mut self) -> std::result::Result<(), WmError> {
234 234 let tree = self.connection.query_tree(self.root)?.reply()?;
235 235 let net_client_info = self
236 236 .connection
@@ -301,7 +301,7 @@ impl WindowManager {
301 301 &self,
302 302 window: Window,
303 303 net_client_info: Atom,
304 - ) -> std::result::Result<TagMask, WindowManagerError> {
304 + ) -> std::result::Result<TagMask, WmError> {
305 305 match self
306 306 .connection
307 307 .get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)?
@@ -328,11 +328,7 @@ impl WindowManager {
328 328 Ok(self.selected_tags)
329 329 }
330 330
331 - fn save_client_tag(
332 - &self,
333 - window: Window,
334 - tag: TagMask,
335 - ) -> std::result::Result<(), WindowManagerError> {
331 + fn save_client_tag(&self, window: Window, tag: TagMask) -> std::result::Result<(), WmError> {
336 332 let net_client_info = self
337 333 .connection
338 334 .intern_atom(false, b"_NET_CLIENT_INFO")?
@@ -355,11 +351,7 @@ impl WindowManager {
355 351 Ok(())
356 352 }
357 353
358 - fn set_wm_state(
359 - &self,
360 - window: Window,
361 - state: u32,
362 - ) -> std::result::Result<(), WindowManagerError> {
354 + fn set_wm_state(&self, window: Window, state: u32) -> std::result::Result<(), WmError> {
363 355 let wm_state_atom = self
364 356 .connection
365 357 .intern_atom(false, b"WM_STATE")?
@@ -383,7 +375,7 @@ impl WindowManager {
383 375 Ok(())
384 376 }
385 377
386 - pub fn run(&mut self) -> std::result::Result<bool, WindowManagerError> {
378 + pub fn run(&mut self) -> std::result::Result<bool, WmError> {
387 379 println!("oxwm started on display {}", self.screen_number);
388 380
389 381 // TODO: Identify errors
@@ -408,7 +400,7 @@ impl WindowManager {
408 400 }
409 401 }
410 402
411 - fn toggle_fullscreen(&mut self) -> std::result::Result<(), WindowManagerError> {
403 + fn toggle_fullscreen(&mut self) -> std::result::Result<(), WmError> {
412 404 if let Some(focused) = self.focused_window {
413 405 if self.fullscreen_window == Some(focused) {
414 406 self.fullscreen_window = None;
@@ -442,7 +434,7 @@ impl WindowManager {
442 434 Ok(())
443 435 }
444 436
445 - fn update_bar(&mut self) -> std::result::Result<(), WindowManagerError> {
437 + fn update_bar(&mut self) -> std::result::Result<(), WmError> {
446 438 let mut occupied_tags: TagMask = 0;
447 439 for &tags in self.window_tags.values() {
448 440 occupied_tags |= tags;
@@ -459,7 +451,7 @@ impl WindowManager {
459 451 &mut self,
460 452 action: KeyAction,
461 453 arg: &Arg,
462 - ) -> std::result::Result<(), WindowManagerError> {
454 + ) -> std::result::Result<(), WmError> {
463 455 match action {
464 456 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?,
465 457 KeyAction::KillClient => {
@@ -529,7 +521,7 @@ impl WindowManager {
529 521 .collect()
530 522 }
531 523
532 - fn update_window_visibility(&self) -> std::result::Result<(), WindowManagerError> {
524 + fn update_window_visibility(&self) -> std::result::Result<(), WmError> {
533 525 for &window in &self.windows {
534 526 if self.is_window_visible(window) {
535 527 self.connection.map_window(window)?;
@@ -541,7 +533,7 @@ impl WindowManager {
541 533 Ok(())
542 534 }
543 535
544 - pub fn view_tag(&mut self, tag_index: usize) -> std::result::Result<(), WindowManagerError> {
536 + pub fn view_tag(&mut self, tag_index: usize) -> std::result::Result<(), WmError> {
545 537 if tag_index >= self.config.tags.len() {
546 538 return Ok(());
547 539 }
@@ -565,7 +557,7 @@ impl WindowManager {
565 557 Ok(())
566 558 }
567 559
568 - fn save_selected_tags(&self) -> std::result::Result<(), WindowManagerError> {
560 + fn save_selected_tags(&self) -> std::result::Result<(), WmError> {
569 561 let net_current_desktop = self
570 562 .connection
571 563 .intern_atom(false, b"_NET_CURRENT_DESKTOP")?
@@ -589,7 +581,7 @@ impl WindowManager {
589 581 Ok(())
590 582 }
591 583
592 - pub fn move_to_tag(&mut self, tag_index: usize) -> std::result::Result<(), WindowManagerError> {
584 + pub fn move_to_tag(&mut self, tag_index: usize) -> std::result::Result<(), WmError> {
593 585 if tag_index >= self.config.tags.len() {
594 586 return Ok(());
595 587 }
@@ -608,7 +600,7 @@ impl WindowManager {
608 600 Ok(())
609 601 }
610 602
611 - pub fn cycle_focus(&mut self, direction: i32) -> std::result::Result<(), WindowManagerError> {
603 + pub fn cycle_focus(&mut self, direction: i32) -> std::result::Result<(), WmError> {
612 604 let visible = self.visible_windows();
613 605
614 606 if visible.is_empty() {
@@ -634,10 +626,7 @@ impl WindowManager {
634 626 Ok(())
635 627 }
636 628
637 - pub fn set_focus(
638 - &mut self,
639 - window: Option<Window>,
640 - ) -> std::result::Result<(), WindowManagerError> {
629 + pub fn set_focus(&mut self, window: Option<Window>) -> std::result::Result<(), WmError> {
641 630 self.focused_window = window;
642 631
643 632 if let Some(win) = window {
@@ -650,7 +639,7 @@ impl WindowManager {
650 639 Ok(())
651 640 }
652 641
653 - fn update_focus_visuals(&self) -> std::result::Result<(), WindowManagerError> {
642 + fn update_focus_visuals(&self) -> std::result::Result<(), WmError> {
654 643 for &window in &self.windows {
655 644 let (border_color, border_width) = if self.focused_window == Some(window) {
656 645 (self.config.border_focused, self.config.border_width)
@@ -672,7 +661,7 @@ impl WindowManager {
672 661 Ok(())
673 662 }
674 663
675 - fn move_mouse(&mut self, window: Window) -> std::result::Result<(), WindowManagerError> {
664 + fn move_mouse(&mut self, window: Window) -> std::result::Result<(), WmError> {
676 665 self.floating_windows.insert(window);
677 666
678 667 let geometry = self.connection.get_geometry(window)?.reply()?;
@@ -725,7 +714,7 @@ impl WindowManager {
725 714 Ok(())
726 715 }
727 716
728 - fn resize_mouse(&mut self, window: Window) -> std::result::Result<(), WindowManagerError> {
717 + fn resize_mouse(&mut self, window: Window) -> std::result::Result<(), WmError> {
729 718 self.floating_windows.insert(window);
730 719
731 720 let geometry = self.connection.get_geometry(window)?.reply()?;
@@ -789,10 +778,7 @@ impl WindowManager {
789 778 Ok(())
790 779 }
791 780
792 - fn handle_event(
793 - &mut self,
794 - event: Event,
795 - ) -> std::result::Result<Option<bool>, WindowManagerError> {
781 + fn handle_event(&mut self, event: Event) -> std::result::Result<Option<bool>, WmError> {
796 782 match event {
797 783 Event::MapRequest(event) => {
798 784 let attrs = match self.connection.get_window_attributes(event.window)?.reply() {
@@ -875,7 +861,7 @@ impl WindowManager {
875 861 Ok(None)
876 862 }
877 863
878 - fn apply_layout(&self) -> std::result::Result<(), WindowManagerError> {
864 + fn apply_layout(&self) -> std::result::Result<(), WmError> {
879 865 if self.fullscreen_window.is_some() {
880 866 return Ok(());
881 867 }
@@ -931,7 +917,7 @@ impl WindowManager {
931 917 Ok(())
932 918 }
933 919
934 - fn remove_window(&mut self, window: Window) -> std::result::Result<(), WindowManagerError> {
920 + fn remove_window(&mut self, window: Window) -> std::result::Result<(), WmError> {
935 921 let initial_count = self.windows.len();
936 922 self.windows.retain(|&w| w != window);
937 923 self.window_tags.remove(&window);