~ruther/dwl

f6800e95ee3f2009c2bd0d8178d24ae961c18988 — Andrea Chiavazza 1 year, 6 months ago 7fb2024
fix some key binding events being passed to clients
2 files changed, 34 insertions(+), 13 deletions(-)

M client.h
M dwl.c
M client.h => client.h +11 -4
@@ 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

M dwl.c => dwl.c +23 -9
@@ 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 int consumed[KEY_MAX + 1];

/* global event handlers */
static struct wl_listener cursor_axis = {.notify = axisnotify};


@@ 1610,7 1611,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)
{
	/*


@@ 1623,11 1624,10 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
		if (CLEANMASK(mods) == CLEANMASK(k->mod)
				&& xkb_keysym_to_lower(sym) == xkb_keysym_to_lower(k->keysym)
				&& k->func) {
			k->func(&k->arg);
			return 1;
			return k;
		}
	}
	return 0;
	return NULL;
}

void


@@ 1653,8 1653,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] = 1;
				key->func(&key->arg);
				handled = 1;
			}
		}
	}

	if (handled && group->wlr_group->keyboard.repeat_info.delay > 0) {


@@ 1671,6 1677,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] = 0;
		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,


@@ 1701,8 1712,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;
}