diff --git a/swhkd/src/daemon.rs b/swhkd/src/daemon.rs index 108f175..af75dd4 100644 --- a/swhkd/src/daemon.rs +++ b/swhkd/src/daemon.rs @@ -441,7 +441,7 @@ fn socket_write(command: &str, socket_path: PathBuf) -> Result<(), Box Result<(), Box> { if !Uid::current().is_root() { let groups = nix::unistd::getgroups(); - for (_, groups) in groups.iter().enumerate() { + for groups in groups.iter() { for group in groups { let group = Group::from_gid(*group); if group.unwrap().unwrap().name == "input" { diff --git a/swhkd/src/uinput.rs b/swhkd/src/uinput.rs index c20fa52..f0684ae 100644 --- a/swhkd/src/uinput.rs +++ b/swhkd/src/uinput.rs @@ -10,30 +10,21 @@ use std::os::unix::io::AsRawFd; ioctl_none!(rfkill_noinput, b'R', 1); pub fn create_uinput_device() -> Result> { - let mut keys = AttributeSet::::new(); - for key in get_all_keys() { - keys.insert(key); - } + let keys: AttributeSet = get_all_keys().iter().copied().collect(); - let mut relative_axes = AttributeSet::::new(); - for axis in get_all_relative_axes() { - relative_axes.insert(axis); - } + let relative_axes: AttributeSet = + get_all_relative_axes().iter().copied().collect(); let device = VirtualDeviceBuilder::new()? .name("swhkd virtual output") .with_keys(&keys)? .with_relative_axes(&relative_axes)? - .build() - .unwrap(); + .build()?; Ok(device) } pub fn create_uinput_switches_device() -> Result> { - let mut switches = AttributeSet::::new(); - for switch in get_all_switches() { - switches.insert(switch); - } + let switches: AttributeSet = get_all_switches().iter().copied().collect(); // We have to disable rfkill-input to avoid blocking all radio devices. When // a new device (virtual or physical) with the SW_RFKILL_ALL capability bit @@ -52,12 +43,11 @@ pub fn create_uinput_switches_device() -> Result Vec { - vec![ +pub fn get_all_keys() -> &'static [Key] { + &[ evdev::Key::KEY_RESERVED, evdev::Key::KEY_ESC, evdev::Key::KEY_1, @@ -609,8 +599,8 @@ pub fn get_all_keys() -> Vec { ] } -pub fn get_all_relative_axes() -> Vec { - vec![ +pub fn get_all_relative_axes() -> &'static [RelativeAxisType] { + &[ RelativeAxisType::REL_X, RelativeAxisType::REL_Y, RelativeAxisType::REL_Z, @@ -627,8 +617,8 @@ pub fn get_all_relative_axes() -> Vec { ] } -pub fn get_all_switches() -> Vec { - vec![ +pub fn get_all_switches() -> &'static [SwitchType] { + &[ SwitchType::SW_LID, SwitchType::SW_TABLET_MODE, SwitchType::SW_HEADPHONE_INSERT,