From cfadebc733032a45468db8952bd784254a513df3 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Mon, 15 Feb 2021 15:34:24 +0100 Subject: [PATCH] Improve wayland settings --- espanso-detect/src/evdev/device.rs | 4 ++-- espanso-detect/src/evdev/ffi.rs | 2 +- espanso-detect/src/evdev/native.cpp | 8 +++++++- espanso-detect/src/evdev/native.h | 2 +- espanso-inject/src/lib.rs | 6 +++++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/espanso-detect/src/evdev/device.rs b/espanso-detect/src/evdev/device.rs index ec87dfa..e07e730 100644 --- a/espanso-detect/src/evdev/device.rs +++ b/espanso-detect/src/evdev/device.rs @@ -15,7 +15,7 @@ use thiserror::Error; use super::{ ffi::{ - is_keyboard, xkb_key_direction, xkb_keycode_t, xkb_keymap_key_repeats, xkb_state, + is_keyboard_or_mouse, xkb_key_direction, xkb_keycode_t, xkb_keymap_key_repeats, xkb_state, xkb_state_get_keymap, xkb_state_key_get_one_sym, xkb_state_key_get_utf8, xkb_state_new, xkb_state_unref, xkb_state_update_key, EV_KEY, }, @@ -59,7 +59,7 @@ impl Device { .custom_flags(O_NONBLOCK | O_CLOEXEC | O_RDONLY) .open(&path)?; - if unsafe { is_keyboard(file.as_raw_fd()) == 0 } { + if unsafe { is_keyboard_or_mouse(file.as_raw_fd()) == 0 } { return Err(DeviceError::InvalidDevice(path.to_string()).into()); } diff --git a/espanso-detect/src/evdev/ffi.rs b/espanso-detect/src/evdev/ffi.rs index 837b8af..e242ca5 100644 --- a/espanso-detect/src/evdev/ffi.rs +++ b/espanso-detect/src/evdev/ffi.rs @@ -73,5 +73,5 @@ extern "C" { #[link(name = "espansodetectevdev", kind = "static")] extern "C" { - pub fn is_keyboard(fd: i32) -> i32; + pub fn is_keyboard_or_mouse(fd: i32) -> i32; } diff --git a/espanso-detect/src/evdev/native.cpp b/espanso-detect/src/evdev/native.cpp index dc34fa0..31e4629 100644 --- a/espanso-detect/src/evdev/native.cpp +++ b/espanso-detect/src/evdev/native.cpp @@ -57,7 +57,7 @@ evdev_bit_is_set(const unsigned long *array, int bit) } /* Some heuristics to see if the device is a keyboard. */ -int32_t is_keyboard(int fd) +int32_t is_keyboard_or_mouse(int fd) { int i; unsigned long evbits[NLONGS(EV_CNT)] = {0}; @@ -76,9 +76,15 @@ int32_t is_keyboard(int fd) if (errno) return false; + // Test for keyboard keys for (i = KEY_RESERVED; i <= KEY_MIN_INTERESTING; i++) if (evdev_bit_is_set(keybits, i)) return true; + // Test for mouse keys + for (i = BTN_MOUSE; i <= BTN_TASK; i++) + if (evdev_bit_is_set(keybits, i)) + return true; + return false; } \ No newline at end of file diff --git a/espanso-detect/src/evdev/native.h b/espanso-detect/src/evdev/native.h index 3a0d8bc..1949e20 100644 --- a/espanso-detect/src/evdev/native.h +++ b/espanso-detect/src/evdev/native.h @@ -22,6 +22,6 @@ #include -extern "C" int32_t is_keyboard(int fd); +extern "C" int32_t is_keyboard_or_mouse(int fd); #endif //ESPANSO_DETECT_EVDEV_H \ No newline at end of file diff --git a/espanso-inject/src/lib.rs b/espanso-inject/src/lib.rs index 3fb4866..a11b22e 100644 --- a/espanso-inject/src/lib.rs +++ b/espanso-inject/src/lib.rs @@ -65,7 +65,11 @@ impl Default for InjectionOptions { } else if cfg!(target_os = "macos") { 2 } else if cfg!(target_os = "linux") { - 0 + if cfg!(feature = "wayland") { + 1 + } else { + 0 + } } else { panic!("unsupported OS"); };