Commit 9f5139b5eaf5e29c28161b8e0df1adf2d247036b

Ran Benita 2016-02-27T19:43:07

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 <ran234@gmail.com>

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;
 }