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 // TODO: Eliminate all library level `anyhow::Error` 37 // TODO: Eliminate all library level `anyhow::Error`
38 #[derive(Debug)] 38 #[derive(Debug)]
39 #[non_exhaustive] 39 #[non_exhaustive]
40 -pub enum WindowManagerError { 40 +pub enum WmError {
41 X11(X11Error), 41 X11(X11Error),
42 Io(std::io::Error), 42 Io(std::io::Error),
43 Anyhow(anyhow::Error), 43 Anyhow(anyhow::Error),
@@ -52,7 +52,7 @@ pub enum X11Error {
52 ReplyOrIdError(x11rb::errors::ReplyOrIdError), 52 ReplyOrIdError(x11rb::errors::ReplyOrIdError),
53 } 53 }
54 54
55 -impl std::fmt::Display for WindowManagerError { 55 +impl std::fmt::Display for WmError {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 match self { 57 match self {
58 // Self::X11(x11_error) => write!(f, "{:?}", x11_error), 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 impl std::fmt::Display for X11Error { 68 impl std::fmt::Display for X11Error {
69 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 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 fn from(value: X11Error) -> Self { 80 fn from(value: X11Error) -> Self {
81 Self::X11(value) 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 fn from(value: x11rb::errors::ConnectError) -> Self { 86 fn from(value: x11rb::errors::ConnectError) -> Self {
87 Self::X11(X11Error::ConnectError(value)) 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 fn from(value: x11rb::errors::ConnectionError) -> Self { 92 fn from(value: x11rb::errors::ConnectionError) -> Self {
93 Self::X11(X11Error::ConnectionError(value)) 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 fn from(value: x11rb::errors::ReplyError) -> Self { 98 fn from(value: x11rb::errors::ReplyError) -> Self {
99 Self::X11(X11Error::ReplyError(value)) 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 fn from(value: x11rb::errors::ReplyOrIdError) -> Self { 104 fn from(value: x11rb::errors::ReplyOrIdError) -> Self {
105 Self::X11(X11Error::ReplyOrIdError(value)) 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 fn from(value: anyhow::Error) -> Self { 110 fn from(value: anyhow::Error) -> Self {
111 Self::Anyhow(value) 111 Self::Anyhow(value)
112 } 112 }
113 } 113 }
114 114
115 impl WindowManager { 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 let (connection, screen_number) = x11rb::connect(None)?; 117 let (connection, screen_number) = x11rb::connect(None)?;
118 let root = connection.setup().roots[screen_number].root; 118 let root = connection.setup().roots[screen_number].root;
119 let screen = connection.setup().roots[screen_number].clone(); 119 let screen = connection.setup().roots[screen_number].clone();
@@ -200,7 +200,7 @@ impl WindowManager {
200 connection: &RustConnection, 200 connection: &RustConnection,
201 root: Window, 201 root: Window,
202 tag_count: usize, 202 tag_count: usize,
203 - ) -> std::result::Result<TagMask, WindowManagerError> { 203 + ) -> std::result::Result<TagMask, WmError> {
204 let net_current_desktop = connection 204 let net_current_desktop = connection
205 .intern_atom(false, b"_NET_CURRENT_DESKTOP")? 205 .intern_atom(false, b"_NET_CURRENT_DESKTOP")?
206 .reply()? 206 .reply()?
@@ -230,7 +230,7 @@ impl WindowManager {
230 Ok(tag_mask(0)) 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 let tree = self.connection.query_tree(self.root)?.reply()?; 234 let tree = self.connection.query_tree(self.root)?.reply()?;
235 let net_client_info = self 235 let net_client_info = self
236 .connection 236 .connection
@@ -301,7 +301,7 @@ impl WindowManager {
301 &self, 301 &self,
302 window: Window, 302 window: Window,
303 net_client_info: Atom, 303 net_client_info: Atom,
304 - ) -> std::result::Result<TagMask, WindowManagerError> { 304 + ) -> std::result::Result<TagMask, WmError> {
305 match self 305 match self
306 .connection 306 .connection
307 .get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)? 307 .get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)?
@@ -328,11 +328,7 @@ impl WindowManager {
328 Ok(self.selected_tags) 328 Ok(self.selected_tags)
329 } 329 }
330 330
331 - fn save_client_tag( 331 + fn save_client_tag(&self, window: Window, tag: TagMask) -> std::result::Result<(), WmError> {
332 - &self,
333 - window: Window,
334 - tag: TagMask,
335 - ) -> std::result::Result<(), WindowManagerError> {
336 let net_client_info = self 332 let net_client_info = self
337 .connection 333 .connection
338 .intern_atom(false, b"_NET_CLIENT_INFO")? 334 .intern_atom(false, b"_NET_CLIENT_INFO")?
@@ -355,11 +351,7 @@ impl WindowManager {
355 Ok(()) 351 Ok(())
356 } 352 }
357 353
358 - fn set_wm_state( 354 + fn set_wm_state(&self, window: Window, state: u32) -> std::result::Result<(), WmError> {
359 - &self,
360 - window: Window,
361 - state: u32,
362 - ) -> std::result::Result<(), WindowManagerError> {
363 let wm_state_atom = self 355 let wm_state_atom = self
364 .connection 356 .connection
365 .intern_atom(false, b"WM_STATE")? 357 .intern_atom(false, b"WM_STATE")?
@@ -383,7 +375,7 @@ impl WindowManager {
383 Ok(()) 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 println!("oxwm started on display {}", self.screen_number); 379 println!("oxwm started on display {}", self.screen_number);
388 380
389 // TODO: Identify errors 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 if let Some(focused) = self.focused_window { 404 if let Some(focused) = self.focused_window {
413 if self.fullscreen_window == Some(focused) { 405 if self.fullscreen_window == Some(focused) {
414 self.fullscreen_window = None; 406 self.fullscreen_window = None;
@@ -442,7 +434,7 @@ impl WindowManager {
442 Ok(()) 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 let mut occupied_tags: TagMask = 0; 438 let mut occupied_tags: TagMask = 0;
447 for &tags in self.window_tags.values() { 439 for &tags in self.window_tags.values() {
448 occupied_tags |= tags; 440 occupied_tags |= tags;
@@ -459,7 +451,7 @@ impl WindowManager {
459 &mut self, 451 &mut self,
460 action: KeyAction, 452 action: KeyAction,
461 arg: &Arg, 453 arg: &Arg,
462 - ) -> std::result::Result<(), WindowManagerError> { 454 + ) -> std::result::Result<(), WmError> {
463 match action { 455 match action {
464 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, 456 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?,
465 KeyAction::KillClient => { 457 KeyAction::KillClient => {
@@ -529,7 +521,7 @@ impl WindowManager {
529 .collect() 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 for &window in &self.windows { 525 for &window in &self.windows {
534 if self.is_window_visible(window) { 526 if self.is_window_visible(window) {
535 self.connection.map_window(window)?; 527 self.connection.map_window(window)?;
@@ -541,7 +533,7 @@ impl WindowManager {
541 Ok(()) 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 if tag_index >= self.config.tags.len() { 537 if tag_index >= self.config.tags.len() {
546 return Ok(()); 538 return Ok(());
547 } 539 }
@@ -565,7 +557,7 @@ impl WindowManager {
565 Ok(()) 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 let net_current_desktop = self 561 let net_current_desktop = self
570 .connection 562 .connection
571 .intern_atom(false, b"_NET_CURRENT_DESKTOP")? 563 .intern_atom(false, b"_NET_CURRENT_DESKTOP")?
@@ -589,7 +581,7 @@ impl WindowManager {
589 Ok(()) 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 if tag_index >= self.config.tags.len() { 585 if tag_index >= self.config.tags.len() {
594 return Ok(()); 586 return Ok(());
595 } 587 }
@@ -608,7 +600,7 @@ impl WindowManager {
608 Ok(()) 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 let visible = self.visible_windows(); 604 let visible = self.visible_windows();
613 605
614 if visible.is_empty() { 606 if visible.is_empty() {
@@ -634,10 +626,7 @@ impl WindowManager {
634 Ok(()) 626 Ok(())
635 } 627 }
636 628
637 - pub fn set_focus( 629 + pub fn set_focus(&mut self, window: Option<Window>) -> std::result::Result<(), WmError> {
638 - &mut self,
639 - window: Option<Window>,
640 - ) -> std::result::Result<(), WindowManagerError> {
641 self.focused_window = window; 630 self.focused_window = window;
642 631
643 if let Some(win) = window { 632 if let Some(win) = window {
@@ -650,7 +639,7 @@ impl WindowManager {
650 Ok(()) 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 for &window in &self.windows { 643 for &window in &self.windows {
655 let (border_color, border_width) = if self.focused_window == Some(window) { 644 let (border_color, border_width) = if self.focused_window == Some(window) {
656 (self.config.border_focused, self.config.border_width) 645 (self.config.border_focused, self.config.border_width)
@@ -672,7 +661,7 @@ impl WindowManager {
672 Ok(()) 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 self.floating_windows.insert(window); 665 self.floating_windows.insert(window);
677 666
678 let geometry = self.connection.get_geometry(window)?.reply()?; 667 let geometry = self.connection.get_geometry(window)?.reply()?;
@@ -725,7 +714,7 @@ impl WindowManager {
725 Ok(()) 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 self.floating_windows.insert(window); 718 self.floating_windows.insert(window);
730 719
731 let geometry = self.connection.get_geometry(window)?.reply()?; 720 let geometry = self.connection.get_geometry(window)?.reply()?;
@@ -789,10 +778,7 @@ impl WindowManager {
789 Ok(()) 778 Ok(())
790 } 779 }
791 780
792 - fn handle_event( 781 + fn handle_event(&mut self, event: Event) -> std::result::Result<Option<bool>, WmError> {
793 - &mut self,
794 - event: Event,
795 - ) -> std::result::Result<Option<bool>, WindowManagerError> {
796 match event { 782 match event {
797 Event::MapRequest(event) => { 783 Event::MapRequest(event) => {
798 let attrs = match self.connection.get_window_attributes(event.window)?.reply() { 784 let attrs = match self.connection.get_window_attributes(event.window)?.reply() {
@@ -875,7 +861,7 @@ impl WindowManager {
875 Ok(None) 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 if self.fullscreen_window.is_some() { 865 if self.fullscreen_window.is_some() {
880 return Ok(()); 866 return Ok(());
881 } 867 }
@@ -931,7 +917,7 @@ impl WindowManager {
931 Ok(()) 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 let initial_count = self.windows.len(); 921 let initial_count = self.windows.len();
936 self.windows.retain(|&w| w != window); 922 self.windows.retain(|&w| w != window);
937 self.window_tags.remove(&window); 923 self.window_tags.remove(&window);