From 727dc178e152f3c2f868c879c7ccbda3132666b4 Mon Sep 17 00:00:00 2001 From: Furkan Sahin Date: Sun, 1 Sep 2024 17:27:23 -0500 Subject: [PATCH] input/keyboard: fix bindsym --to-code failing on duplicates If a keysymbol maps to many keycodes, we should choose the first seen keycode instead of last seen, because it is more likely that duplic ates are coming from nonstandard keys such as the 'Internet' keys. With these changes, I can bindsym my Print key. API maps both keycodes 107 and 218 to the Keysym 0xff61 = 65377. The only way to map between keysym to keycode or vice versa seems to be to loop through all keycodes exposed by and it starts from the 'lowest' or first keycode. --- sway/commands/bind.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 268f285537..2766fa2c39 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c @@ -649,7 +649,7 @@ void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding) } /** - * The last found keycode associated with the keysym + * The first found keycode associated with the keysym * and the total count of matches. */ struct keycode_matches { @@ -673,8 +673,10 @@ static void find_keycode(struct xkb_keymap *keymap, struct keycode_matches *matches = data; if (matches->keysym == keysym) { - matches->keycode = keycode; matches->count++; + if (matches->count == 1) { + matches->keycode = keycode; + } } } @@ -718,10 +720,9 @@ bool translate_binding(struct sway_binding *binding) { xkb_keysym_t *keysym = binding->syms->items[i]; struct keycode_matches matches = get_keycode_for_keysym(*keysym); - if (matches.count != 1) { - sway_log(SWAY_INFO, "Unable to convert keysym %" PRIu32 " into" - " a single keycode (found %d matches)", - *keysym, matches.count); + if (matches.count < 1) { + sway_log(SWAY_INFO, "Unable to convert keysym %" PRIu32 " into a keycode", + *keysym); goto error; }