From 54bc764f0d41f0ed7da2a1ce96800e23680479c4 Mon Sep 17 00:00:00 2001 From: jyn Date: Sun, 22 Sep 2024 05:00:33 -0400 Subject: [PATCH] config: Allow `m:*` to specify all mouse ids at once Previously, each mouse input device had to be specified explicitly in the config file. Now, all mice can be specified at once using `m:*`. To avoid backwards compatibility issues, `*` retains its existing meaning of "all keyboard devices". To avoid capturing our own mouse output, the virtual pointer device is now marked as virtual (previously only the virtual keyboard was marked as virtual). --- docs/keyd.scdoc | 5 +++-- src/config.c | 5 +++++ src/config.h | 1 + src/daemon.c | 8 ++------ src/device.c | 2 +- src/keyd.h | 1 + src/vkbd.h | 2 +- src/vkbd/uinput.c | 6 +++--- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/docs/keyd.scdoc b/docs/keyd.scdoc index 553f370e..7aa52c1e 100644 --- a/docs/keyd.scdoc +++ b/docs/keyd.scdoc @@ -86,6 +86,7 @@ or [ids] * + m:* - - ... @@ -129,9 +130,9 @@ Note: All keyboards defined within a given config file will share the same state. This is useful for linking separate input devices together (e.g foot pedals). -Note 2: The wildcard will only match devices which keyd identifies as keyboards. +Note 2: The `*` wildcard will only match devices which keyd identifies as keyboards. keyd is also capable of *managing mice* (e.g to facilitate clearing -of oneshot modifiers on click), but their ids must be explicitly listed. +of oneshot modifiers on click). To match all mice, use `m:*`. Note 3: *Mouse support is currently experimental*, and is mostly confined to traditional mice (e.g touchpads). Adding some mice to diff --git a/src/config.c b/src/config.c index d3b301ce..de3be1c0 100644 --- a/src/config.c +++ b/src/config.c @@ -773,6 +773,8 @@ static void parse_id_section(struct config *config, struct ini_section *section) if (!strcmp(s, "*")) { config->wildcard = 1; + } else if (!strcmp(s, "m:*")) { + config->wildcard_mouse = 1; } else if (strstr(s, "m:") == s) { assert(config->nr_ids < ARRAY_SIZE(config->ids)); config->ids[config->nr_ids].flags = ID_MOUSE; @@ -962,6 +964,9 @@ int config_check_match(struct config *config, const char *id, uint8_t flags) } } + /* Only the `m:*` wildcard should match mice, not the default `*` wildcard. */ + if (flags == ID_MOUSE) + return config->wildcard_mouse ? 1 : 0; return config->wildcard ? 1 : 0; } diff --git a/src/config.h b/src/config.h index 6fe9fee3..30c8ec96 100644 --- a/src/config.h +++ b/src/config.h @@ -119,6 +119,7 @@ struct config { char aliases[256][32]; uint8_t wildcard; + uint8_t wildcard_mouse; struct { char id[64]; uint8_t flags; diff --git a/src/daemon.c b/src/daemon.c index 90333724..39096beb 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -199,11 +199,7 @@ static struct config_ent *lookup_config_ent(const char *id, uint8_t flags) ent = ent->next; } - /* The wildcard should not match mice. */ - if (rank == 1 && (flags == ID_MOUSE)) - return NULL; - else - return match; + return match; } static void manage_device(struct device *dev) @@ -545,7 +541,7 @@ int run_daemon(int argc, char *argv[]) if (ipcfd < 0) die("failed to create %s (another instance already running?)", SOCKET_PATH); - vkbd = vkbd_init(VKBD_NAME); + vkbd = vkbd_init(VKBD_NAME, VPTR_NAME); setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stderr, NULL, _IOLBF, 0); diff --git a/src/device.c b/src/device.c index c7bc5fb5..bc4ce1d6 100644 --- a/src/device.c +++ b/src/device.c @@ -185,7 +185,7 @@ static int device_init(const char *path, struct device *dev) dev->data = NULL; dev->grabbed = 0; - dev->is_virtual = !strcmp(dev->name, VKBD_NAME); + dev->is_virtual = !strcmp(dev->name, VKBD_NAME) || !strcmp(dev->name, VPTR_NAME); return 0; } else { close(fd); diff --git a/src/keyd.h b/src/keyd.h index 63189390..334a7f99 100644 --- a/src/keyd.h +++ b/src/keyd.h @@ -50,6 +50,7 @@ #define ARRAY_SIZE(x) (int)(sizeof(x)/sizeof(x[0])) #define VKBD_NAME "keyd virtual keyboard" +#define VPTR_NAME "keyd virtual pointer" enum event_type { EV_DEV_ADD, diff --git a/src/vkbd.h b/src/vkbd.h index e5123067..4773824c 100644 --- a/src/vkbd.h +++ b/src/vkbd.h @@ -10,7 +10,7 @@ struct vkbd; -struct vkbd *vkbd_init(const char *name); +struct vkbd *vkbd_init(const char *kbd_name, const char *ptr_name); void vkbd_mouse_move(const struct vkbd *vkbd, int x, int y); void vkbd_mouse_move_abs(const struct vkbd *vkbd, int x, int y); diff --git a/src/vkbd/uinput.c b/src/vkbd/uinput.c index 6c5f974b..c1b298cf 100644 --- a/src/vkbd/uinput.c +++ b/src/vkbd/uinput.c @@ -225,13 +225,13 @@ static void write_key_event(const struct vkbd *vkbd, uint8_t code, int state) pthread_mutex_unlock(&mtx); } -struct vkbd *vkbd_init(const char *name) +struct vkbd *vkbd_init(const char *kbd_name, const char *ptr_name) { pthread_t tid; struct vkbd *vkbd = calloc(1, sizeof vkbd); - vkbd->fd = create_virtual_keyboard(name); - vkbd->pfd = create_virtual_pointer("keyd virtual pointer"); + vkbd->fd = create_virtual_keyboard(kbd_name); + vkbd->pfd = create_virtual_pointer(ptr_name); return vkbd; }