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 2 use std::process::Command;
2 3
3 -use anyhow::Result;
4 4 use x11rb::connection::Connection;
5 5 use x11rb::protocol::xproto::*;
6 6
7 +use crate::window_manager::X11Error;
8 +
7 9 #[derive(Debug, Copy, Clone)]
8 10 pub enum KeyAction {
9 11 Spawn,
@@ -67,7 +69,7 @@ pub fn setup_keybinds(
67 69 connection: &impl Connection,
68 70 root: Window,
69 71 keybindings: &[Key],
70 -) -> Result<()> {
72 +) -> Result<(), X11Error> {
71 73 for keybinding in keybindings {
72 74 let modifier_mask = modifiers_to_mask(keybinding.modifiers);
73 75
@@ -83,20 +85,20 @@ pub fn setup_keybinds(
83 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 89 for keybinding in keybindings {
88 90 let modifier_mask = modifiers_to_mask(keybinding.modifiers);
89 91
90 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<()> {
99 - use std::io::ErrorKind;
100 +pub fn handle_spawn_action(action: KeyAction, arg: &Arg) -> io::Result<()> {
101 + use io::ErrorKind;
100 102 match action {
101 103 KeyAction::Spawn => match arg {
102 104 Arg::Str(command) => match Command::new(command).spawn() {
+7 −3 src/window_manager.rs
@@ -34,7 +34,6 @@ pub struct WindowManager {
34 34 bar: Bar,
35 35 }
36 36
37 -// TODO: Eliminate all library level `anyhow::Error`
38 37 #[derive(Debug)]
39 38 pub enum WmError {
40 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 95 impl From<anyhow::Error> for WmError {
91 96 fn from(value: anyhow::Error) -> Self {
92 97 Self::Anyhow(value)
@@ -376,7 +381,6 @@ impl WindowManager {
376 381 pub fn run(&mut self) -> WmResult<bool> {
377 382 println!("oxwm started on display {}", self.screen_number);
378 383
379 - // TODO: Identify errors
380 384 keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?;
381 385 self.update_bar()?;
382 386
@@ -820,7 +824,7 @@ impl WindowManager {
820 824 }
821 825 }
822 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 828 match action {
825 829 KeyAction::Quit => return Ok(Some(false)),
826 830 KeyAction::Restart => return Ok(Some(true)),