diff --git a/src/config/action.rs b/src/config/action.rs index 9096be9..9392a5a 100644 --- a/src/config/action.rs +++ b/src/config/action.rs @@ -31,10 +31,10 @@ where D: Deserializer<'de>, { let action = RemapActions::deserialize(deserializer)?; - return Ok(Remap { + Ok(Remap { remap: action.remap.into_iter().map(|(k, v)| (k, v.into_vec())).collect(), - timeout: action.timeout_millis.map(|ms| Duration::from_millis(ms)), - }); + timeout: action.timeout_millis.map(Duration::from_millis), + }) } fn deserialize_launch<'de, D>(deserializer: D) -> Result, D::Error> diff --git a/src/config/tests.rs b/src/config/tests.rs index 1952a59..8dedce4 100644 --- a/src/config/tests.rs +++ b/src/config/tests.rs @@ -178,6 +178,6 @@ fn test_keymap_mark() { fn assert_parse(yaml: &str) { let result: Result = serde_yaml::from_str(yaml); if let Err(e) = result { - assert!(false, "{}", e) + panic!("{}", e) } } diff --git a/src/event_handler.rs b/src/event_handler.rs index a3a7a99..11d64f7 100644 --- a/src/event_handler.rs +++ b/src/event_handler.rs @@ -145,7 +145,7 @@ impl EventHandler { self.pressed_keys.insert(key, event.0); } else { if let Some(original_key) = self.pressed_keys.get(&key) { - events[0].0 = original_key.clone(); + events[0].0 = *original_key; } if value == RELEASE { self.pressed_keys.remove(&key); @@ -268,7 +268,7 @@ impl EventHandler { let expiration = Expiration::OneShot(TimeSpec::from_duration(timeout)); self.override_timer.unset()?; self.override_timer.set(expiration, TimerSetTimeFlags::empty())?; - self.override_timeout_key = Some(key.clone()); + self.override_timeout_key = Some(*key); } } Action::Launch(command) => self.run_command(command.clone()), diff --git a/src/main.rs b/src/main.rs index 344bb5e..cf9d457 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use nix::sys::timerfd::{ClockId, TimerFd, TimerFlags}; use std::collections::HashMap; use std::io::stdout; use std::os::unix::io::{AsRawFd, RawFd}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; mod client; mod config; @@ -130,11 +130,11 @@ fn main() -> anyhow::Result<()> { } for input_device in input_devices.values_mut() { - if readable_fds.contains(input_device.as_raw_fd()) { - if !handle_input_events(input_device, &mut handler, &mut config)? { - println!("Found a removed device. Reselecting devices."); - break 'event_loop Event::ReloadDevices; - } + if readable_fds.contains(input_device.as_raw_fd()) + && !handle_input_events(input_device, &mut handler, &mut config)? + { + println!("Found a removed device. Reselecting devices."); + break 'event_loop Event::ReloadDevices; } } @@ -203,21 +203,19 @@ fn handle_input_events( config: &mut Config, ) -> anyhow::Result { match input_device.fetch_events().map_err(|e| (e.raw_os_error(), e)) { - Err((Some(ENODEV), _)) => { - return Ok(false); - } - Err((_, error)) => return Err(error).context("Error fetching input events"), + Err((Some(ENODEV), _)) => Ok(false), + Err((_, error)) => Err(error).context("Error fetching input events"), Ok(events) => { for event in events { if event.event_type() == EventType::KEY { handler - .on_event(event, &config) + .on_event(event, config) .map_err(|e| anyhow!("Failed handling {event:?}:\n {e:?}"))?; } else { handler.send_event(event)?; } } - return Ok(true); + Ok(true) } } } @@ -233,7 +231,7 @@ fn handle_device_changes( event.name.and_then(|name| { let path = PathBuf::from("/dev/input/").join(name); let mut device = InputDevice::try_from(path).ok()?; - if device.is_input_device(device_filter, &ignore_filter, mouse) && device.grab() { + if device.is_input_device(device_filter, ignore_filter, mouse) && device.grab() { device.print(); Some(device.into()) } else { @@ -250,7 +248,7 @@ fn handle_config_changes( device_filter: &[String], ignore_filter: &[String], mouse: bool, - config_path: &PathBuf, + config_path: &Path, ) -> anyhow::Result { for event in &events { match (event.mask, &event.name) { @@ -268,7 +266,7 @@ fn handle_config_changes( event.name.and_then(|name| { let path = PathBuf::from("/dev/input/").join(name); let mut device = InputDevice::try_from(path).ok()?; - if device.is_input_device(&device_filter, &ignore_filter, mouse) && device.grab() { + if device.is_input_device(device_filter, ignore_filter, mouse) && device.grab() { device.print(); Some(device.into()) } else {