vmod: take xkb_mod_set instead of the entire keymap This is the only place where the modifier information is modified. We will make it local to a given XKB file (after which it will be merged into the keymap). Currently it changes the keymap directly, which sidesteps the abstraction and leaves side-effects even if the XkbFile's compilation fails. 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 127 128 129 130 131 132 133 134 135 136 137 138 139
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 772e3f3..7555f41 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -768,7 +768,8 @@ HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
ok = HandleGlobalVar(info, (VarDef *) stmt);
break;
case STMT_VMOD:
- ok = HandleVModDef(info->keymap, (VModDef *) stmt, merge);
+ ok = HandleVModDef(info->ctx, &info->keymap->mods,
+ (VModDef *) stmt, merge);
break;
default:
log_err(info->ctx,
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 310fc0c..f259c74 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -1199,7 +1199,8 @@ HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
ok = HandleGlobalVar(info, (VarDef *) stmt);
break;
case STMT_VMOD:
- ok = HandleVModDef(info->keymap, (VModDef *) stmt, merge);
+ ok = HandleVModDef(info->ctx, &info->keymap->mods,
+ (VModDef *) stmt, merge);
break;
case STMT_MODMAP:
ok = HandleModMapDef(info, (ModMapDef *) stmt);
diff --git a/src/xkbcomp/types.c b/src/xkbcomp/types.c
index d022999..521a3d6 100644
--- a/src/xkbcomp/types.c
+++ b/src/xkbcomp/types.c
@@ -645,7 +645,8 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
ok = true;
break;
case STMT_VMOD:
- ok = HandleVModDef(info->keymap, (VModDef *) stmt, merge);
+ ok = HandleVModDef(info->ctx, &info->keymap->mods,
+ (VModDef *) stmt, merge);
break;
default:
log_err(info->ctx,
diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c
index 363752e..9273a10 100644
--- a/src/xkbcomp/vmod.c
+++ b/src/xkbcomp/vmod.c
@@ -30,8 +30,8 @@
#include "vmod.h"
bool
-HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt,
- enum merge_mode merge)
+HandleVModDef(struct xkb_context *ctx, struct xkb_mod_set *mods,
+ VModDef *stmt, enum merge_mode merge)
{
xkb_mod_index_t i;
struct xkb_mod *mod;
@@ -46,11 +46,10 @@ HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt,
* it sets the vmod-to-real-mod[s] mapping directly instead of going
* through modifier_map or some such.
*/
- if (!ExprResolveModMask(keymap->ctx, stmt->value, MOD_REAL,
- &keymap->mods, &mapping)) {
- log_err(keymap->ctx,
+ if (!ExprResolveModMask(ctx, stmt->value, MOD_REAL, mods, &mapping)) {
+ log_err(ctx,
"Declaration of %s ignored\n",
- xkb_atom_text(keymap->ctx, stmt->name));
+ xkb_atom_text(ctx, stmt->name));
return false;
}
}
@@ -58,13 +57,13 @@ HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt,
mapping = 0;
}
- darray_enumerate(i, mod, keymap->mods.mods) {
+ darray_enumerate(i, mod, mods->mods) {
if (mod->name == stmt->name) {
if (mod->type != MOD_VIRT) {
- log_err(keymap->ctx,
+ log_err(ctx,
"Can't add a virtual modifier named \"%s\"; "
"there is already a non-virtual modifier with this name! Ignored\n",
- xkb_atom_text(keymap->ctx, mod->name));
+ xkb_atom_text(ctx, mod->name));
return false;
}
@@ -77,12 +76,12 @@ HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt,
use = (merge == MERGE_OVERRIDE ? mapping : mod->mapping);
ignore = (merge == MERGE_OVERRIDE ? mod->mapping : mapping);
- log_warn(keymap->ctx,
+ log_warn(ctx,
"Virtual modifier %s defined multiple times; "
"Using %s, ignoring %s\n",
- xkb_atom_text(keymap->ctx, stmt->name),
- ModMaskText(keymap->ctx, &keymap->mods, use),
- ModMaskText(keymap->ctx, &keymap->mods, ignore));
+ xkb_atom_text(ctx, stmt->name),
+ ModMaskText(ctx, mods, use),
+ ModMaskText(ctx, mods, ignore));
mapping = use;
}
@@ -92,8 +91,8 @@ HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt,
}
}
- if (darray_size(keymap->mods.mods) >= XKB_MAX_MODS) {
- log_err(keymap->ctx,
+ if (darray_size(mods->mods) >= XKB_MAX_MODS) {
+ log_err(ctx,
"Too many modifiers defined (maximum %d)\n",
XKB_MAX_MODS);
return false;
@@ -102,6 +101,6 @@ HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt,
new.name = stmt->name;
new.mapping = mapping;
new.type = MOD_VIRT;
- darray_append(keymap->mods.mods, new);
+ darray_append(mods->mods, new);
return true;
}
diff --git a/src/xkbcomp/vmod.h b/src/xkbcomp/vmod.h
index 1ba59f7..546cf7e 100644
--- a/src/xkbcomp/vmod.h
+++ b/src/xkbcomp/vmod.h
@@ -28,7 +28,7 @@
#define XKBCOMP_VMOD_H
bool
-HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt,
- enum merge_mode merge);
+HandleVModDef(struct xkb_context *ctx, struct xkb_mod_set *mods,
+ VModDef *stmt, enum merge_mode merge);
#endif