linput

Listen to input events
git clone git://git.akobets.xyz/linput
Log | Files | Refs | README | LICENSE

commit fc82c318c1b8b302b3fb6248b12389b9caa9391e
parent d0177ca7ad433a0e5c0a12d8a18a3439de88641b
Author: Artem Kobets <artem@akobets.xyz>
Date:   Sat, 18 Apr 2020 19:06:00 +0300

confirm that program doesn't care about left/right modifiers

Diffstat:
Mconfig.def.h | 5+++--
Mlinput.1 | 3+--
Mlinput.c | 18++++++++----------
3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -34,8 +34,9 @@ enum { static const struct HotkeyRule { const char *name; int mod_mask; - /* see <linux/input-event-codes.h> for complete list - * (KEY_* constants) */ + /* see <linux/input-event-codes.h> for complete list (KEY_* constants) + * modifiers (e.g. KEY_RIGHTSHIFT, KEY_LEFTSHIFT) + * are ignored, specify them in mod_mask instead. */ int keys[HOTKEY_MAX_KEYS + 1]; int event_mask; } hotkeys[] = { diff --git a/linput.1 b/linput.1 @@ -21,8 +21,7 @@ are simple rules that listen to a specific event. .B Hotkeys are rules specifically for keyboard events, which match familiar hotkey behavior. You can specify a -modifier mask (Ctrl, Alt, etc.), a list of regular keys -that need to be pressed at once, and an event mask +modifier mask (Ctrl, Alt, etc.), a list of regular keys, and an event mask (trigger on press, release or hold). linput is customized through editing config.h file and recompiling source code. diff --git a/linput.c b/linput.c @@ -154,19 +154,17 @@ int is_hotkey_active(const struct HotkeyRule *hotkey, int last_key) { int k; - int match = 1; - if (!is_mod(last_key)) - if (!has_key(hotkey, last_key)) - match = 0; + if (!has_key(hotkey, last_key) && !is_mod(last_key)) + return 0; if (!is_match_hotkey_mod(hotkey)) - match = 0; + return 0; if (!is_match_hotkey_event(hotkey, last_key)) - match = 0; + return 0; - for (k = 1; match && k < LENGTH(key_state); k++) { + for (k = 1; k < LENGTH(key_state); k++) { if (k == last_key || is_mod(k)) /* skip, handled above */ continue; @@ -174,15 +172,15 @@ is_hotkey_active(const struct HotkeyRule *hotkey, int last_key) if (has_key(hotkey, k)) { /* all other keys in hotkey should be pressed */ if (key_state[k] == 0) - match = 0; + return 0; } else { /* all keys not in hotkey should not be pressed */ if (key_state[k] != 0 && !is_key_ignored(k)) - match = 0; + return 0; } } - return match; + return 1; } void