Diff
diff --git a/src/keyboard/handlers.rs b/src/keyboard/handlers.rs
index 77d45db..6f615d4 100644
--- a/src/keyboard/handlers.rs
+++ b/src/keyboard/handlers.rs
@@ -1,9 +1,11 @@
+use std::io;
use std::process::Command;
-use anyhow::Result;
use x11rb::connection::Connection;
use x11rb::protocol::xproto::*;
+use crate::window_manager::X11Error;
+
#[derive(Debug, Copy, Clone)]
pub enum KeyAction {
Spawn,
@@ -67,7 +69,7 @@ pub fn setup_keybinds(
connection: &impl Connection,
root: Window,
keybindings: &[Key],
-) -> Result<()> {
+) -> Result<(), X11Error> {
for keybinding in keybindings {
let modifier_mask = modifiers_to_mask(keybinding.modifiers);
@@ -83,20 +85,20 @@ pub fn setup_keybinds(
Ok(())
}
-pub fn handle_key_press(event: KeyPressEvent, keybindings: &[Key]) -> Result<(KeyAction, Arg)> {
+pub fn handle_key_press(event: KeyPressEvent, keybindings: &[Key]) -> (KeyAction, Arg) {
for keybinding in keybindings {
let modifier_mask = modifiers_to_mask(keybinding.modifiers);
if event.detail == keybinding.key && event.state == modifier_mask.into() {
- return Ok((keybinding.func, keybinding.arg.clone()));
+ return (keybinding.func, keybinding.arg.clone());
}
}
- Ok((KeyAction::None, Arg::None))
+ (KeyAction::None, Arg::None)
}
-pub fn handle_spawn_action(action: KeyAction, arg: &Arg) -> Result<()> {
- use std::io::ErrorKind;
+pub fn handle_spawn_action(action: KeyAction, arg: &Arg) -> io::Result<()> {
+ use io::ErrorKind;
match action {
KeyAction::Spawn => match arg {
Arg::Str(command) => match Command::new(command).spawn() {
diff --git a/src/window_manager.rs b/src/window_manager.rs
index e52e521..b5f3e96 100644
--- a/src/window_manager.rs
+++ b/src/window_manager.rs
@@ -34,7 +34,6 @@ pub struct WindowManager {
bar: Bar,
}
-// TODO: Eliminate all library level `anyhow::Error`
#[derive(Debug)]
pub enum WmError {
X11(X11Error),
@@ -87,6 +86,12 @@ impl<T: Into<X11Error>> From<T> for WmError {
}
}
+impl From<std::io::Error> for WmError {
+ fn from(value: std::io::Error) -> Self {
+ Self::Io(value)
+ }
+}
+
impl From<anyhow::Error> for WmError {
fn from(value: anyhow::Error) -> Self {
Self::Anyhow(value)
@@ -376,7 +381,6 @@ impl WindowManager {
pub fn run(&mut self) -> WmResult<bool> {
println!("oxwm started on display {}", self.screen_number);
- // TODO: Identify errors
keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?;
self.update_bar()?;
@@ -820,7 +824,7 @@ impl WindowManager {
}
}
Event::KeyPress(event) => {
- let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings)?;
+ let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings);
match action {
KeyAction::Quit => return Ok(Some(false)),
KeyAction::Restart => return Ok(Some(true)),