Promote keymap enumeration API to public

Rename the functions to get keysyms by key/layout/level to fit with the
recent public API renames, and expose them.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
master
Daniel Stone 2012-09-19 16:19:57 +10:00
parent 33a66515d6
commit bf19408078
7 changed files with 101 additions and 53 deletions

View File

@ -568,8 +568,8 @@ write_keysyms(struct xkb_keymap *keymap, struct buf *buf,
for (level = 0; level < XkbKeyGroupWidth(keymap, key, group); level++) {
if (level != 0)
write_buf(buf, ", ");
num_syms = xkb_key_get_syms_by_level(keymap, key, group, level,
&syms);
num_syms = xkb_keymap_key_get_syms_by_level(keymap, key->keycode,
group, level, &syms);
if (num_syms == 0) {
write_buf(buf, "%15s", "NoSymbol");
}

View File

@ -225,6 +225,20 @@ xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t kc)
return key->num_groups;
}
/**
* Returns the number of levels active for a particular key and layout.
*/
XKB_EXPORT xkb_level_index_t
xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t kc,
xkb_layout_index_t layout)
{
const struct xkb_key *key = XkbKey(keymap, kc);
if (!key)
return 0;
return XkbKeyGroupWidth(keymap, key, layout);
}
/**
* Return the total number of active LEDs in the keymap.
*/
@ -299,13 +313,15 @@ get_entry_for_key_state(struct xkb_state *state, const struct xkb_key *key,
* XKB_LEVEL_INVALID.
*/
xkb_level_index_t
xkb_key_get_level(struct xkb_state *state, const struct xkb_key *key,
xkb_group_index_t group)
xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
xkb_layout_index_t layout)
{
struct xkb_keymap *keymap = xkb_state_get_keymap(state);
const struct xkb_key *key = XkbKey(keymap, kc);
struct xkb_kt_map_entry *entry;
/* If we don't find an explicit match the default is 0. */
entry = get_entry_for_key_state(state, key, group);
entry = get_entry_for_key_state(state, key, layout);
if (!entry)
return 0;
@ -313,17 +329,19 @@ xkb_key_get_level(struct xkb_state *state, const struct xkb_key *key,
}
/**
* Returns the group to use for the given key and state, taking
* wrapping/clamping/etc into account, or XKB_GROUP_INVALID.
* Returns the layout to use for the given key and state, taking
* wrapping/clamping/etc into account, or XKB_LAYOUT_INVALID.
*/
xkb_group_index_t
xkb_key_get_group(struct xkb_state *state, const struct xkb_key *key)
XKB_EXPORT xkb_layout_index_t
xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t kc)
{
xkb_group_index_t ret = xkb_state_serialize_group(state,
XKB_STATE_EFFECTIVE);
struct xkb_keymap *keymap = xkb_state_get_keymap(state);
const struct xkb_key *key = XkbKey(keymap, kc);
xkb_layout_index_t ret =
xkb_state_serialize_layout(state, XKB_STATE_EFFECTIVE);
if (key->num_groups == 0)
return XKB_GROUP_INVALID;
return XKB_LAYOUT_INVALID;
if (ret < key->num_groups)
return ret;
@ -349,26 +367,28 @@ xkb_key_get_group(struct xkb_state *state, const struct xkb_key *key)
}
/**
* As below, but takes an explicit group/level rather than state.
* As below, but takes an explicit layout/level rather than state.
*/
int
xkb_key_get_syms_by_level(struct xkb_keymap *keymap,
const struct xkb_key *key,
xkb_group_index_t group, xkb_level_index_t level,
const xkb_keysym_t **syms_out)
XKB_EXPORT int
xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
xkb_keycode_t kc,
xkb_layout_index_t layout,
xkb_level_index_t level,
const xkb_keysym_t **syms_out)
{
const struct xkb_key *key = XkbKey(keymap, kc);
int num_syms;
if (group >= key->num_groups)
if (layout >= key->num_groups)
goto err;
if (level >= XkbKeyGroupWidth(keymap, key, group))
if (level >= XkbKeyGroupWidth(keymap, key, layout))
goto err;
num_syms = XkbKeyNumSyms(key, group, level);
num_syms = XkbKeyNumSyms(key, layout, level);
if (num_syms == 0)
goto err;
*syms_out = XkbKeySymEntry(key, group, level);
*syms_out = XkbKeySymEntry(key, layout, level);
return num_syms;
err:
@ -385,21 +405,22 @@ xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t kc,
const xkb_keysym_t **syms_out)
{
struct xkb_keymap *keymap = xkb_state_get_map(state);
xkb_group_index_t group;
xkb_layout_index_t layout;
xkb_level_index_t level;
const struct xkb_key *key = XkbKey(keymap, kc);
if (!key)
return -1;
group = xkb_key_get_group(state, key);
if (group == XKB_GROUP_INVALID)
layout = xkb_state_key_get_layout(state, kc);
if (layout == XKB_LAYOUT_INVALID)
goto err;
level = xkb_key_get_level(state, key, group);
level = xkb_state_key_get_level(state, kc, layout);
if (level == XKB_LEVEL_INVALID)
goto err;
return xkb_key_get_syms_by_level(keymap, key, group, level, syms_out);
return xkb_keymap_key_get_syms_by_level(keymap, kc, layout, level,
syms_out);
err:
*syms_out = NULL;
@ -425,7 +446,7 @@ key_get_consumed(struct xkb_state *state, const struct xkb_key *key)
struct xkb_kt_map_entry *entry;
xkb_group_index_t group;
group = xkb_key_get_group(state, key);
group = xkb_state_key_get_layout(state, key->keycode);
if (group == XKB_GROUP_INVALID)
return 0;

View File

@ -85,10 +85,6 @@
#include "utils.h"
#include "context.h"
typedef uint32_t xkb_level_index_t;
#define XKB_LEVEL_INVALID 0xffffffff
#define XKB_KEY_NAME_LENGTH 4
/* These should all be dynamic. */
@ -308,6 +304,7 @@ enum xkb_explicit_components {
};
struct xkb_key {
xkb_keycode_t keycode;
char name[XKB_KEY_NAME_LENGTH];
enum xkb_explicit_components explicit;
@ -430,17 +427,4 @@ XkbKeyActionEntry(const struct xkb_key *key, xkb_layout_index_t layout,
struct xkb_keymap *
xkb_map_new(struct xkb_context *ctx);
xkb_layout_index_t
xkb_key_get_group(struct xkb_state *state, const struct xkb_key *key);
xkb_level_index_t
xkb_key_get_level(struct xkb_state *state, const struct xkb_key *key,
xkb_layout_index_t layout);
int
xkb_key_get_syms_by_level(struct xkb_keymap *keymap,
const struct xkb_key *key,
xkb_layout_index_t layout, xkb_level_index_t level,
const xkb_keysym_t **syms_out);
#endif

View File

@ -109,21 +109,21 @@ static const union xkb_action fake = { .type = ACTION_TYPE_NONE };
static const union xkb_action *
xkb_key_get_action(struct xkb_state *state, const struct xkb_key *key)
{
xkb_group_index_t group;
xkb_layout_index_t layout;
xkb_level_index_t level;
if (!key->actions)
return &fake;
group = xkb_key_get_group(state, key);
if (group == XKB_GROUP_INVALID)
layout = xkb_state_key_get_layout(state, key->keycode);
if (layout == XKB_LAYOUT_INVALID)
return &fake;
level = xkb_key_get_level(state, key, group);
level = xkb_state_key_get_level(state, key->keycode, layout);
if (level == XKB_LEVEL_INVALID)
return &fake;
return XkbKeyActionEntry(key, group, level);
return XkbKeyActionEntry(key, layout, level);
}
static struct xkb_filter *

View File

@ -696,9 +696,12 @@ CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
keymap->max_key_code = info->max_key_code;
darray_resize0(keymap->keys, keymap->max_key_code + 1);
for (kc = info->min_key_code; kc <= info->max_key_code; kc++)
for (kc = info->min_key_code; kc <= info->max_key_code; kc++) {
struct xkb_key *key = &darray_item(keymap->keys, kc);
key->keycode = kc;
LongToKeyName(darray_item(info->key_names, kc).name,
darray_item(keymap->keys, kc).name);
key->name);
}
keymap->keycodes_section_name = strdup_safe(info->name);

View File

@ -75,7 +75,8 @@ FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
const xkb_keysym_t *syms;
int num_syms;
num_syms = xkb_key_get_syms_by_level(keymap, key, group, level, &syms);
num_syms = xkb_keymap_key_get_syms_by_level(keymap, key->keycode, group,
level, &syms);
if (num_syms == 0)
return NULL;

View File

@ -93,12 +93,14 @@ typedef uint32_t xkb_mod_index_t;
typedef uint32_t xkb_mod_mask_t;
typedef uint32_t xkb_layout_index_t;
typedef uint32_t xkb_layout_mask_t;
typedef uint32_t xkb_level_index_t;
typedef uint32_t xkb_led_index_t;
typedef uint32_t xkb_led_mask_t;
#define XKB_MOD_INVALID (0xffffffff)
#define XKB_LAYOUT_INVALID (0xffffffff)
#define XKB_KEYCODE_INVALID (0xffffffff)
#define XKB_LEVEL_INVALID (0xffffffff)
#define XKB_LED_INVALID (0xffffffff)
#define XKB_KEYCODE_MAX (0xffffffff - 1)
@ -453,6 +455,13 @@ xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);
xkb_layout_index_t
xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
/**
* Returns the number of levels active for the specified key and layout.
*/
xkb_level_index_t
xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
xkb_layout_index_t layout);
/**
* Returns 1 if the key should repeat, or 0 otherwise.
*/
@ -538,6 +547,36 @@ int
xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
const xkb_keysym_t **syms_out);
/**
* Returns the layout number that would be active for a particular key with
* the given state.
*/
xkb_layout_index_t
xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
/**
* Returns the level number that would be active for a particular key with
* the given state and layout number, usually obtained from
* xkb_state_key_get_layout.
*/
xkb_level_index_t
xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
xkb_layout_index_t layout);
/**
* Gives the symbols obtained from pressing a particular key with the given
* layout and level. *syms_out will be set to point to an array of keysyms,
* with the return value being the number of symbols in *syms_out. If the
* return value is 0, *syms_out will be set to NULL, as there are no symbols
* produced by this event.
*/
int
xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
xkb_keycode_t key,
xkb_layout_index_t layout,
xkb_level_index_t level,
const xkb_keysym_t **syms_out);
/**
* Modifier and group types for state objects. This enum is bitmaskable,
* e.g. (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED) is valid to exclude