linput

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

commit 4fb6ab843e55e49e2ff7e6802d6b447307ec477c
parent e9cedc6f5a63b1a9f0024e77382ad3029a62bb12
Author: Artem Kobets <artem@akobets.xyz>
Date:   Sun,  5 Jul 2020 17:04:14 +0300

add reset key

Diffstat:
Mconfig.def.h | 6++++++
Mlinput.c | 10++++++++++
2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -94,3 +94,9 @@ static int ignored_keys[] = { BTN_RIGHT, BTN_MIDDLE }; + +/* A key, pressing which will reset hotkey state. + * For rare cases when input event detection misbehaves + * (e.g. on system suspend/resume). + * Set to 0 for no reset key. */ +static int reset_key = 0; diff --git a/linput.c b/linput.c @@ -29,6 +29,7 @@ static int is_key_ignored(int key); static int is_match_hotkey_event(const struct HotkeyRule *hotkey, int key); static int is_match_hotkey_mod(const struct HotkeyRule *hotkey); static int is_hotkey_active(const struct HotkeyRule *hotkey, int last_key); +static void hotkey_reset(); static void run(char **cmd); static void add_fd(int fd, const char *path); @@ -210,6 +211,12 @@ is_hotkey_active(const struct HotkeyRule *hotkey, int last_key) } void +hotkey_reset() +{ + memset(key_state, 0, sizeof(key_state)); +} + +void run(char **cmd) { if (cmd == NULL) @@ -419,6 +426,9 @@ handle_input(int fd) } if (buf.type == EV_KEY) { + if (reset_key != 0 && buf.code == reset_key && buf.value == 1) + hotkey_reset(); + key_state[buf.code] = buf.value; for (i = 0; i < LENGTH(hotkeys); i++) {