linput

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

commit 6c65cf9172d32623bd22d7afb10b9c7ebb0bfd6b
parent 7138fb5b0280b0a2c8d4ca22543d4e78eb8364f6
Author: Artem Kobets <artem@akobets.xyz>
Date:   Mon, 20 Apr 2020 12:29:19 +0300

docs

Diffstat:
M.gitignore | 1+
MREADME | 9+++++++++
Mconfig.def.h | 5++++-
Mlinput.c | 13++++++-------
4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1 +1,2 @@ linput +config.h diff --git a/README b/README @@ -33,6 +33,15 @@ They consist of a modifier mask (Ctrl, Alt, etc.), a list of regular keys, and an event mask (trigger on press, release or hold). +Recommendations +--------------- +linput opens device files, and it might not have permission to do this if it +is not executed as root. If you'd like to execute it as normal user, you can achieve this +with one of the following: + - add user to a group that has read permission on input device files (e.g. 'input') + - modify makefile to use setuid or setgid on executable, so it always gets needed permissions. + + Author ------ Artem Kobets <artem@akobets.xyz> diff --git a/config.def.h b/config.def.h @@ -5,6 +5,7 @@ static char *cmd_volumeup[] = { "amixer", "-qM", "sset", "Master", "2%+", NULL } static char *cmd_volumedown[] = { "amixer", "-qM", "sset", "Master", "2%-", NULL }; static struct EventRule { + /* set cmd as NULL to disable the rule */ char **cmd; /* see <linux/input-event-codes.h> * for type/code/value available values */ @@ -43,10 +44,12 @@ enum { #define HOTKEY_MAX_KEYS 10 static struct HotkeyRule { + /* set cmd as NULL to disable the rule */ char **cmd; int mod_mask; /* see <linux/input-event-codes.h> for complete list - * (KEY_* constants) */ + * (KEY_* constants) + * end with 0 */ int keys[HOTKEY_MAX_KEYS + 1]; int event_mask; } hotkeys[] = { diff --git a/linput.c b/linput.c @@ -441,18 +441,17 @@ handle_inotify(int fd) { snprintf(filename, sizeof(filename), "/dev/input/%s", event->name); retries = 0; - max_retries = 3; + max_retries = 1; while (retries <= max_retries) { fd = open_input_file(filename); - /* If linput was started as normal user, - * file may not be opened due to missing file permissions. - * If that's the case, try several times before giving up. - */ + /* If program is executed as normal user, + * device files may not have required permissions + * to be opened right away (hotplug race condition) + * If that's the case, retry before giving up. */ if (fd == -1 && errno == EACCES) { sleep(1); retries++; - } - else + } else break; } }