From 9f5139b5eaf5e29c28161b8e0df1adf2d247036b Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 27 Feb 2016 19:43:07 +0200 Subject: [PATCH] state: factor out entry_is_active() check Makes the code slightly cleaner and I plan to use the function in another place. Signed-off-by: Ran Benita --- src/state.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/state.c b/src/state.c index 83ff872..67fceb4 100644 --- a/src/state.c +++ b/src/state.c @@ -116,6 +116,17 @@ struct xkb_state { struct xkb_keymap *keymap; }; +/* + * If the virtual modifiers are not bound to anything, the entry + * is not active and should be skipped. xserver does this with + * cached entry->active field. + */ +static bool +entry_is_active(const struct xkb_key_type_entry *entry) +{ + return entry->mods.mods == 0 || entry->mods.mask != 0; +} + static const struct xkb_key_type_entry * get_entry_for_key_state(struct xkb_state *state, const struct xkb_key *key, xkb_layout_index_t group) @@ -123,18 +134,10 @@ get_entry_for_key_state(struct xkb_state *state, const struct xkb_key *key, const struct xkb_key_type *type = key->groups[group].type; xkb_mod_mask_t active_mods = state->components.mods & type->mods.mask; - for (unsigned i = 0; i < type->num_entries; i++) { - /* - * If the virtual modifiers are not bound to anything, we're - * supposed to skip the entry (xserver does this with cached - * entry->active field). - */ - if (type->entries[i].mods.mods != 0 && type->entries[i].mods.mask == 0) - continue; - - if (type->entries[i].mods.mask == active_mods) + for (unsigned i = 0; i < type->num_entries; i++) + if (entry_is_active(&type->entries[i]) && + type->entries[i].mods.mask == active_mods) return &type->entries[i]; - } return NULL; } -- 2.7.4