fix some key binding events being passed to clients

This commit is contained in:
Andrea Chiavazza 2025-05-08 22:18:56 +01:00
parent 4456f4536a
commit 1f82a5bc08
2 changed files with 35 additions and 15 deletions

View File

@ -291,11 +291,18 @@ client_is_unmanaged(Client *c)
static inline void static inline void
client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb) client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb)
{ {
if (kb) uint32_t filtered[WLR_KEYBOARD_KEYS_CAP];
wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes, size_t size = 0;
kb->num_keycodes, &kb->modifiers); if (!kb) {
else
wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL); 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 static inline void

35
dwl.c
View File

@ -291,7 +291,7 @@ static void gpureset(struct wl_listener *listener, void *data);
static void handlesig(int signo); static void handlesig(int signo);
static void incnmaster(const Arg *arg); static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data); 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 keypress(struct wl_listener *listener, void *data);
static void keypressmod(struct wl_listener *listener, void *data); static void keypressmod(struct wl_listener *listener, void *data);
static int keyrepeat(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 wlr_box sgeom;
static struct wl_list mons; static struct wl_list mons;
static Monitor *selmon; static Monitor *selmon;
static bool consumed[KEY_MAX + 1];
/* global event handlers */ /* global event handlers */
static struct wl_listener cursor_axis = {.notify = axisnotify}; 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); wlr_seat_set_capabilities(seat, caps);
} }
int const Key *
keybinding(uint32_t mods, xkb_keysym_t sym) keybinding(uint32_t mods, xkb_keysym_t sym)
{ {
/* /*
@ -1613,12 +1614,10 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
const Key *k; const Key *k;
for (k = keys; k < END(keys); k++) { for (k = keys; k < END(keys); k++) {
if (CLEANMASK(mods) == CLEANMASK(k->mod) if (CLEANMASK(mods) == CLEANMASK(k->mod)
&& sym == k->keysym && k->func) { && sym == k->keysym && k->func)
k->func(&k->arg); return k;
return 1;
}
} }
return 0; return NULL;
} }
void void
@ -1644,8 +1643,14 @@ keypress(struct wl_listener *listener, void *data)
/* On _press_ if there is no active screen locker, /* On _press_ if there is no active screen locker,
* attempt to process a compositor keybinding. */ * attempt to process a compositor keybinding. */
if (!locked && event->state == WL_KEYBOARD_KEY_STATE_PRESSED) { if (!locked && event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
for (i = 0; i < nsyms; i++) for (i = 0; i < nsyms; i++) {
handled = keybinding(mods, syms[i]) || handled; 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) { if (handled && group->wlr_group->keyboard.repeat_info.delay > 0) {
@ -1662,6 +1667,11 @@ keypress(struct wl_listener *listener, void *data)
if (handled) if (handled)
return; 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); wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard);
/* Pass unhandled keycodes along to the client. */ /* Pass unhandled keycodes along to the client. */
wlr_seat_keyboard_notify_key(seat, event->time_msec, 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, wl_event_source_timer_update(group->key_repeat_source,
1000 / group->wlr_group->keyboard.repeat_info.rate); 1000 / group->wlr_group->keyboard.repeat_info.rate);
for (i = 0; i < group->nsyms; i++) for (i = 0; i < group->nsyms; i++) {
keybinding(group->mods, group->keysyms[i]); const Key *key = keybinding(group->mods, group->keysyms[i]);
if (key)
key->func(&key->arg);
}
return 0; return 0;
} }