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 <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
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. */