From c7047275b0b98b480ee6dccd6d9ab12b614e80fd Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Wed, 6 Oct 2021 19:17:32 +0200 Subject: [PATCH] fix(inject): fix warnings --- espanso-inject/src/evdev/ffi.rs | 1 + espanso-inject/src/evdev/uinput.rs | 20 ++++++++++---------- espanso-inject/src/x11/mod.rs | 22 +++++++++++----------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/espanso-inject/src/evdev/ffi.rs b/espanso-inject/src/evdev/ffi.rs index 2fbdbfc..18c96ee 100644 --- a/espanso-inject/src/evdev/ffi.rs +++ b/espanso-inject/src/evdev/ffi.rs @@ -25,6 +25,7 @@ pub struct xkb_rule_names { } #[repr(C)] +#[allow(clippy::upper_case_acronyms)] pub enum xkb_key_direction { UP, DOWN, diff --git a/espanso-inject/src/evdev/uinput.rs b/espanso-inject/src/evdev/uinput.rs index 331b2a9..ebacf48 100644 --- a/espanso-inject/src/evdev/uinput.rs +++ b/espanso-inject/src/evdev/uinput.rs @@ -39,7 +39,7 @@ impl UInputDevice { let uinput_path = CString::new("/dev/uinput").expect("unable to generate /dev/uinput path"); let raw_fd = unsafe { open(uinput_path.as_ptr(), O_WRONLY | O_NONBLOCK) }; if raw_fd < 0 { - return Err(UInputDeviceError::OpenFailed().into()); + return Err(UInputDeviceError::Open().into()); } let fd = scopeguard::guard(raw_fd, |raw_fd| unsafe { close(raw_fd); @@ -47,24 +47,24 @@ impl UInputDevice { // Enable keyboard events if unsafe { ioctl(*fd, ui_set_evbit(), EV_KEY as c_uint) } != 0 { - return Err(UInputDeviceError::KeyEVBitFailed().into()); + return Err(UInputDeviceError::KeyEVBit().into()); } // Register all keycodes for key_code in 0..256 { if unsafe { ioctl(*fd, ui_set_keybit(), key_code) } != 0 { - return Err(UInputDeviceError::KeyBitFailed().into()); + return Err(UInputDeviceError::KeyBit().into()); } } // Register the virtual device if unsafe { setup_uinput_device(*fd) } != 0 { - return Err(UInputDeviceError::DeviceSetupFailed().into()); + return Err(UInputDeviceError::DeviceSetup().into()); } // Create the device if unsafe { ioctl(*fd, ui_dev_create()) } != 0 { - return Err(UInputDeviceError::DeviceCreateFailed().into()); + return Err(UInputDeviceError::DeviceCreate().into()); } Ok(Self { @@ -92,17 +92,17 @@ impl Drop for UInputDevice { #[derive(Error, Debug)] pub enum UInputDeviceError { #[error("could not open uinput device")] - OpenFailed(), + Open(), #[error("could not set keyboard evbit")] - KeyEVBitFailed(), + KeyEVBit(), #[error("could not set keyboard keybit")] - KeyBitFailed(), + KeyBit(), #[error("could not register virtual device")] - DeviceSetupFailed(), + DeviceSetup(), #[error("could not create uinput device")] - DeviceCreateFailed(), + DeviceCreate(), } diff --git a/espanso-inject/src/x11/mod.rs b/espanso-inject/src/x11/mod.rs index 0d8ba82..7878fe5 100644 --- a/espanso-inject/src/x11/mod.rs +++ b/espanso-inject/src/x11/mod.rs @@ -73,7 +73,7 @@ impl X11Injector { let display = unsafe { ffi::XOpenDisplay(std::ptr::null()) }; if display.is_null() { - return Err(X11InjectorError::InitFailure().into()); + return Err(X11InjectorError::Init().into()); } let (char_map, sym_map) = Self::generate_maps(display); @@ -155,9 +155,9 @@ impl X11Injector { .map(|sym| { self .sym_map - .get(&sym) + .get(sym) .cloned() - .ok_or_else(|| X11InjectorError::SymMappingFailure(*sym).into()) + .ok_or_else(|| X11InjectorError::SymMapping(*sym).into()) }) .collect() } @@ -337,7 +337,7 @@ impl Injector for X11Injector { .char_map .get(&char) .cloned() - .ok_or_else(|| X11InjectorError::CharMappingFailure(char).into()) + .ok_or_else(|| X11InjectorError::CharMapping(char).into()) }) .collect(); @@ -401,18 +401,18 @@ impl Injector for X11Injector { // First press the keys for record in records.iter() { if options.disable_fast_inject { - self.xtest_send_key(&record, true, delay_us); + self.xtest_send_key(record, true, delay_us); } else { - self.send_key(focused_window, &record, true, delay_us); + self.send_key(focused_window, record, true, delay_us); } } // Then release them for record in records.iter().rev() { if options.disable_fast_inject { - self.xtest_send_key(&record, false, delay_us); + self.xtest_send_key(record, false, delay_us); } else { - self.send_key(focused_window, &record, false, delay_us); + self.send_key(focused_window, record, false, delay_us); } } @@ -423,11 +423,11 @@ impl Injector for X11Injector { #[derive(Error, Debug)] pub enum X11InjectorError { #[error("failed to initialize x11 display")] - InitFailure(), + Init(), #[error("missing vkey mapping for char `{0}`")] - CharMappingFailure(String), + CharMapping(String), #[error("missing record mapping for sym `{0}`")] - SymMappingFailure(u64), + SymMapping(u64), }