[PATCH libxkbcommon] Add xkb_key_get_action API

Daniel Stone daniel at fooishbar.org
Mon Mar 19 09:10:10 PDT 2012


Hi Ran,

On 16 March 2012 17:04, Ran Benita <ran234 at gmail.com> wrote:
> By which one can tell when to switch groups, etc.
>
> Signed-off-by: Ran Benita <ran234 at gmail.com>
> ---
> This would allow me to delete some duplicate code in the application
> and would make me a happy camper for a while.

It makes sense now, but the API I was hoping for (and am mostly done with) is:
+/**
+ * Updates a state object to reflect the given key being pressed or released.
+ */
+_X_EXPORT void
+xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key, enum
xkb_key_direction direction);

That way users can remain ignorant of the actions completely, which
would make the flow:
{
    struct xkb_keymap *xkb = (...);
    struct xkb_state *state;
    xkb_keycode_t lctrl, ralt, q;

    state = xkb_state_new(xkb);
    /* state is empty */
    xkb_state_update_for_key(state, lctrl, XKB_KEY_PRESSED);
    /* state now reflects Control mod, LCtrl vmod */
    xkb_state_update_for_key(state, ralt, XKB_KEY_RELEASED);
    /* Control, Mod1, LCtrl, RAlt */
    xkb_state_update_for_key(state, q, XKB_KEY_PRESSED);
    /* as above */
    xkb_state_update_for_key(state, q, XKB_KEY_RELEASED);
    /* same again */
    xkb_state_update_for_key(state, lctrl, XKB_KEY_RELEASED);
    /* Mod1, RAlt */
    xkb_state_update_for_key(state, ralt, XKB_KEY_RELEASED);
    /* empty again */
}

Does that sound OK? Any thoughts? Hopefully that'll lead to even less
code in your app (and everyone else's).

> Wasn't sure about a couple of things:
> - Should the by_level API be exposed (the _syms one seems to be non-static
>  but not exported).

I'm thinking that will need to be exported to allow clients to
interrogate the keymap, but want to encourage people to use the state
API as much as possible.

> - Should the API allow for returning multiple actions per keypress (as the
>  _syms API seems to suggest will be done for keysyms)?

At the moment, I can't see a use for multiple actions per keypress,
whereas there's a definite need for symbols, as Unicode has been
pushing back on adding precomposed symbols, so some keymaps have
symbols which cannot be represented in a single symbol; at the moment,
they're working around it by having a placeholder symbol which
triggers an entry in the Compose map with multiple symbols.

Cheers,
Daniel


More information about the xorg-devel mailing list