update more "leaf" functions to new concrete error type
Browse files
- "leaf" refering to functions that dont call many others
+29 −20 src/window_manager.rs
| @@ -210,8 +210,8 @@ impl WindowManager { | ||
| 210 | 210 | bar, |
| 211 | 211 | }; |
| 212 | 212 | |
| 213 | - // TODO: identify error types | |
| 214 | 213 | window_manager.scan_existing_windows()?; |
| 214 | + // TODO: identify error types | |
| 215 | 215 | window_manager.update_bar()?; |
| 216 | 216 | |
| 217 | 217 | Ok(window_manager) |
| @@ -251,7 +251,7 @@ impl WindowManager { | ||
| 251 | 251 | Ok(tag_mask(0)) |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - fn scan_existing_windows(&mut self) -> Result<()> { | |
| 254 | + fn scan_existing_windows(&mut self) -> std::result::Result<(), WindowManagerError> { | |
| 255 | 255 | let tree = self.connection.query_tree(self.root)?.reply()?; |
| 256 | 256 | let net_client_info = self |
| 257 | 257 | .connection |
| @@ -279,7 +279,6 @@ impl WindowManager { | ||
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | if attrs.map_state == MapState::VIEWABLE { |
| 282 | - // TODO: Identify errors | |
| 283 | 282 | let tag = self.get_saved_tag(window, net_client_info)?; |
| 284 | 283 | self.windows.push(window); |
| 285 | 284 | self.window_tags.insert(window, tag); |
| @@ -304,7 +303,6 @@ impl WindowManager { | ||
| 304 | 303 | .is_ok_and(|prop| !prop.value.is_empty()); |
| 305 | 304 | |
| 306 | 305 | if has_wm_class { |
| 307 | - // TODO: Identify errors | |
| 308 | 306 | let tag = self.get_saved_tag(window, net_client_info)?; |
| 309 | 307 | self.windows.push(window); |
| 310 | 308 | self.window_tags.insert(window, tag); |
| @@ -313,16 +311,18 @@ impl WindowManager { | ||
| 313 | 311 | } |
| 314 | 312 | |
| 315 | 313 | if let Some(&first) = self.windows.first() { |
| 316 | - // TODO: Identify errors | |
| 317 | 314 | self.set_focus(Some(first))?; |
| 318 | 315 | } |
| 319 | 316 | |
| 320 | - // TODO: Identify errors | |
| 321 | 317 | self.apply_layout()?; |
| 322 | 318 | Ok(()) |
| 323 | 319 | } |
| 324 | 320 | |
| 325 | - fn get_saved_tag(&self, window: Window, net_client_info: Atom) -> Result<TagMask> { | |
| 321 | + fn get_saved_tag( | |
| 322 | + &self, | |
| 323 | + window: Window, | |
| 324 | + net_client_info: Atom, | |
| 325 | + ) -> std::result::Result<TagMask, WindowManagerError> { | |
| 326 | 326 | match self |
| 327 | 327 | .connection |
| 328 | 328 | .get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)? |
| @@ -349,7 +349,11 @@ impl WindowManager { | ||
| 349 | 349 | Ok(self.selected_tags) |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - fn save_client_tag(&self, window: Window, tag: TagMask) -> Result<()> { | |
| 352 | + fn save_client_tag( | |
| 353 | + &self, | |
| 354 | + window: Window, | |
| 355 | + tag: TagMask, | |
| 356 | + ) -> std::result::Result<(), WindowManagerError> { | |
| 353 | 357 | let net_client_info = self |
| 354 | 358 | .connection |
| 355 | 359 | .intern_atom(false, b"_NET_CLIENT_INFO")? |
| @@ -372,7 +376,11 @@ impl WindowManager { | ||
| 372 | 376 | Ok(()) |
| 373 | 377 | } |
| 374 | 378 | |
| 375 | - fn set_wm_state(&self, window: Window, state: u32) -> Result<()> { | |
| 379 | + fn set_wm_state( | |
| 380 | + &self, | |
| 381 | + window: Window, | |
| 382 | + state: u32, | |
| 383 | + ) -> std::result::Result<(), WindowManagerError> { | |
| 376 | 384 | let wm_state_atom = self |
| 377 | 385 | .connection |
| 378 | 386 | .intern_atom(false, b"WM_STATE")? |
| @@ -421,14 +429,13 @@ impl WindowManager { | ||
| 421 | 429 | } |
| 422 | 430 | } |
| 423 | 431 | |
| 424 | - fn toggle_fullscreen(&mut self) -> Result<()> { | |
| 432 | + fn toggle_fullscreen(&mut self) -> std::result::Result<(), WindowManagerError> { | |
| 425 | 433 | if let Some(focused) = self.focused_window { |
| 426 | 434 | if self.fullscreen_window == Some(focused) { |
| 427 | 435 | self.fullscreen_window = None; |
| 428 | 436 | |
| 429 | 437 | self.connection.map_window(self.bar.window())?; |
| 430 | 438 | |
| 431 | - // TODO: Identify errors | |
| 432 | 439 | self.apply_layout()?; |
| 433 | 440 | self.update_focus_visuals()?; |
| 434 | 441 | } else { |
| @@ -539,7 +546,7 @@ impl WindowManager { | ||
| 539 | 546 | .collect() |
| 540 | 547 | } |
| 541 | 548 | |
| 542 | - fn update_window_visibility(&self) -> Result<()> { | |
| 549 | + fn update_window_visibility(&self) -> std::result::Result<(), WindowManagerError> { | |
| 543 | 550 | for &window in &self.windows { |
| 544 | 551 | if self.is_window_visible(window) { |
| 545 | 552 | self.connection.map_window(window)?; |
| @@ -575,7 +582,7 @@ impl WindowManager { | ||
| 575 | 582 | Ok(()) |
| 576 | 583 | } |
| 577 | 584 | |
| 578 | - fn save_selected_tags(&self) -> Result<()> { | |
| 585 | + fn save_selected_tags(&self) -> std::result::Result<(), WindowManagerError> { | |
| 579 | 586 | let net_current_desktop = self |
| 580 | 587 | .connection |
| 581 | 588 | .intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
| @@ -644,7 +651,10 @@ impl WindowManager { | ||
| 644 | 651 | Ok(()) |
| 645 | 652 | } |
| 646 | 653 | |
| 647 | - pub fn set_focus(&mut self, window: Option<Window>) -> Result<()> { | |
| 654 | + pub fn set_focus( | |
| 655 | + &mut self, | |
| 656 | + window: Option<Window>, | |
| 657 | + ) -> std::result::Result<(), WindowManagerError> { | |
| 648 | 658 | self.focused_window = window; |
| 649 | 659 | |
| 650 | 660 | if let Some(win) = window { |
| @@ -653,12 +663,11 @@ impl WindowManager { | ||
| 653 | 663 | self.connection.flush()?; |
| 654 | 664 | } |
| 655 | 665 | |
| 656 | - // TODO: Indentify errors | |
| 657 | 666 | self.update_focus_visuals()?; |
| 658 | 667 | Ok(()) |
| 659 | 668 | } |
| 660 | 669 | |
| 661 | - fn update_focus_visuals(&self) -> Result<()> { | |
| 670 | + fn update_focus_visuals(&self) -> std::result::Result<(), WindowManagerError> { | |
| 662 | 671 | for &window in &self.windows { |
| 663 | 672 | let (border_color, border_width) = if self.focused_window == Some(window) { |
| 664 | 673 | (self.config.border_focused, self.config.border_width) |
| @@ -680,7 +689,7 @@ impl WindowManager { | ||
| 680 | 689 | Ok(()) |
| 681 | 690 | } |
| 682 | 691 | |
| 683 | - fn move_mouse(&mut self, window: Window) -> Result<()> { | |
| 692 | + fn move_mouse(&mut self, window: Window) -> std::result::Result<(), WindowManagerError> { | |
| 684 | 693 | self.floating_windows.insert(window); |
| 685 | 694 | |
| 686 | 695 | let geometry = self.connection.get_geometry(window)?.reply()?; |
| @@ -733,7 +742,7 @@ impl WindowManager { | ||
| 733 | 742 | Ok(()) |
| 734 | 743 | } |
| 735 | 744 | |
| 736 | - fn resize_mouse(&mut self, window: Window) -> Result<()> { | |
| 745 | + fn resize_mouse(&mut self, window: Window) -> std::result::Result<(), WindowManagerError> { | |
| 737 | 746 | self.floating_windows.insert(window); |
| 738 | 747 | |
| 739 | 748 | let geometry = self.connection.get_geometry(window)?.reply()?; |
| @@ -880,7 +889,7 @@ impl WindowManager { | ||
| 880 | 889 | Ok(None) |
| 881 | 890 | } |
| 882 | 891 | |
| 883 | - fn apply_layout(&self) -> Result<()> { | |
| 892 | + fn apply_layout(&self) -> std::result::Result<(), WindowManagerError> { | |
| 884 | 893 | if self.fullscreen_window.is_some() { |
| 885 | 894 | return Ok(()); |
| 886 | 895 | } |
| @@ -936,7 +945,7 @@ impl WindowManager { | ||
| 936 | 945 | Ok(()) |
| 937 | 946 | } |
| 938 | 947 | |
| 939 | - fn remove_window(&mut self, window: Window) -> Result<()> { | |
| 948 | + fn remove_window(&mut self, window: Window) -> std::result::Result<(), WindowManagerError> { | |
| 940 | 949 | let initial_count = self.windows.len(); |
| 941 | 950 | self.windows.retain(|&w| w != window); |
| 942 | 951 | self.window_tags.remove(&window); |