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 | bar, | 210 | bar, |
| 211 | }; | 211 | }; |
| 212 | 212 | ||
| 213 | - // TODO: identify error types | ||
| 214 | window_manager.scan_existing_windows()?; | 213 | window_manager.scan_existing_windows()?; |
| 214 | + // TODO: identify error types | ||
| 215 | window_manager.update_bar()?; | 215 | window_manager.update_bar()?; |
| 216 | 216 | ||
| 217 | Ok(window_manager) | 217 | Ok(window_manager) |
| @@ -251,7 +251,7 @@ impl WindowManager { | |||
| 251 | Ok(tag_mask(0)) | 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 | let tree = self.connection.query_tree(self.root)?.reply()?; | 255 | let tree = self.connection.query_tree(self.root)?.reply()?; |
| 256 | let net_client_info = self | 256 | let net_client_info = self |
| 257 | .connection | 257 | .connection |
| @@ -279,7 +279,6 @@ impl WindowManager { | |||
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | if attrs.map_state == MapState::VIEWABLE { | 281 | if attrs.map_state == MapState::VIEWABLE { |
| 282 | - // TODO: Identify errors | ||
| 283 | let tag = self.get_saved_tag(window, net_client_info)?; | 282 | let tag = self.get_saved_tag(window, net_client_info)?; |
| 284 | self.windows.push(window); | 283 | self.windows.push(window); |
| 285 | self.window_tags.insert(window, tag); | 284 | self.window_tags.insert(window, tag); |
| @@ -304,7 +303,6 @@ impl WindowManager { | |||
| 304 | .is_ok_and(|prop| !prop.value.is_empty()); | 303 | .is_ok_and(|prop| !prop.value.is_empty()); |
| 305 | 304 | ||
| 306 | if has_wm_class { | 305 | if has_wm_class { |
| 307 | - // TODO: Identify errors | ||
| 308 | let tag = self.get_saved_tag(window, net_client_info)?; | 306 | let tag = self.get_saved_tag(window, net_client_info)?; |
| 309 | self.windows.push(window); | 307 | self.windows.push(window); |
| 310 | self.window_tags.insert(window, tag); | 308 | self.window_tags.insert(window, tag); |
| @@ -313,16 +311,18 @@ impl WindowManager { | |||
| 313 | } | 311 | } |
| 314 | 312 | ||
| 315 | if let Some(&first) = self.windows.first() { | 313 | if let Some(&first) = self.windows.first() { |
| 316 | - // TODO: Identify errors | ||
| 317 | self.set_focus(Some(first))?; | 314 | self.set_focus(Some(first))?; |
| 318 | } | 315 | } |
| 319 | 316 | ||
| 320 | - // TODO: Identify errors | ||
| 321 | self.apply_layout()?; | 317 | self.apply_layout()?; |
| 322 | Ok(()) | 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 | match self | 326 | match self |
| 327 | .connection | 327 | .connection |
| 328 | .get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)? | 328 | .get_property(false, window, net_client_info, AtomEnum::CARDINAL, 0, 2)? |
| @@ -349,7 +349,11 @@ impl WindowManager { | |||
| 349 | Ok(self.selected_tags) | 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 | let net_client_info = self | 357 | let net_client_info = self |
| 354 | .connection | 358 | .connection |
| 355 | .intern_atom(false, b"_NET_CLIENT_INFO")? | 359 | .intern_atom(false, b"_NET_CLIENT_INFO")? |
| @@ -372,7 +376,11 @@ impl WindowManager { | |||
| 372 | Ok(()) | 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 | let wm_state_atom = self | 384 | let wm_state_atom = self |
| 377 | .connection | 385 | .connection |
| 378 | .intern_atom(false, b"WM_STATE")? | 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 | if let Some(focused) = self.focused_window { | 433 | if let Some(focused) = self.focused_window { |
| 426 | if self.fullscreen_window == Some(focused) { | 434 | if self.fullscreen_window == Some(focused) { |
| 427 | self.fullscreen_window = None; | 435 | self.fullscreen_window = None; |
| 428 | 436 | ||
| 429 | self.connection.map_window(self.bar.window())?; | 437 | self.connection.map_window(self.bar.window())?; |
| 430 | 438 | ||
| 431 | - // TODO: Identify errors | ||
| 432 | self.apply_layout()?; | 439 | self.apply_layout()?; |
| 433 | self.update_focus_visuals()?; | 440 | self.update_focus_visuals()?; |
| 434 | } else { | 441 | } else { |
| @@ -539,7 +546,7 @@ impl WindowManager { | |||
| 539 | .collect() | 546 | .collect() |
| 540 | } | 547 | } |
| 541 | 548 | ||
| 542 | - fn update_window_visibility(&self) -> Result<()> { | 549 | + fn update_window_visibility(&self) -> std::result::Result<(), WindowManagerError> { |
| 543 | for &window in &self.windows { | 550 | for &window in &self.windows { |
| 544 | if self.is_window_visible(window) { | 551 | if self.is_window_visible(window) { |
| 545 | self.connection.map_window(window)?; | 552 | self.connection.map_window(window)?; |
| @@ -575,7 +582,7 @@ impl WindowManager { | |||
| 575 | Ok(()) | 582 | Ok(()) |
| 576 | } | 583 | } |
| 577 | 584 | ||
| 578 | - fn save_selected_tags(&self) -> Result<()> { | 585 | + fn save_selected_tags(&self) -> std::result::Result<(), WindowManagerError> { |
| 579 | let net_current_desktop = self | 586 | let net_current_desktop = self |
| 580 | .connection | 587 | .connection |
| 581 | .intern_atom(false, b"_NET_CURRENT_DESKTOP")? | 588 | .intern_atom(false, b"_NET_CURRENT_DESKTOP")? |
| @@ -644,7 +651,10 @@ impl WindowManager { | |||
| 644 | Ok(()) | 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 | self.focused_window = window; | 658 | self.focused_window = window; |
| 649 | 659 | ||
| 650 | if let Some(win) = window { | 660 | if let Some(win) = window { |
| @@ -653,12 +663,11 @@ impl WindowManager { | |||
| 653 | self.connection.flush()?; | 663 | self.connection.flush()?; |
| 654 | } | 664 | } |
| 655 | 665 | ||
| 656 | - // TODO: Indentify errors | ||
| 657 | self.update_focus_visuals()?; | 666 | self.update_focus_visuals()?; |
| 658 | Ok(()) | 667 | Ok(()) |
| 659 | } | 668 | } |
| 660 | 669 | ||
| 661 | - fn update_focus_visuals(&self) -> Result<()> { | 670 | + fn update_focus_visuals(&self) -> std::result::Result<(), WindowManagerError> { |
| 662 | for &window in &self.windows { | 671 | for &window in &self.windows { |
| 663 | let (border_color, border_width) = if self.focused_window == Some(window) { | 672 | let (border_color, border_width) = if self.focused_window == Some(window) { |
| 664 | (self.config.border_focused, self.config.border_width) | 673 | (self.config.border_focused, self.config.border_width) |
| @@ -680,7 +689,7 @@ impl WindowManager { | |||
| 680 | Ok(()) | 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 | self.floating_windows.insert(window); | 693 | self.floating_windows.insert(window); |
| 685 | 694 | ||
| 686 | let geometry = self.connection.get_geometry(window)?.reply()?; | 695 | let geometry = self.connection.get_geometry(window)?.reply()?; |
| @@ -733,7 +742,7 @@ impl WindowManager { | |||
| 733 | Ok(()) | 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 | self.floating_windows.insert(window); | 746 | self.floating_windows.insert(window); |
| 738 | 747 | ||
| 739 | let geometry = self.connection.get_geometry(window)?.reply()?; | 748 | let geometry = self.connection.get_geometry(window)?.reply()?; |
| @@ -880,7 +889,7 @@ impl WindowManager { | |||
| 880 | Ok(None) | 889 | Ok(None) |
| 881 | } | 890 | } |
| 882 | 891 | ||
| 883 | - fn apply_layout(&self) -> Result<()> { | 892 | + fn apply_layout(&self) -> std::result::Result<(), WindowManagerError> { |
| 884 | if self.fullscreen_window.is_some() { | 893 | if self.fullscreen_window.is_some() { |
| 885 | return Ok(()); | 894 | return Ok(()); |
| 886 | } | 895 | } |
| @@ -936,7 +945,7 @@ impl WindowManager { | |||
| 936 | Ok(()) | 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 | let initial_count = self.windows.len(); | 949 | let initial_count = self.windows.len(); |
| 941 | self.windows.retain(|&w| w != window); | 950 | self.windows.retain(|&w| w != window); |
| 942 | self.window_tags.remove(&window); | 951 | self.window_tags.remove(&window); |