xkbcomp/keymap: use default interpret in ApplyInterpsToKey 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>
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
diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index e8db5fd..611d313 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -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)) {