Skip to content

Commit

Permalink
input/keyboard: fix bindsym --to-code failing on duplicates
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Furkan Sahin committed Sep 1, 2024
1 parent 980a4e0 commit 727dc17
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions sway/commands/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
}
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 727dc17

Please sign in to comment.