fix(inject): fix warnings

This commit is contained in:
Federico Terzi 2021-10-06 19:17:32 +02:00
parent 55930364f8
commit c7047275b0
3 changed files with 22 additions and 21 deletions

View File

@ -25,6 +25,7 @@ pub struct xkb_rule_names {
}
#[repr(C)]
#[allow(clippy::upper_case_acronyms)]
pub enum xkb_key_direction {
UP,
DOWN,

View File

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

View File

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