Key events associated with keybindings (both pressed and released) are not
sent to clients. When using wlr_seat_keyboard_notify_enter() it it
therefore important not to send the keycodes of _all_ pressed keys, but
only those that were actually _sent_ to clients (that is, those that were
not bound).
This approach is consistent with sway's implementation in input/seat.c
https://github.com/swaywm/sway/blob/
cffb006feba52c318e66f73c3463032fa76782dc/sway/input/seat.c#L173-L175
Fixes issue #510
#ifndef __LABWC_KEY_STATE_H
#define __LABWC_KEY_STATE_H
+/*
+ * All keycodes in these functions are (Linux) libinput evdev scancodes which is
+ * what 'wlr_keyboard' uses (e.g. 'seat->keyboard_group->keyboard->keycodes').
+ * Note: These keycodes are different to XKB scancodes by a value of 8.
+ */
+
+/**
+ * key_state_pressed_sent_keycodes - generate array of pressed+sent keys
+ * Note: The array is generated by subtracting any bound keys from _all_ pressed
+ * keys (because bound keys were not forwarded to clients).
+ */
+uint32_t *key_state_pressed_sent_keycodes(void);
+int key_state_nr_pressed_sent_keycodes(void);
+
void key_state_set_pressed(uint32_t keycode, bool ispressed);
void key_state_store_pressed_keys_as_bound(void);
bool key_state_corresponding_press_event_was_bound(uint32_t keycode);
int nr_keys;
};
-static struct key_array pressed, bound;
+static struct key_array pressed, bound, pressed_sent;
static void
remove_key(struct key_array *array, uint32_t keycode)
array->keys[array->nr_keys++] = keycode;
}
+uint32_t *
+key_state_pressed_sent_keycodes(void)
+{
+ /* pressed_sent = pressed - bound */
+ memcpy(pressed_sent.keys, pressed.keys,
+ MAX_PRESSED_KEYS * sizeof(uint32_t));
+ pressed_sent.nr_keys = pressed.nr_keys;
+ for (int i = 0; i < bound.nr_keys; ++i) {
+ remove_key(&pressed_sent, bound.keys[i]);
+ }
+ return pressed_sent.keys;
+}
+
+int
+key_state_nr_pressed_sent_keycodes(void)
+{
+ return pressed_sent.nr_keys;
+}
+
void
key_state_set_pressed(uint32_t keycode, bool ispressed)
{
}
for (size_t i = 0; i < keybind->keysyms_len; i++) {
if (xkb_keysym_to_lower(sym) == keybind->keysyms[i]) {
+ key_state_store_pressed_keys_as_bound();
actions_run(NULL, server, &keybind->actions, 0);
return true;
}
bool handled = false;
- key_state_set_pressed(keycode,
+ key_state_set_pressed(event->keycode,
event->state == WL_KEYBOARD_KEY_STATE_PRESSED);
/*
* If a press event was handled by a compositor binding, then do not
* forward the corresponding release event to clients
*/
- if (key_state_corresponding_press_event_was_bound(keycode)
+ if (key_state_corresponding_press_event_was_bound(event->keycode)
&& event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
- key_state_bound_key_remove(keycode);
+ key_state_bound_key_remove(event->keycode);
return true;
}
if (!handled) {
wlr_seat_set_keyboard(wlr_seat, keyboard);
wlr_seat_keyboard_notify_key(wlr_seat, event->time_msec,
- event->keycode, event->state);
+ event->keycode, event->state);
}
}
#include <wlr/types/wlr_touch.h>
#include <wlr/util/log.h>
#include "common/mem.h"
+#include "key-state.h"
#include "labwc.h"
static void
return;
}
struct wlr_keyboard *kb = &seat->keyboard_group->keyboard;
- wlr_seat_keyboard_notify_enter(seat->seat, surface, kb->keycodes,
- kb->num_keycodes, &kb->modifiers);
+
+ /*
+ * Key events associated with keybindings (both pressed and released)
+ * are not sent to clients. When changing surface-focus it is therefore
+ * important not to send the keycodes of _all_ pressed keys, but only
+ * those that were actually _sent_ to clients (that is, those that were
+ * not bound).
+ */
+ uint32_t *pressed_sent_keycodes = key_state_pressed_sent_keycodes();
+ int nr_pressed_sent_keycodes = key_state_nr_pressed_sent_keycodes();
+
+ wlr_seat_keyboard_notify_enter(seat->seat, surface,
+ pressed_sent_keycodes, nr_pressed_sent_keycodes, &kb->modifiers);
struct server *server = seat->server;
struct wlr_pointer_constraint_v1 *constraint =