xkbcommon: Converting keysym to keycode

adlo adloconwy at gmail.com
Sat Dec 4 10:36:23 UTC 2021


Does xkbcommon have modifier masks, like that used in the “state” field of XKeyEvent?

> On 4 Dec 2021, at 08:34, adlo <adloconwy at gmail.com> wrote:
> 
> Basically the program I’m working on was originally designed for X11, and I’m trying to adapt it to Wayland. I’m trying to find an equivalent to XKeysymToKeycode().
> 
>> it doesn't, but if you look at xkbcli how-to-type and it's source
>> (tools/how-to-type.c) that's the closest approximation.
> 
> What does this program do? Does it iterate through all possible keycodes and lookup the keysym for them?
>> 
>> Main reason is that the keycode->keysym conversion is one-way only and it's
>> not 100% reliable to go back. e.g. if a modifier is locked/latched you cannot
>> access certain keysyms without unlocking that modifier, etc.
> 
> How would I deal with capital letters with regards to getting a keycode from a keysym?
> 
>> KEY_TAB is defined in linux/input-event-codes.h. XKB uses those keycodes + 8
>> for the evdev ruleset (see /usr/share/X11/xkb/keycodes/evdev for the mapping)
>> and it goes from there. If you're using a different ruleset you're going to
>> get interesting results but evdev is effectively hardcoded everywhere anyway,
>> so you won't.
> 
> Is linux/input-event-codes.h keycodes or keysyms?


More information about the wayland-devel mailing list