[libxkbcommon] Question about how to get xkb_keycode_t from xkb_keysym_t.

Jasper St. Pierre jstpierre at mecheye.net
Mon Jun 1 08:40:57 PDT 2015


Note that there are non-obvious consequences to this. The keymap is
hierarchical upon layouts and levels. You can either do a depth-first
search, or a breadth-first search. This can change behavior.
XKeysymToKeycode is documented as doing a breadth-first search. This can
have consequences in behavior. See:

https://git.gnome.org/browse/mutter/commit/src/core/keybindings.c?id=60c22b62366d737f7f6eabe7d46fa682c6f400d7

I'd highly recommend doing keygrabs on keysyms if you do want to let your
clients do key grabs at all.

On Mon, Jun 1, 2015 at 6:02 AM, Daniel Stone <daniel at fooishbar.org> wrote:

> Hi,
>
> On 1 June 2015 at 12:22, 박성진 <sj76.park at samsung.com> wrote:
>
>>  Actually, we'd like to provide a key grab protocol to wayland client(s)
>>
>> with which each client can make request to grab a key to wayland
>> compositor.
>>
>> To use the protocol, we need to provide one or more keycodes associated
>> with a given keysym to the compositor as an argument.
>>
>> At this moment we would like to call the following API to get keycode(s)
>> from a keysym if exist.
>>
>> Could you share your opinion ?
>>
>
> You might be better off asking to grab on a particular keysym instead,
> since the compositor always needs to track the current state so can
> trivially extract the keysym.
>
>
>> /**
>>
>>  @param[in] keymap : xkb_keymap pointer
>>
>>  @param[in] keysym : xkb_keysym_t keysym
>>
>>  @param[out] keycodes array : xkb_keycode_t pointer
>>
>>  @return number of keycodes found on success, otherwise -1
>>
>> */
>>
>> XKB_EXPORT int xkb_keycodes_from_keysym(struct xkb_keymap *keymap,
>> xkb_keysym_t keysym, xkb_keycode_t *keycodes);
>>
>> or XKB_EXPORT int xkb_keymap_keycodes_from_keysym(struct xkb_keymap
>> *keymap, xkb_keysym_t keysym, xkb_keycode_t *keycodes);
>>
> On the face of it, this seems okay, except you might want to document that
> 0 is a valid, non-error, return code; presumably in order to deal with
> keycode allocation, you would have to do something like:
> xkb_keycode_t *keycodes;
> int num_keycodes;
>
> num_keycodes = xkb_keymap_keycodes_from_keysym(keymap, keysym, NULL);
> if (num_keycodes == -1)
>     return -1;
> else if (num_keycodes == 0)
>     return 1; /* still succeeded, just don't have any keycodes */
>
> keycodes = malloc(num_keycodes * sizeof(*keycodes));
> num_keycodes = xkb_keymap_keycodes_from_keysym(keymap, keysym, keycodes);
>
> Cheers,
> Daniel
>
>
>> Thanks and regards,
>>
>> Sung-Jin Park
>>
>>
>>
>> ------- *Original Message* -------
>>
>> *Sender* : Daniel Stone<daniel at fooishbar.org>
>>
>> *Date* : 2015-06-01 18:57 (GMT+09:00)
>>
>> *Title* : Re: [libxkbcommon] Question about how to get xkb_keycode_t
>> from xkb_keysym_t.
>>
>>
>> Hi Sung-Jin,
>>
>> On 1 June 2015 at 07:16, Sung-Jin Park <sj76.park at samsung.com> wrote:
>>
>>>  I'd like to ask how to get keycode(s) from keysym using libxkbcommon
>>> API.
>>> Is there any API in libxkbcommon ?
>>>
>>
>> The short answer is, no.
>>
>> The long answer is, look through the keymap and find every keycode which
>> produces that keysym, which may be on various layouts (groups) or shift
>> levels.
>>
>> If you can share more details of what you actually want to achieve, that
>> might be helpful.
>>
>> Cheers,
>> Daniel
>>
>>
>>
>>
>>
>>
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
>


-- 
  Jasper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20150601/f0fc1807/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 201506012022904_HZO3ZPZQ.gif
Type: image/gif
Size: 13168 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20150601/f0fc1807/attachment-0001.gif>


More information about the wayland-devel mailing list