tony / oxwm

replace explicit Result types with `WmResult` alias in `window_manager` Browse files
emzywastaken committed 2025-10-13 parent 0c27cae commit 96dd81e72a1af0601d51f97e277247b2d4b77a20
Showing 1 changed file with 24 additions and 32 deletions. UnifiedSplit
+24 −32 src/window_manager.rs
@@ -36,7 +36,6 @@ pub struct WindowManager {
36 36
37 37 // TODO: Eliminate all library level `anyhow::Error`
38 38 #[derive(Debug)]
39 -#[non_exhaustive]
40 39 pub enum WmError {
41 40 X11(X11Error),
42 41 Io(std::io::Error),
@@ -44,7 +43,6 @@ pub enum WmError {
44 43 }
45 44
46 45 #[derive(Debug)]
47 -#[non_exhaustive]
48 46 pub enum X11Error {
49 47 ConnectError(x11rb::errors::ConnectError),
50 48 ConnectionError(x11rb::errors::ConnectionError),
@@ -52,6 +50,8 @@ pub enum X11Error {
52 50 ReplyOrIdError(x11rb::errors::ReplyOrIdError),
53 51 }
54 52
53 +type WmResult<T> = Result<T, WmError>;
54 +
55 55 impl std::fmt::Display for WmError {
56 56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 57 match self {
@@ -113,7 +113,7 @@ impl From<anyhow::Error> for WmError {
113 113 }
114 114
115 115 impl WindowManager {
116 - pub fn new(config: Config) -> std::result::Result<Self, WmError> {
116 + pub fn new(config: Config) -> WmResult<Self> {
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, WmError> {
203 + ) -> WmResult<TagMask> {
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<(), WmError> {
233 + fn scan_existing_windows(&mut self) -> WmResult<()> {
234 234 let tree = self.connection.query_tree(self.root)?.reply()?;
235 235 let net_client_info = self
236 236 .connection
@@ -297,11 +297,7 @@ impl WindowManager {
297 297 Ok(())
298 298 }
299 299
300 - fn get_saved_tag(
301 - &self,
302 - window: Window,
303 - net_client_info: Atom,
304 - ) -> std::result::Result<TagMask, WmError> {
300 + fn get_saved_tag(&self, window: Window, net_client_info: Atom) -> WmResult<TagMask> {
305 301 match self
306 302 .connection
307 303 .get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)?
@@ -328,7 +324,7 @@ impl WindowManager {
328 324 Ok(self.selected_tags)
329 325 }
330 326
331 - fn save_client_tag(&self, window: Window, tag: TagMask) -> std::result::Result<(), WmError> {
327 + fn save_client_tag(&self, window: Window, tag: TagMask) -> WmResult<()> {
332 328 let net_client_info = self
333 329 .connection
334 330 .intern_atom(false, b"_NET_CLIENT_INFO")?
@@ -351,7 +347,7 @@ impl WindowManager {
351 347 Ok(())
352 348 }
353 349
354 - fn set_wm_state(&self, window: Window, state: u32) -> std::result::Result<(), WmError> {
350 + fn set_wm_state(&self, window: Window, state: u32) -> WmResult<()> {
355 351 let wm_state_atom = self
356 352 .connection
357 353 .intern_atom(false, b"WM_STATE")?
@@ -375,7 +371,7 @@ impl WindowManager {
375 371 Ok(())
376 372 }
377 373
378 - pub fn run(&mut self) -> std::result::Result<bool, WmError> {
374 + pub fn run(&mut self) -> WmResult<bool> {
379 375 println!("oxwm started on display {}", self.screen_number);
380 376
381 377 // TODO: Identify errors
@@ -400,7 +396,7 @@ impl WindowManager {
400 396 }
401 397 }
402 398
403 - fn toggle_fullscreen(&mut self) -> std::result::Result<(), WmError> {
399 + fn toggle_fullscreen(&mut self) -> WmResult<()> {
404 400 if let Some(focused) = self.focused_window {
405 401 if self.fullscreen_window == Some(focused) {
406 402 self.fullscreen_window = None;
@@ -434,7 +430,7 @@ impl WindowManager {
434 430 Ok(())
435 431 }
436 432
437 - fn update_bar(&mut self) -> std::result::Result<(), WmError> {
433 + fn update_bar(&mut self) -> WmResult<()> {
438 434 let mut occupied_tags: TagMask = 0;
439 435 for &tags in self.window_tags.values() {
440 436 occupied_tags |= tags;
@@ -447,11 +443,7 @@ impl WindowManager {
447 443 Ok(())
448 444 }
449 445
450 - fn handle_key_action(
451 - &mut self,
452 - action: KeyAction,
453 - arg: &Arg,
454 - ) -> std::result::Result<(), WmError> {
446 + fn handle_key_action(&mut self, action: KeyAction, arg: &Arg) -> WmResult<()> {
455 447 match action {
456 448 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?,
457 449 KeyAction::KillClient => {
@@ -521,7 +513,7 @@ impl WindowManager {
521 513 .collect()
522 514 }
523 515
524 - fn update_window_visibility(&self) -> std::result::Result<(), WmError> {
516 + fn update_window_visibility(&self) -> WmResult<()> {
525 517 for &window in &self.windows {
526 518 if self.is_window_visible(window) {
527 519 self.connection.map_window(window)?;
@@ -533,7 +525,7 @@ impl WindowManager {
533 525 Ok(())
534 526 }
535 527
536 - pub fn view_tag(&mut self, tag_index: usize) -> std::result::Result<(), WmError> {
528 + pub fn view_tag(&mut self, tag_index: usize) -> WmResult<()> {
537 529 if tag_index >= self.config.tags.len() {
538 530 return Ok(());
539 531 }
@@ -557,7 +549,7 @@ impl WindowManager {
557 549 Ok(())
558 550 }
559 551
560 - fn save_selected_tags(&self) -> std::result::Result<(), WmError> {
552 + fn save_selected_tags(&self) -> WmResult<()> {
561 553 let net_current_desktop = self
562 554 .connection
563 555 .intern_atom(false, b"_NET_CURRENT_DESKTOP")?
@@ -581,7 +573,7 @@ impl WindowManager {
581 573 Ok(())
582 574 }
583 575
584 - pub fn move_to_tag(&mut self, tag_index: usize) -> std::result::Result<(), WmError> {
576 + pub fn move_to_tag(&mut self, tag_index: usize) -> WmResult<()> {
585 577 if tag_index >= self.config.tags.len() {
586 578 return Ok(());
587 579 }
@@ -600,7 +592,7 @@ impl WindowManager {
600 592 Ok(())
601 593 }
602 594
603 - pub fn cycle_focus(&mut self, direction: i32) -> std::result::Result<(), WmError> {
595 + pub fn cycle_focus(&mut self, direction: i32) -> WmResult<()> {
604 596 let visible = self.visible_windows();
605 597
606 598 if visible.is_empty() {
@@ -626,7 +618,7 @@ impl WindowManager {
626 618 Ok(())
627 619 }
628 620
629 - pub fn set_focus(&mut self, window: Option<Window>) -> std::result::Result<(), WmError> {
621 + pub fn set_focus(&mut self, window: Option<Window>) -> WmResult<()> {
630 622 self.focused_window = window;
631 623
632 624 if let Some(win) = window {
@@ -639,7 +631,7 @@ impl WindowManager {
639 631 Ok(())
640 632 }
641 633
642 - fn update_focus_visuals(&self) -> std::result::Result<(), WmError> {
634 + fn update_focus_visuals(&self) -> WmResult<()> {
643 635 for &window in &self.windows {
644 636 let (border_color, border_width) = if self.focused_window == Some(window) {
645 637 (self.config.border_focused, self.config.border_width)
@@ -661,7 +653,7 @@ impl WindowManager {
661 653 Ok(())
662 654 }
663 655
664 - fn move_mouse(&mut self, window: Window) -> std::result::Result<(), WmError> {
656 + fn move_mouse(&mut self, window: Window) -> WmResult<()> {
665 657 self.floating_windows.insert(window);
666 658
667 659 let geometry = self.connection.get_geometry(window)?.reply()?;
@@ -714,7 +706,7 @@ impl WindowManager {
714 706 Ok(())
715 707 }
716 708
717 - fn resize_mouse(&mut self, window: Window) -> std::result::Result<(), WmError> {
709 + fn resize_mouse(&mut self, window: Window) -> WmResult<()> {
718 710 self.floating_windows.insert(window);
719 711
720 712 let geometry = self.connection.get_geometry(window)?.reply()?;
@@ -778,7 +770,7 @@ impl WindowManager {
778 770 Ok(())
779 771 }
780 772
781 - fn handle_event(&mut self, event: Event) -> std::result::Result<Option<bool>, WmError> {
773 + fn handle_event(&mut self, event: Event) -> WmResult<Option<bool>> {
782 774 match event {
783 775 Event::MapRequest(event) => {
784 776 let attrs = match self.connection.get_window_attributes(event.window)?.reply() {
@@ -861,7 +853,7 @@ impl WindowManager {
861 853 Ok(None)
862 854 }
863 855
864 - fn apply_layout(&self) -> std::result::Result<(), WmError> {
856 + fn apply_layout(&self) -> WmResult<()> {
865 857 if self.fullscreen_window.is_some() {
866 858 return Ok(());
867 859 }
@@ -917,7 +909,7 @@ impl WindowManager {
917 909 Ok(())
918 910 }
919 911
920 - fn remove_window(&mut self, window: Window) -> std::result::Result<(), WmError> {
912 + fn remove_window(&mut self, window: Window) -> WmResult<()> {
921 913 let initial_count = self.windows.len();
922 914 self.windows.retain(|&w| w != window);
923 915 self.window_tags.remove(&window);