This commit is contained in:
Schrottkatze 2022-10-11 03:07:22 +02:00
parent 1b688c7883
commit 52a61e070d
3 changed files with 42 additions and 15 deletions

View file

@ -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)

View file

@ -9,17 +9,32 @@ use super::{error, screen, window};
pub struct Display {
pub(super) ptr: *mut xlib::Display,
name: String,
keyboard_grab: Option<Grabbables>,
pointer_grab: Option<Grabbables>,
keyboard_grab: Option<GrabbablesModes>,
pointer_grab: Option<GrabbablesModes>,
}
// 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
});

View file

@ -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<i32>),
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"),
}
)
}