Fix virtual modifiers mask extraction The calculations were performed incorrectly in several places, specifically shifting by 16 instead of 8 (= XkbNumModifiers) and masking with 0xff instead of 0xffff. More stuff that probably never worked as intended. This also makes these more grep-able when we remove the vmods/real_mods separation. 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index e5632f3..22252b9 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -310,7 +310,7 @@ HandleSetLatchMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1;
act->real_mods = act->mask = (t2 & 0xff);
- act->vmods = (t2 >> 8) & 0xffff;
+ act->vmods = (t2 >> XkbNumModifiers) & 0xffff;
return true;
}
return false;
@@ -335,7 +335,7 @@ HandleLockMods(struct xkb_keymap *keymap, struct xkb_any_action *action,
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1;
act->real_mods = act->mask = (t2 & 0xff);
- act->vmods = (t2 >> 8) & 0xffff;
+ act->vmods = (t2 >> XkbNumModifiers) & 0xffff;
return true;
}
return false;
@@ -659,7 +659,7 @@ HandleISOLock(struct xkb_keymap *keymap, struct xkb_any_action *action,
act->flags = flags & (~XkbSA_ISODfltIsGroup);
act->real_mods = mods & 0xff;
- act->vmods = (mods >> 8) & 0xff;
+ act->vmods = (mods >> XkbNumModifiers) & 0xffff;
return true;
}
else if (field == F_Group) {
@@ -937,7 +937,7 @@ HandleRedirectKey(struct xkb_keymap *keymap, struct xkb_any_action *action,
else
act->mods &= ~(t2 & 0xff);
- t2 = (t2 >> 8) & 0xffff;
+ t2 = (t2 >> XkbNumModifiers) & 0xffff;
act->vmods_mask |= t2;
if (field == F_Modifiers)
act->vmods |= t2;
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 2761221..064a7fe 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -767,7 +767,7 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
return ReportIndicatorBadType(info, led, field, "modifier mask");
led->real_mods = mask & 0xff;
- led->vmods = (mask >> 8) & 0xff;
+ led->vmods = (mask >> XkbNumModifiers) & 0xffff;
led->defined |= LED_FIELD_MODS;
}
else if (istreq(field, "groups")) {
@@ -998,7 +998,7 @@ HandleGroupCompatDef(CompatInfo *info, GroupCompatDef *def,
}
tmp.real_mods = mask & 0xff;
- tmp.vmods = (mask >> 8) & 0xffff;
+ tmp.vmods = (mask >> XkbNumModifiers) & 0xffff;
tmp.defined = true;
return AddGroupCompat(info, def->group - 1, &tmp);
}
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 1eeae5a..f25a1f5 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -466,7 +466,7 @@ SetModifiers(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
}
mods = mask & 0xff; /* core mods */
- vmods = (mask >> 8) & 0xffff; /* xkb virtual mods */
+ vmods = (mask >> XkbNumModifiers) & 0xffff; /* xkb virtual mods */
if (type->defined & TYPE_FIELD_MASK) {
log_warn(info->keymap->ctx,
@@ -644,8 +644,8 @@ SetMapEntry(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
if (!ExprResolveVModMask(info->keymap, arrayNdx, &mask))
return ReportTypeBadType(info, type, "map entry", "modifier mask");
- entry.mods.real_mods = mask & 0xff; /* modifiers < 512 */
- entry.mods.vmods = (mask >> 8) & 0xffff; /* modifiers > 512 */
+ entry.mods.real_mods = mask & 0xff;
+ entry.mods.vmods = (mask >> XkbNumModifiers) & 0xffff;
if ((entry.mods.real_mods & (~type->mask)) ||
(entry.mods.vmods & (~type->vmask))) {
@@ -686,7 +686,7 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
"modifier mask");
new.indexMods = mask & 0xff;
- new.indexVMods = (mask >> 8) & 0xffff;
+ new.indexVMods = (mask >> XkbNumModifiers) & 0xffff;
if ((new.indexMods & (~type->mask)) ||
(new.indexVMods & (~type->vmask))) {
@@ -711,7 +711,7 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
}
new.preMods = mask & 0xff;
- new.preVMods = (mask >> 16) & 0xffff;
+ new.preVMods = (mask >> XkbNumModifiers) & 0xffff;
if ((new.preMods & (~new.indexMods)) ||
(new.preVMods & (~new.indexVMods))) {
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index ea4fb11..62c9fd5 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -81,7 +81,7 @@ typedef struct _KeyInfo {
xkb_atom_t types[XkbNumKbdGroups];
enum key_repeat repeat;
- unsigned short vmodmap;
+ xkb_mod_mask_t vmodmap;
xkb_atom_t dfltType;
uint8_t out_of_range_group_action;
@@ -1040,7 +1040,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
ok = ExprResolveVModMask(info->keymap, value, &mask);
if (ok) {
- keyi->vmodmap = (mask >> 8);
+ keyi->vmodmap = (mask >> XkbNumModifiers) & 0xffff;
keyi->defined |= KEY_FIELD_VMODMAP;
}
else {