linput

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

commit 8105d5476538091fced17904c53ac2245e2e927e
parent 9e028dfe858c373590da5d8dfe2f7c430aece07c
Author: Artem Kobets <artem@akobets.xyz>
Date:   Sun, 19 Apr 2020 13:17:08 +0300

don't die on fork fail

Diffstat:
Mlinput.c | 97+++++++++++++++++++++++++------------------------------------------------------
1 file changed, 30 insertions(+), 67 deletions(-)

diff --git a/linput.c b/linput.c @@ -116,81 +116,45 @@ is_match_hotkey_mod(const struct HotkeyRule *hotkey) if (mod_mask & MOD_ANY) return 1; - - if ( - (mod_mask & MOD_LEFTSHIFT) && - key_state[KEY_LEFTSHIFT] == 0 - ) + if ((mod_mask & MOD_LEFTSHIFT) && + key_state[KEY_LEFTSHIFT] == 0) return 0; - - if ( - (mod_mask & MOD_RIGHTSHIFT) && - key_state[KEY_RIGHTSHIFT] == 0 - ) + if ((mod_mask & MOD_RIGHTSHIFT) && + key_state[KEY_RIGHTSHIFT] == 0) return 0; - - if ( - (mod_mask & MOD_SHIFT) && + if ((mod_mask & MOD_SHIFT) && (key_state[KEY_LEFTSHIFT] == 0 && - key_state[KEY_RIGHTSHIFT] == 0) - ) + key_state[KEY_RIGHTSHIFT] == 0)) return 0; - - if ( - (mod_mask & MOD_LEFTCTRL) && - key_state[KEY_LEFTCTRL] == 0 - ) + if ((mod_mask & MOD_LEFTCTRL) && + key_state[KEY_LEFTCTRL] == 0) return 0; - - if ( - (mod_mask & MOD_RIGHTCTRL) && - key_state[KEY_RIGHTCTRL] == 0 - ) + if ((mod_mask & MOD_RIGHTCTRL) && + key_state[KEY_RIGHTCTRL] == 0) return 0; - - if ( - (mod_mask & MOD_CTRL) && + if ((mod_mask & MOD_CTRL) && (key_state[KEY_LEFTCTRL] == 0 && - key_state[KEY_RIGHTCTRL] == 0) - ) + key_state[KEY_RIGHTCTRL] == 0)) return 0; - - if ( - (mod_mask & MOD_LEFTSUPER) && - key_state[KEY_LEFTMETA] == 0 - ) + if ((mod_mask & MOD_LEFTSUPER) && + key_state[KEY_LEFTMETA] == 0) return 0; - - if ( - (mod_mask & MOD_RIGHTSUPER) && - key_state[KEY_RIGHTMETA] == 0 - ) + if ((mod_mask & MOD_RIGHTSUPER) && + key_state[KEY_RIGHTMETA] == 0) return 0; - - if ( - (mod_mask & MOD_SUPER) && + if ((mod_mask & MOD_SUPER) && (key_state[KEY_LEFTMETA] == 0 && - key_state[KEY_RIGHTMETA] == 0) - ) + key_state[KEY_RIGHTMETA] == 0)) return 0; - - if ( - (mod_mask & MOD_LEFTALT) && - key_state[KEY_LEFTALT] == 0 - ) + if ((mod_mask & MOD_LEFTALT) && + key_state[KEY_LEFTALT] == 0) return 0; - - if ( - (mod_mask & MOD_RIGHTALT) && - key_state[KEY_RIGHTALT] == 0 - ) + if ((mod_mask & MOD_RIGHTALT) && + key_state[KEY_RIGHTALT] == 0) return 0; - - if ( - (mod_mask & MOD_ALT) && + if ((mod_mask & MOD_ALT) && (key_state[KEY_LEFTALT] == 0 && - key_state[KEY_RIGHTALT] == 0) - ) + key_state[KEY_RIGHTALT] == 0)) return 0; return 1; @@ -203,12 +167,10 @@ is_hotkey_active(const struct HotkeyRule *hotkey, int last_key) if (!has_key(hotkey, last_key) && !is_mod(last_key)) return 0; - - if (!is_match_hotkey_mod(hotkey)) - return 0; - if (!is_match_hotkey_event(hotkey, last_key)) return 0; + if (!is_match_hotkey_mod(hotkey)) + return 0; for (k = 1; k < LENGTH(key_state); k++) { if (k == last_key || is_mod(k)) @@ -234,12 +196,13 @@ run(char **cmd) { switch (fork()) { case -1: - die("fork: %s\n", strerror(errno)); + fprintf(stderr, "fork: %s\n", strerror(errno)); break; case 0: - if (cmd != NULL && cmd[0] != NULL) + if (cmd != NULL) { execvp(cmd[0], cmd); - fprintf(stderr, "execvp %s: %s\n", cmd[0], strerror(errno)); + fprintf(stderr, "execvp %s: %s\n", cmd[0], strerror(errno)); + } _exit(EXIT_FAILURE); break; }