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 <dan...@fooishbar.org> wrote: > Hi, > > On 1 June 2015 at 12:22, 박성진 <sj76.p...@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<dan...@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.p...@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@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/wayland-devel > > -- Jasper
_______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel