summaryrefslogtreecommitdiff
path: root/src/xkbcomp/keymap.c
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-10-05 22:07:04 +0200
committerRan Benita <ran234@gmail.com>2012-10-06 21:41:59 +0200
commit1005b320f14339236ff53a07b13d6dcbad52bf19 (patch)
tree57bbf751a4daaca29fbef2faecf1403d471964f9 /src/xkbcomp/keymap.c
parent6974e1f9acc42a946203a48c3a57d8bbb19e3316 (diff)
downloadlibxkbcommon-1005b320f14339236ff53a07b13d6dcbad52bf19.tar.gz
libxkbcommon-1005b320f14339236ff53a07b13d6dcbad52bf19.tar.bz2
libxkbcommon-1005b320f14339236ff53a07b13d6dcbad52bf19.zip
Don't use shifted virtual modifier masks
Modifier masks can be confusing in some places. For example, key->vmodmap only contains virtual modifiers, where the first is in position 0, the second in 1 etc., while normally in a xkb_mod_mask_t the virtual modifiers start from the 8th (XKB_NUM_CORE_MODS) position. This happens in some other places as well. Change all of the masks to be in the usual real+virtual format, and when we need to access e.g. keymap->vmods we just adjust by XKB_NUM_CORE_MODS. (This also goes for indexes, e.g. interpret->virtual_modifier). This makes this stuff easier to reason about. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/xkbcomp/keymap.c')
-rw-r--r--src/xkbcomp/keymap.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index b9cfc17..52198d1 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -34,13 +34,12 @@ ComputeEffectiveMask(struct xkb_keymap *keymap, struct xkb_mods *mods)
{
const struct xkb_vmod *vmod;
xkb_mod_index_t i;
- xkb_mod_mask_t vmask = mods->mods >> XKB_NUM_CORE_MODS;
/* The effective mask is only real mods for now. */
mods->mask = mods->mods & 0xff;
darray_enumerate(i, vmod, keymap->vmods)
- if (vmask & (1 << i))
+ if (mods->mods & (1 << (i + XKB_NUM_CORE_MODS)))
mods->mask |= vmod->mapping;
}
@@ -138,7 +137,7 @@ FindInterpForKey(struct xkb_keymap *keymap, const struct xkb_key *key,
static bool
ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
{
- xkb_mod_mask_t vmodmask = 0;
+ xkb_mod_mask_t vmodmap = 0;
xkb_layout_index_t group;
xkb_level_index_t level;
@@ -162,7 +161,7 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
if ((group == 0 && level == 0) ||
!(interp->match & MATCH_LEVEL_ONE_ONLY)) {
if (interp->virtual_mod != XKB_MOD_INVALID)
- vmodmask |= (1 << interp->virtual_mod);
+ vmodmap |= (1 << interp->virtual_mod);
}
if (interp->act.type != ACTION_TYPE_NONE)
@@ -171,7 +170,7 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
}
if (!(key->explicit & EXPLICIT_VMODMAP))
- key->vmodmap = vmodmask;
+ key->vmodmap = vmodmap;
return true;
}
@@ -199,7 +198,7 @@ UpdateDerivedKeymapFields(struct xkb_keymap *keymap)
/* Update keymap->vmods, the virtual -> real mod mapping. */
xkb_foreach_key(key, keymap)
darray_enumerate(i, vmod, keymap->vmods)
- if (key->vmodmap & (1 << i))
+ if (key->vmodmap & (1 << (XKB_NUM_CORE_MODS + i)))
vmod->mapping |= key->modmap;
/* Now update the level masks for all the types to reflect the vmods. */