From 1f82a5bc0805acb4f97f1865a802200afa4f3913 Mon Sep 17 00:00:00 2001 From: Andrea Chiavazza Date: Thu, 8 May 2025 22:18:56 +0100 Subject: [PATCH] fix some key binding events being passed to clients --- client.h | 15 +++++++++++---- dwl.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/client.h b/client.h index f1e2ab5..aa366b4 100644 --- a/client.h +++ b/client.h @@ -291,11 +291,18 @@ client_is_unmanaged(Client *c) static inline void client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb) { - if (kb) - wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes, - kb->num_keycodes, &kb->modifiers); - else + uint32_t filtered[WLR_KEYBOARD_KEYS_CAP]; + size_t size = 0; + if (!kb) { wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL); + return; + } + for (size_t i = 0; i < kb->num_keycodes; i++) { + uint32_t key = kb->keycodes[i]; + if (!consumed[key]) + filtered[size++] = key; + } + wlr_seat_keyboard_notify_enter(seat, s, filtered, size, &kb->modifiers); } static inline void diff --git a/dwl.c b/dwl.c index 4816159..bd62cf6 100644 --- a/dwl.c +++ b/dwl.c @@ -291,7 +291,7 @@ static void gpureset(struct wl_listener *listener, void *data); static void handlesig(int signo); static void incnmaster(const Arg *arg); static void inputdevice(struct wl_listener *listener, void *data); -static int keybinding(uint32_t mods, xkb_keysym_t sym); +static const Key * keybinding(uint32_t mods, xkb_keysym_t sym); static void keypress(struct wl_listener *listener, void *data); static void keypressmod(struct wl_listener *listener, void *data); static int keyrepeat(void *data); @@ -405,6 +405,7 @@ static struct wlr_output_layout *output_layout; static struct wlr_box sgeom; static struct wl_list mons; static Monitor *selmon; +static bool consumed[KEY_MAX + 1]; /* global event handlers */ static struct wl_listener cursor_axis = {.notify = axisnotify}; @@ -1602,7 +1603,7 @@ inputdevice(struct wl_listener *listener, void *data) wlr_seat_set_capabilities(seat, caps); } -int +const Key * keybinding(uint32_t mods, xkb_keysym_t sym) { /* @@ -1613,12 +1614,10 @@ keybinding(uint32_t mods, xkb_keysym_t sym) const Key *k; for (k = keys; k < END(keys); k++) { if (CLEANMASK(mods) == CLEANMASK(k->mod) - && sym == k->keysym && k->func) { - k->func(&k->arg); - return 1; - } + && sym == k->keysym && k->func) + return k; } - return 0; + return NULL; } void @@ -1644,8 +1643,14 @@ keypress(struct wl_listener *listener, void *data) /* On _press_ if there is no active screen locker, * attempt to process a compositor keybinding. */ if (!locked && event->state == WL_KEYBOARD_KEY_STATE_PRESSED) { - for (i = 0; i < nsyms; i++) - handled = keybinding(mods, syms[i]) || handled; + for (i = 0; i < nsyms; i++) { + const Key *key = keybinding(mods, syms[i]); + if (key) { + consumed[event->keycode] = true; + key->func(&key->arg); + handled = 1; + } + } } if (handled && group->wlr_group->keyboard.repeat_info.delay > 0) { @@ -1662,6 +1667,11 @@ keypress(struct wl_listener *listener, void *data) if (handled) return; + if (consumed[event->keycode]) { + if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) + consumed[event->keycode] = false; + return; // don't pass to the client the release event of a handled key-press + } wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard); /* Pass unhandled keycodes along to the client. */ wlr_seat_keyboard_notify_key(seat, event->time_msec, @@ -1692,8 +1702,11 @@ keyrepeat(void *data) wl_event_source_timer_update(group->key_repeat_source, 1000 / group->wlr_group->keyboard.repeat_info.rate); - for (i = 0; i < group->nsyms; i++) - keybinding(group->mods, group->keysyms[i]); + for (i = 0; i < group->nsyms; i++) { + const Key *key = keybinding(group->mods, group->keysyms[i]); + if (key) + key->func(&key->arg); + } return 0; }