xkbcomp/keymap: use default interpret in ApplyInterpsToKey
authorRan Benita <ran234@gmail.com>
Thu, 27 Sep 2012 07:19:12 +0000 (09:19 +0200)
committerRan Benita <ran234@gmail.com>
Thu, 27 Sep 2012 19:12:08 +0000 (21:12 +0200)
This makes the code easier to follow and does more explicitly what the
xkblib spec says:
     If no matching symbol interpretation is found, the server uses a
     default interpretation where:
        sym = 0
        flags = XkbSI_AutoRepeat
        match = XkbSI_AnyOfOrNone
        mods = 0
        virtual_mod = XkbNoModifier
        act = SA_NoAction

If a level doesn't have any keysyms, we don't apply anything to it.

Signed-off-by: Ran Benita <ran234@gmail.com>
src/xkbcomp/keymap.c

index e8db5fd..611d313 100644 (file)
@@ -62,13 +62,22 @@ UpdateActionMods(struct xkb_keymap *keymap, union xkb_action *act,
     }
 }
 
+static const struct xkb_sym_interpret default_interpret = {
+    .sym = XKB_KEY_NoSymbol,
+    .repeat = true,
+    .match = MATCH_ANY_OR_NONE,
+    .mods = 0,
+    .virtual_mod = XKB_MOD_INVALID,
+    .act = { .type = ACTION_TYPE_NONE },
+};
+
 /**
  * Find an interpretation which applies to this particular level, either by
  * finding an exact match for the symbol and modifier combination, or a
  * generic XKB_KEY_NoSymbol match.
  */
-static struct xkb_sym_interpret *
-FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
+static const struct xkb_sym_interpret *
+FindInterpForKey(struct xkb_keymap *keymap, const struct xkb_key *key,
                  xkb_layout_index_t group, xkb_level_index_t level)
 {
     struct xkb_sym_interpret *interp;
@@ -124,7 +133,7 @@ FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
             return interp;
     }
 
-    return NULL;
+    return &default_interpret;
 }
 
 static bool
@@ -132,28 +141,24 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
 {
     xkb_mod_mask_t vmodmask = 0;
     xkb_layout_index_t group;
-    xkb_level_index_t width, level;
+    xkb_level_index_t level;
 
     /* If we've been told not to bind interps to this key, then don't. */
     if (key->explicit & EXPLICIT_INTERP)
         return true;
 
     for (group = 0; group < key->num_groups; group++) {
-        width = XkbKeyGroupWidth(key, group);
-        for (level = 0; level < width; level++) {
-            struct xkb_sym_interpret *interp;
+        for (level = 0; level < XkbKeyGroupWidth(key, group); level++) {
+            const struct xkb_sym_interpret *interp;
 
             interp = FindInterpForKey(keymap, key, group, level);
+            if (!interp)
+                continue;
 
             /* Infer default key behaviours from the base level. */
-            if (group == 0 && level == 0) {
-                if (!(key->explicit & EXPLICIT_REPEAT) &&
-                    (!interp || interp->repeat))
+            if (group == 0 && level == 0)
+                if (!(key->explicit & EXPLICIT_REPEAT) && interp->repeat)
                     key->repeats = true;
-            }
-
-            if (!interp)
-                continue;
 
             if ((group == 0 && level == 0) ||
                 !(interp->match & MATCH_LEVEL_ONE_ONLY)) {