Skip to content

Commit

Permalink
keymap: add xkb_keymap_key_get_name()
Browse files Browse the repository at this point in the history
this function is the inverse of xkb_keymap_key_by_name()

Signed-off-by: Mike Blumenkrantz <[email protected]>
  • Loading branch information
Mike Blumenkrantz committed Jan 20, 2016
1 parent f1334cc commit ff20653
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,19 @@ xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter,
iter(keymap, key->keycode, data);
}

XKB_EXPORT const char *
xkb_keymap_key_get_name(struct xkb_keymap *keymap, xkb_keycode_t kc)
{
struct xkb_key *key;

xkb_keys_foreach(key, keymap) {
if (key->keycode == kc)
return xkb_atom_text(keymap->ctx, key->name);
}

return NULL;
}

XKB_EXPORT xkb_keycode_t
xkb_keymap_key_by_name(struct xkb_keymap *keymap, const char *keyname)
{
Expand Down
13 changes: 13 additions & 0 deletions xkbcommon/xkbcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,19 @@ void
xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter,
void *data);

/**
* Find the key name for a given keycode in a keymap.
*
* @returns The key name. If no key with this keycode exists,
* returns NULL.
*
* @sa xkb_keycode_t
* @memberof xkb_keymap
* @since 0.6.0
*/
const char *
xkb_keymap_key_get_name(struct xkb_keymap *keymap, xkb_keycode_t kc);

/**
* Find the keycode for a given keyname in a keymap.
*
Expand Down

0 comments on commit ff20653

Please sign in to comment.