map, state: check for KeycodeInRange only in API functions 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
diff --git a/src/map.c b/src/map.c
index 532d00d..d133ae1 100644
--- a/src/map.c
+++ b/src/map.c
@@ -205,9 +205,10 @@ xkb_map_group_get_index(struct xkb_keymap *keymap, const char *name)
XKB_EXPORT xkb_group_index_t
xkb_key_num_groups(struct xkb_keymap *keymap, xkb_keycode_t kc)
{
- if (XkbKeycodeInRange(keymap, kc))
- return XkbKey(keymap, kc)->num_groups;
- return 0;
+ if (!XkbKeycodeInRange(keymap, kc))
+ return 0;
+
+ return XkbKey(keymap, kc)->num_groups;
}
/**
@@ -290,12 +291,8 @@ xkb_key_get_level(struct xkb_state *state, xkb_keycode_t kc,
{
struct xkb_kt_map_entry *entry;
- if (!XkbKeycodeInRange(xkb_state_get_map(state), kc))
- return XKB_LEVEL_INVALID;
-
- entry = get_entry_for_key_state(state, kc);
-
/* If we don't find an explicit match the default is 0. */
+ entry = get_entry_for_key_state(state, kc);
if (!entry)
return 0;
@@ -310,12 +307,9 @@ xkb_group_index_t
xkb_key_get_group(struct xkb_state *state, xkb_keycode_t kc)
{
struct xkb_keymap *keymap = xkb_state_get_map(state);
+ struct xkb_key *key;
xkb_group_index_t ret = xkb_state_serialize_group(state,
XKB_STATE_EFFECTIVE);
- struct xkb_key *key;
-
- if (!XkbKeycodeInRange(keymap, kc))
- return XKB_GROUP_INVALID;
key = XkbKey(keymap, kc);
if (key->num_groups == 0)
@@ -384,7 +378,7 @@ xkb_key_get_syms(struct xkb_state *state, xkb_keycode_t kc,
xkb_group_index_t group;
xkb_level_index_t level;
- if (!state || !XkbKeycodeInRange(keymap, kc))
+ if (!XkbKeycodeInRange(keymap, kc))
return -1;
key = XkbKey(keymap, kc);
@@ -412,6 +406,7 @@ xkb_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t kc)
{
if (!XkbKeycodeInRange(keymap, kc))
return 0;
+
return XkbKey(keymap, kc)->repeats;
}
diff --git a/src/state.c b/src/state.c
index dbb05be..2532f87 100644
--- a/src/state.c
+++ b/src/state.c
@@ -113,12 +113,11 @@ xkb_key_get_action(struct xkb_state *state, xkb_keycode_t kc)
{
xkb_group_index_t group;
xkb_level_index_t level;
- struct xkb_key *key = NULL;
+ struct xkb_key *key;
- if (XkbKeycodeInRange(state->keymap, kc))
- key = XkbKey(state->keymap, kc);
+ key = XkbKey(state->keymap, kc);
- if (!key || !key->actions)
+ if (!key->actions)
return &fake;
group = xkb_key_get_group(state, kc);
@@ -487,9 +486,6 @@ xkb_state_new(struct xkb_keymap *keymap)
{
struct xkb_state *ret;
- if (!keymap)
- return NULL;
-
ret = calloc(sizeof(*ret), 1);
if (!ret)
return NULL;
@@ -510,9 +506,7 @@ xkb_state_ref(struct xkb_state *state)
XKB_EXPORT void
xkb_state_unref(struct xkb_state *state)
{
- state->refcnt--;
- assert(state->refcnt >= 0);
- if (state->refcnt > 0)
+ if (--state->refcnt > 0)
return;
xkb_map_unref(state->keymap);
@@ -600,6 +594,9 @@ xkb_state_update_key(struct xkb_state *state, xkb_keycode_t kc,
xkb_mod_index_t i;
xkb_mod_mask_t bit;
+ if (!XkbKeycodeInRange(state->keymap, kc))
+ return;
+
state->set_mods = 0;
state->clear_mods = 0;