Skip to content

Commit

Permalink
Fix #63
Browse files Browse the repository at this point in the history
  • Loading branch information
TTWNO committed Nov 28, 2022
1 parent bf094b4 commit 4ae9d31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sohkd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ authors = [
[dependencies]
clap.workspace = true
env_logger = "0.10.0"
evdev = { version = "0.12.0", features = ["tokio"] }
evdev = { version = "0.11.6", features = ["tokio"] }
itertools = "0.10.5"
log = "0.4.17"
nix.workspace = true
Expand Down
16 changes: 7 additions & 9 deletions sohkd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
// }
let arg_devices = arg_devices.collect::<Vec<&str>>();
evdev::enumerate()
.filter(|(_, device)| arg_devices.contains(&device.name().unwrap_or("")))
.map(|(_, device)| device)
.filter(|device| arg_devices.contains(&device.name().unwrap_or("")))
.collect()
} else {
log::trace!("Attempting to find all keyboard file descriptors.");
evdev::enumerate().filter(check_device_is_keyboard).map(|(_, device)| device).collect()
evdev::enumerate().filter(check_device_is_keyboard).collect()
}
};

Expand Down Expand Up @@ -253,14 +252,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
match signal {
SIGUSR1 => {
execution_is_paused = true;
for (_, mut device) in evdev::enumerate().filter(check_device_is_keyboard) {
for mut device in evdev::enumerate().filter(check_device_is_keyboard) {
let _ = device.ungrab();
}
}

SIGUSR2 => {
execution_is_paused = false;
for (_, mut device) in evdev::enumerate().filter(check_device_is_keyboard) {
for mut device in evdev::enumerate().filter(check_device_is_keyboard) {
let _ = device.grab();
}
}
Expand All @@ -271,15 +270,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
}

SIGINT => {
for (_, mut device) in evdev::enumerate().filter(check_device_is_keyboard) {
for mut device in evdev::enumerate().filter(check_device_is_keyboard) {
let _ = device.ungrab();
}
log::warn!("Received SIGINT signal, exiting...");
exit(1);
}

_ => {
for (_, mut device) in evdev::enumerate().filter(check_device_is_keyboard) {
for mut device in evdev::enumerate().filter(check_device_is_keyboard) {
let _ = device.ungrab();
}

Expand Down Expand Up @@ -422,8 +421,7 @@ pub fn check_input_group() -> Result<(), Box<dyn Error>> {
}
}

pub fn check_device_is_keyboard(tup: &(PathBuf, Device)) -> bool {
let device = &tup.1;
pub fn check_device_is_keyboard(device: &Device) -> bool {
if device.supported_keys().map_or(false, |keys| keys.contains(Key::KEY_ENTER)) {
if device.name() == Some("sohkd virtual output") {
return false;
Expand Down

0 comments on commit 4ae9d31

Please sign in to comment.