compat: use xkb_mod_set instead of entire keymap 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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 7555f41..eec69e6 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -89,9 +89,9 @@ typedef struct {
LedInfo default_led;
darray(LedInfo) leds;
ActionsInfo *actions;
+ struct xkb_mod_set mods;
struct xkb_context *ctx;
- struct xkb_keymap *keymap;
} CompatInfo;
static const char *
@@ -105,7 +105,7 @@ siText(SymInterpInfo *si, CompatInfo *info)
snprintf(buf, 128, "%s+%s(%s)",
KeysymText(info->ctx, si->interp.sym),
SIMatchText(si->interp.match),
- ModMaskText(info->ctx, &info->keymap->mods, si->interp.mods));
+ ModMaskText(info->ctx, &info->mods, si->interp.mods));
return buf;
}
@@ -142,13 +142,13 @@ ReportLedNotArray(CompatInfo *info, LedInfo *ledi, const char *field)
}
static void
-InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap,
- ActionsInfo *actions)
+InitCompatInfo(CompatInfo *info, struct xkb_context *ctx,
+ ActionsInfo *actions, const struct xkb_mod_set *mods)
{
memset(info, 0, sizeof(*info));
- info->ctx = keymap->ctx;
- info->keymap = keymap;
+ info->ctx = ctx;
info->actions = actions;
+ CopyModSet(&info->mods, mods);
info->default_interp.merge = MERGE_OVERRIDE;
info->default_interp.interp.virtual_mod = XKB_MOD_INVALID;
info->default_led.merge = MERGE_OVERRIDE;
@@ -158,6 +158,7 @@ static void
ClearCompatInfo(CompatInfo *info)
{
free(info->name);
+ ClearModSet(&info->mods);
darray_free(info->interps);
darray_free(info->leds);
}
@@ -280,7 +281,7 @@ ResolveStateAndPredicate(ExprDef *expr, enum xkb_match_operation *pred_rtrn,
}
}
- return ExprResolveModMask(info->ctx, expr, MOD_REAL, &info->keymap->mods,
+ return ExprResolveModMask(info->ctx, expr, MOD_REAL, &info->mods,
mods_rtrn);
}
@@ -378,6 +379,8 @@ MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
return;
}
+ MoveModSet(&into->mods, &from->mods);
+
if (into->name == NULL) {
into->name = from->name;
from->name = NULL;
@@ -416,7 +419,7 @@ HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *include)
{
CompatInfo included;
- InitCompatInfo(&included, info->keymap, info->actions);
+ InitCompatInfo(&included, info->ctx, info->actions, &info->mods);
included.name = include->stmt;
include->stmt = NULL;
@@ -431,7 +434,7 @@ HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *include)
return false;
}
- InitCompatInfo(&next_incl, info->keymap, info->actions);
+ InitCompatInfo(&next_incl, info->ctx, info->actions, &included.mods);
next_incl.default_interp = info->default_interp;
next_incl.default_interp.merge = stmt->merge;
next_incl.default_led = info->default_led;
@@ -461,7 +464,7 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
if (arrayNdx)
return ReportSINotArray(info, si, field);
- if (!HandleActionDef(info->ctx, info->actions, &info->keymap->mods,
+ if (!HandleActionDef(info->ctx, info->actions, &info->mods,
value, &si->interp.action))
return false;
@@ -472,8 +475,7 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
if (arrayNdx)
return ReportSINotArray(info, si, field);
- if (!ExprResolveMod(info->ctx, value, MOD_VIRT, &info->keymap->mods,
- &ndx))
+ if (!ExprResolveMod(info->ctx, value, MOD_VIRT, &info->mods, &ndx))
return ReportSIBadType(info, si, field, "virtual modifier");
si->interp.virtual_mod = ndx;
@@ -529,7 +531,7 @@ SetLedMapField(CompatInfo *info, LedInfo *ledi, const char *field,
return ReportLedNotArray(info, ledi, field);
if (!ExprResolveModMask(info->ctx, value, MOD_BOTH,
- &info->keymap->mods, &ledi->led.mods.mods))
+ &info->mods, &ledi->led.mods.mods))
return ReportLedBadType(info, ledi, field, "modifier mask");
ledi->defined |= LED_FIELD_MODS;
@@ -633,7 +635,7 @@ HandleGlobalVar(CompatInfo *info, VarDef *stmt)
ret = SetLedMapField(info, &info->default_led, field, ndx,
stmt->value);
else
- ret = SetActionField(info->ctx, info->actions, &info->keymap->mods,
+ ret = SetActionField(info->ctx, info->actions, &info->mods,
elem, field, ndx, stmt->value);
return ret;
}
@@ -768,8 +770,7 @@ HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
ok = HandleGlobalVar(info, (VarDef *) stmt);
break;
case STMT_VMOD:
- ok = HandleVModDef(info->ctx, &info->keymap->mods,
- (VModDef *) stmt, merge);
+ ok = HandleVModDef(info->ctx, &info->mods, (VModDef *) stmt, merge);
break;
default:
log_err(info->ctx,
@@ -808,12 +809,11 @@ CopyInterps(CompatInfo *info, bool needSymbol, enum xkb_match_operation pred,
}
static void
-CopyLedMapDefs(CompatInfo *info)
+CopyLedMapDefsToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
{
LedInfo *ledi;
xkb_led_index_t i;
struct xkb_led *led;
- struct xkb_keymap *keymap = info->keymap;
darray_foreach(ledi, info->leds) {
/*
@@ -865,6 +865,8 @@ CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
keymap->compat_section_name = strdup_safe(info->name);
XkbEscapeMapName(keymap->compat_section_name);
+ MoveModSet(&keymap->mods, &info->mods);
+
if (!darray_empty(info->interps)) {
struct collect collect;
darray_init(collect.sym_interprets);
@@ -885,7 +887,7 @@ CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
keymap->sym_interprets = darray_mem(collect.sym_interprets, 0);
}
- CopyLedMapDefs(info);
+ CopyLedMapDefsToKeymap(keymap, info);
return true;
}
@@ -901,7 +903,7 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
if (!actions)
return false;
- InitCompatInfo(&info, keymap, actions);
+ InitCompatInfo(&info, keymap->ctx, actions, &keymap->mods);
info.default_interp.merge = merge;
info.default_led.merge = merge;
diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c
index 9273a10..8f4221d 100644
--- a/src/xkbcomp/vmod.c
+++ b/src/xkbcomp/vmod.c
@@ -29,6 +29,27 @@
#include "expr.h"
#include "vmod.h"
+void
+MoveModSet(struct xkb_mod_set *into, struct xkb_mod_set *from)
+{
+ darray_free(into->mods);
+ into->mods = from->mods;
+ darray_init(from->mods);
+}
+
+void
+CopyModSet(struct xkb_mod_set *into, const struct xkb_mod_set *from)
+{
+ darray_free(into->mods);
+ darray_copy(into->mods, from->mods);
+}
+
+void
+ClearModSet(struct xkb_mod_set *mods)
+{
+ darray_free(mods->mods);
+}
+
bool
HandleVModDef(struct xkb_context *ctx, struct xkb_mod_set *mods,
VModDef *stmt, enum merge_mode merge)
diff --git a/src/xkbcomp/vmod.h b/src/xkbcomp/vmod.h
index 546cf7e..39020d5 100644
--- a/src/xkbcomp/vmod.h
+++ b/src/xkbcomp/vmod.h
@@ -27,6 +27,15 @@
#ifndef XKBCOMP_VMOD_H
#define XKBCOMP_VMOD_H
+void
+MoveModSet(struct xkb_mod_set *into, struct xkb_mod_set *from);
+
+void
+CopyModSet(struct xkb_mod_set *into, const struct xkb_mod_set *from);
+
+void
+ClearModSet(struct xkb_mod_set *mods);
+
bool
HandleVModDef(struct xkb_context *ctx, struct xkb_mod_set *mods,
VModDef *stmt, enum merge_mode merge);