From 75853ed66b87ceeac7067818cb8559ecb40bb9b0 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 10 Aug 2012 10:11:49 +0300 Subject: [PATCH] Use XKB_{GROUP,LEVEL}_INVALID instead of -1 for errors The group/level types are unsigned, so it's odd to return -1 for them. Instead use their invalid values (which happen to be == -1). Signed-off-by: Ran Benita --- src/map.c | 27 +++++++++++++++++++-------- src/state.c | 5 +++++ src/xkb-priv.h | 3 ++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/map.c b/src/map.c index 4a7ce31..fdb51c9 100644 --- a/src/map.c +++ b/src/map.c @@ -211,7 +211,8 @@ xkb_map_led_get_index(struct xkb_keymap *keymap, const char *name) } /** - * Returns the level to use for the given key and state, or -1 if invalid. + * Returns the level to use for the given key and state, or + * XKB_LEVEL_INVALID. */ xkb_level_index_t xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc, @@ -223,7 +224,7 @@ xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc, xkb_mod_mask_t active_mods; if (!XkbKeycodeInRange(keymap, kc)) - return 0; + return XKB_LEVEL_INVALID; type = XkbKeyType(keymap, XkbKey(keymap, kc), group); active_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE); @@ -233,12 +234,13 @@ xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc, if (type->map[i].mods.mask == active_mods) return type->map[i].level; + /* If we don't find an explicit match the default is 0. */ return 0; } /** * Returns the group to use for the given key and state, taking - * wrapping/clamping/etc into account. + * wrapping/clamping/etc into account, or XKB_GROUP_INVALID. */ xkb_group_index_t xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc) @@ -249,8 +251,11 @@ xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc) struct xkb_key *key; if (!XkbKeycodeInRange(keymap, kc)) - return 0; + return XKB_GROUP_INVALID; + key = XkbKey(keymap, kc); + if (key->num_groups == 0) + return XKB_GROUP_INVALID; if (ret < key->num_groups) return ret; @@ -321,11 +326,11 @@ xkb_key_get_syms(struct xkb_state *state, xkb_keycode_t kc, key = XkbKey(keymap, kc); group = xkb_key_get_group(state, kc); - if (group == -1) + if (group == XKB_GROUP_INVALID) goto err; level = xkb_key_get_level(state, kc, group); - if (level == -1) + if (level == XKB_LEVEL_INVALID) goto err; return xkb_key_get_syms_by_level(keymap, key, group, level, syms_out); @@ -389,6 +394,9 @@ xkb_key_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t kc, return 0; group = xkb_key_get_group(state, kc); + if (group == XKB_GROUP_INVALID) + return 0; + type = XkbKeyType(keymap, XkbKey(keymap, kc), group); entry = get_entry_for_key_state(state, type, kc); if (!entry) @@ -415,13 +423,16 @@ xkb_key_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t kc, xkb_group_index_t group; if (!XkbKeycodeInRange(keymap, kc)) - return 0; + return mask; group = xkb_key_get_group(state, kc); + if (group == XKB_GROUP_INVALID) + return mask; + type = XkbKeyType(keymap, XkbKey(keymap, kc), group); entry = get_entry_for_key_state(state, type, kc); if (!entry) - return 0; + return mask; return mask & ~(type->mods.mask & ~entry->preserve.mask); } diff --git a/src/state.c b/src/state.c index 4006872..758bbf7 100644 --- a/src/state.c +++ b/src/state.c @@ -122,7 +122,12 @@ xkb_key_get_action(struct xkb_state *state, xkb_keycode_t kc) return &fake; group = xkb_key_get_group(state, kc); + if (group == XKB_GROUP_INVALID) + return &fake; + level = xkb_key_get_level(state, kc, group); + if (level == XKB_LEVEL_INVALID) + return &fake; return XkbKeyActionEntry(state->keymap, key, group, level); } diff --git a/src/xkb-priv.h b/src/xkb-priv.h index 8a217eb..e38703d 100644 --- a/src/xkb-priv.h +++ b/src/xkb-priv.h @@ -89,10 +89,11 @@ #include "darray.h" #include "list.h" -typedef uint16_t xkb_level_index_t; +typedef uint32_t xkb_level_index_t; typedef uint32_t xkb_atom_t; #define XKB_ATOM_NONE 0 +#define XKB_LEVEL_INVALID 0xffffffff enum xkb_file_type { /* The top level file which includes the other component files. */