tony / oxwm

replace `anyhow` results in keyboard::handlers module with concrete types Browse files
- `handle_key_press` cannot fail so return type changed accordingly
- `handle_spawn_action` only fails on IO
emzywastaken committed 2025-10-14 parent 06b24c8 commit 2eaba0967f67d2f06151440a2bfd7b5ab75cc184
Showing 2 changed files with 16 additions and 10 deletions. UnifiedSplit
+9 −7 src/keyboard/handlers.rs
@@ -1,9 +1,11 @@
1 +use std::io;
1 use std::process::Command; 2 use std::process::Command;
2 3
3 -use anyhow::Result;
4 use x11rb::connection::Connection; 4 use x11rb::connection::Connection;
5 use x11rb::protocol::xproto::*; 5 use x11rb::protocol::xproto::*;
6 6
7 +use crate::window_manager::X11Error;
8 +
7 #[derive(Debug, Copy, Clone)] 9 #[derive(Debug, Copy, Clone)]
8 pub enum KeyAction { 10 pub enum KeyAction {
9 Spawn, 11 Spawn,
@@ -67,7 +69,7 @@ pub fn setup_keybinds(
67 connection: &impl Connection, 69 connection: &impl Connection,
68 root: Window, 70 root: Window,
69 keybindings: &[Key], 71 keybindings: &[Key],
70 -) -> Result<()> { 72 +) -> Result<(), X11Error> {
71 for keybinding in keybindings { 73 for keybinding in keybindings {
72 let modifier_mask = modifiers_to_mask(keybinding.modifiers); 74 let modifier_mask = modifiers_to_mask(keybinding.modifiers);
73 75
@@ -83,20 +85,20 @@ pub fn setup_keybinds(
83 Ok(()) 85 Ok(())
84 } 86 }
85 87
86 -pub fn handle_key_press(event: KeyPressEvent, keybindings: &[Key]) -> Result<(KeyAction, Arg)> { 88 +pub fn handle_key_press(event: KeyPressEvent, keybindings: &[Key]) -> (KeyAction, Arg) {
87 for keybinding in keybindings { 89 for keybinding in keybindings {
88 let modifier_mask = modifiers_to_mask(keybinding.modifiers); 90 let modifier_mask = modifiers_to_mask(keybinding.modifiers);
89 91
90 if event.detail == keybinding.key && event.state == modifier_mask.into() { 92 if event.detail == keybinding.key && event.state == modifier_mask.into() {
91 - return Ok((keybinding.func, keybinding.arg.clone())); 93 + return (keybinding.func, keybinding.arg.clone());
92 } 94 }
93 } 95 }
94 96
95 - Ok((KeyAction::None, Arg::None)) 97 + (KeyAction::None, Arg::None)
96 } 98 }
97 99
98 -pub fn handle_spawn_action(action: KeyAction, arg: &Arg) -> Result<()> { 100 +pub fn handle_spawn_action(action: KeyAction, arg: &Arg) -> io::Result<()> {
99 - use std::io::ErrorKind; 101 + use io::ErrorKind;
100 match action { 102 match action {
101 KeyAction::Spawn => match arg { 103 KeyAction::Spawn => match arg {
102 Arg::Str(command) => match Command::new(command).spawn() { 104 Arg::Str(command) => match Command::new(command).spawn() {
+7 −3 src/window_manager.rs
@@ -34,7 +34,6 @@ pub struct WindowManager {
34 bar: Bar, 34 bar: Bar,
35 } 35 }
36 36
37 -// TODO: Eliminate all library level `anyhow::Error`
38 #[derive(Debug)] 37 #[derive(Debug)]
39 pub enum WmError { 38 pub enum WmError {
40 X11(X11Error), 39 X11(X11Error),
@@ -87,6 +86,12 @@ impl<T: Into<X11Error>> From<T> for WmError {
87 } 86 }
88 } 87 }
89 88
89 +impl From<std::io::Error> for WmError {
90 + fn from(value: std::io::Error) -> Self {
91 + Self::Io(value)
92 + }
93 +}
94 +
90 impl From<anyhow::Error> for WmError { 95 impl From<anyhow::Error> for WmError {
91 fn from(value: anyhow::Error) -> Self { 96 fn from(value: anyhow::Error) -> Self {
92 Self::Anyhow(value) 97 Self::Anyhow(value)
@@ -376,7 +381,6 @@ impl WindowManager {
376 pub fn run(&mut self) -> WmResult<bool> { 381 pub fn run(&mut self) -> WmResult<bool> {
377 println!("oxwm started on display {}", self.screen_number); 382 println!("oxwm started on display {}", self.screen_number);
378 383
379 - // TODO: Identify errors
380 keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?; 384 keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?;
381 self.update_bar()?; 385 self.update_bar()?;
382 386
@@ -820,7 +824,7 @@ impl WindowManager {
820 } 824 }
821 } 825 }
822 Event::KeyPress(event) => { 826 Event::KeyPress(event) => {
823 - let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings)?; 827 + let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings);
824 match action { 828 match action {
825 KeyAction::Quit => return Ok(Some(false)), 829 KeyAction::Quit => return Ok(Some(false)),
826 KeyAction::Restart => return Ok(Some(true)), 830 KeyAction::Restart => return Ok(Some(true)),