diff --git a/src/macro_writer.rs b/src/macro_writer.rs index d4ffc65..c569697 100644 --- a/src/macro_writer.rs +++ b/src/macro_writer.rs @@ -21,7 +21,7 @@ impl MacroWriter { pub fn write(&mut self, instruction: Instructions) { if self.ignore_delay_capturing { - if let Instructions::Delay(_) = instruction { () } + if let Instructions::Delay(_) = instruction { } } writeln!(&mut self.outfile, "{}", instruction) diff --git a/src/xwrap/display.rs b/src/xwrap/display.rs index 819e204..2b4580b 100644 --- a/src/xwrap/display.rs +++ b/src/xwrap/display.rs @@ -9,17 +9,32 @@ use super::{error, screen, window}; pub struct Display { pub(super) ptr: *mut xlib::Display, name: String, - keyboard_grab: Option, - pointer_grab: Option, + keyboard_grab: Option, + pointer_grab: Option, } // for keyboard/pointer grabs so Display is less messy #[derive(Debug)] -struct Grabbables { +struct GrabbablesModes { keyboard_mode: GrabMode, pointer_mode: GrabMode, } +#[derive(Debug)] +pub enum Grabbables { + Keyboard, + Pointer, +} + +impl std::fmt::Display for Grabbables{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Grabbables::Keyboard => write!(f, "keyboard"), + Grabbables::Pointer => write!(f, "pointer"), + } + } +} + #[derive(Clone, Copy, Debug)] pub enum GrabMode { Sync, @@ -118,14 +133,7 @@ impl Display { } } - pub fn grab_keyboard( - &mut self, - grab_window: window::Window, - owner_events: bool, - pointer_mode: GrabMode, - keyboard_mode: GrabMode, - time:xlib::Time, - ) -> Result<()> { + pub fn grab_keyboard( &mut self, grab_window: window::Window, owner_events: bool, pointer_mode: GrabMode, keyboard_mode: GrabMode, time:xlib::Time) -> Result<()> { match unsafe { xlib::XGrabKeyboard( self.ptr, @@ -137,7 +145,7 @@ impl Display { ) } { xlib::GrabSuccess => { - self.keyboard_grab = Some(Grabbables { + self.keyboard_grab = Some(GrabbablesModes { keyboard_mode, pointer_mode }); diff --git a/src/xwrap/error.rs b/src/xwrap/error.rs index 615b15a..f16f459 100644 --- a/src/xwrap/error.rs +++ b/src/xwrap/error.rs @@ -2,12 +2,19 @@ use std::{fmt, ops}; use x11::xlib; +use super::display; + /// Various errors to be used in this wrapper #[derive(Debug)] pub enum XError { OpenDisplayError(String), DisplayKeycodesError, InvalidKeycodeError(xlib::KeyCode, ops::Range), + AlreadyGrabbed(display::Grabbables), + XAlreadyGrabbed(display::Grabbables), + XGrabFrozen(display::Grabbables), + XGrabInvalidTime, + XGrabNotViewable, } impl std::fmt::Display for XError { @@ -18,8 +25,20 @@ impl std::fmt::Display for XError { match self { XError::OpenDisplayError(display_name) => format!("error when opening display '{}'", display_name), - XError::DisplayKeycodesError => String::from("error when running XDisplayKeycodes"), - XError::InvalidKeycodeError(code, range) => format!("keycode {} outside of range {:?}", code, range), + XError::DisplayKeycodesError => + String::from("error when running XDisplayKeycodes"), + XError::InvalidKeycodeError(code, range) => + format!("keycode {} outside of range {:?}", code, range), + XError::AlreadyGrabbed(thing_attempted_to_grab) => + format!("this display already grabbed the {}", thing_attempted_to_grab), + XError::XAlreadyGrabbed(thing_attempted_to_grab) => + format!("{} is already actively grabbed by another client", thing_attempted_to_grab), + XError::XGrabFrozen(thing_attempted_to_grab) => + format!("{} is frozen by an active grab of another client", thing_attempted_to_grab), + XError::XGrabInvalidTime => + String::from("invalid grab time"), + XError::XGrabNotViewable => + String::from("grab_window is not viewable"), } ) }