Re: xkbcommon: Converting keysym to keycode

2022-08-06 Thread adlo
afaict there’s a for loop that iterates over all the layouts, and within that 
it iterates over all the shift levels, and within that it iterates over all the 
modifier masks? Is that what’s going on? So basically it’s iterating over them 
until it finds a match?

In that printf on line 220, would the value of “keycode” at that point be the 
best approximation of XKeysymToKeycode ()?

What’s the difference between shift level and modifier state? They seem to 
overlap somewhat. Is it that the Shift key can be both a modifier and a shift 
level, but the Num Lock key is a shift level but not a modifier?

Regards
adlo

> On 5 Dec 2021, at 23:14, adlo  wrote:
> 
> 
>> 
>> On 5 Dec 2021, at 05:15, Peter Hutterer  wrote:
>> 
>> please look at the source, it's not a huge program.
> 
> I have looked at the source, it’s just that I can’t see anything that’s 
> directly related to what I’m trying to do. It calls 
> xkb_keymap_key_get_mods_for_level(), which seems to be related to getting the 
> mods, and it seems to have things that get the name of a key, or get a key 
> from the name, but I can’t see anything that looks like it’s related to 
> getting or approximating a keycode from a keysym.
> 


Re: xkbcommon: Converting keysym to keycode

2021-12-06 Thread adlo
> On 5 Dec 2021, at 05:15, Peter Hutterer  wrote:
> 
> please look at the source, it's not a huge program.

I have looked at the source, it’s just that I can’t see anything that’s 
directly related to what I’m trying to do. It calls 
xkb_keymap_key_get_mods_for_level(), which seems to be related to getting the 
mods, and it seems to have things that get the name of a key, or get a key from 
the name, but I can’t see anything that looks like it’s related to getting or 
approximating a keycode from a keysym.



Re: xkbcommon: Converting keysym to keycode

2021-12-06 Thread Peter Hutterer
On Sat, Dec 04, 2021 at 08:34:49AM +, adlo 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?

please look at the source, it's not a huge program.

> > 
> > 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?

there's no such thing as a capital letter with keycodes, keycodes are really
just "this physical key has been pressed". so capital letters usually resolve
to a sequence - shift down, keycode, shift up. That is where the difficult
bits start.

> 
> > 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?

keycodes, but they have semantic naming for easier association.

Cheers,
  Peter


Re: xkbcommon: Converting keysym to keycode

2021-12-06 Thread adlo
Does xkbcommon have modifier masks, like that used in the “state” field of 
XKeyEvent?

> On 4 Dec 2021, at 08:34, adlo  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?


Re: xkbcommon: Converting keysym to keycode

2021-12-06 Thread adlo
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?

Re: xkbcommon: Converting keysym to keycode

2021-12-01 Thread Peter Hutterer
On Wed, Dec 01, 2021 at 02:31:38PM +, adlo wrote:
> Does xkbcommon have a function to convert a keysym to a keycode?

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.

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.

> Also, what keycodes does Weston use? It seems that in libweston, KEY_TAB is
> assigned the number 15. Is this a real keycode? Is this a standard keycode?
> Is it used in xkbcommon or anything like that?

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.

And note, it's a keycode with a semantic naming after the US layout. Those
names are just easier to identify than XKB's naming scheme, e.g. KEY_C is a
lot easier to understand than AB03 (alphabetic keys, second row from botton,
third from left). This goes doubly for high keycodes, KEY_MICMUTE is a lot
easier to associate than I256 (Internet key 256) [1]

It's effectively standard everywhere in Wayland, including things like
BTN_LEFT instead of numerical buttons.

Cheers,
   Peter

[1] because the internet was totally the future when that naming scheme was
invented.


Re: xkbcommon: Converting keysym to keycode

2021-12-01 Thread Andri Yngvason
Hi adlo

mið., 1. des. 2021 kl. 14:31 skrifaði adlo :
>
> Hi
>
> Does xkbcommon have a function to convert a keysym to a keycode?

It does not, last time I checked, but
"xkb_keymap_key_get_mods_for_level" does help a lot.

Wayvnc does this sort of reverse key mapping. Maybe this helps? See:
https://github.com/any1/wayvnc/blob/master/src/keyboard.c

Regards,
Andri


xkbcommon: Converting keysym to keycode

2021-12-01 Thread adlo
Hi

Does xkbcommon have a function to convert a keysym to a keycode?

Also, what keycodes does Weston use? It seems that in libweston, KEY_TAB is 
assigned the number 15. Is this a real keycode? Is this a standard keycode? Is 
it used in xkbcommon or anything like that?

Regards

adlo