diff options
author | Ran Benita <ran234@gmail.com> | 2012-10-05 22:46:21 +0200 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2012-10-06 21:41:59 +0200 |
commit | 424de613af4c0a8121213bbee8c4fdd8364612e5 (patch) | |
tree | 60ccce13d87c24cf7bd1411bf1889bed0830472a /src | |
parent | 1005b320f14339236ff53a07b13d6dcbad52bf19 (diff) | |
download | libxkbcommon-424de613af4c0a8121213bbee8c4fdd8364612e5.tar.gz libxkbcommon-424de613af4c0a8121213bbee8c4fdd8364612e5.tar.bz2 libxkbcommon-424de613af4c0a8121213bbee8c4fdd8364612e5.zip |
Keep real and virtual mods in the same table in the keymap
We change the keymap->vmods array into keymap->mods, and change it's
member type from struct xkb_vmod to struct xkb_mod. This table now
includes the real modifiers in the first 8 places. To distinguish
between them, we add an enum mod_type to struct xkb_mod.
Besides being a more reasonable approach, this enables us to share
some code later, remove XKB_NUM_CORE_MODS (though the 0xff mask still
appears in a few places), and prepares us to flat out remove the
distinction in the future. This commit just does the conversion.
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/keymap-dump.c | 22 | ||||
-rw-r--r-- | src/keymap.c | 32 | ||||
-rw-r--r-- | src/keymap.h | 17 | ||||
-rw-r--r-- | src/text.c | 94 | ||||
-rw-r--r-- | src/text.h | 12 | ||||
-rw-r--r-- | src/xkbcomp/compat.c | 4 | ||||
-rw-r--r-- | src/xkbcomp/expr.c | 40 | ||||
-rw-r--r-- | src/xkbcomp/expr.h | 2 | ||||
-rw-r--r-- | src/xkbcomp/keymap.c | 45 | ||||
-rw-r--r-- | src/xkbcomp/symbols.c | 18 | ||||
-rw-r--r-- | src/xkbcomp/vmod.c | 36 |
11 files changed, 166 insertions, 156 deletions
diff --git a/src/keymap-dump.c b/src/keymap-dump.c index 38b8c95..261562a 100644 --- a/src/keymap-dump.c +++ b/src/keymap-dump.c @@ -127,15 +127,18 @@ err: static bool write_vmods(struct xkb_keymap *keymap, struct buf *buf) { - const struct xkb_vmod *vmod; + const struct xkb_mod *mod; xkb_mod_index_t num_vmods = 0; - darray_foreach(vmod, keymap->vmods) { + darray_foreach(mod, keymap->mods) { + if (mod->type != MOD_VIRT) + continue; + if (num_vmods == 0) write_buf(buf, "\t\tvirtual_modifiers "); else write_buf(buf, ","); - write_buf(buf, "%s", xkb_atom_text(keymap->ctx, vmod->name)); + write_buf(buf, "%s", xkb_atom_text(keymap->ctx, mod->name)); num_vmods++; } @@ -523,10 +526,10 @@ write_compat(struct xkb_keymap *keymap, struct buf *buf) VModMaskText(keymap, interp->mods)); if (interp->virtual_mod != XKB_MOD_INVALID) { - xkb_mod_index_t idx = interp->virtual_mod - XKB_NUM_CORE_MODS; + xkb_mod_index_t idx = interp->virtual_mod; write_buf(buf, "\t\t\tvirtualModifier= %s;\n", xkb_atom_text(keymap->ctx, - darray_item(keymap->vmods, idx).name)); + darray_item(keymap->mods, idx).name)); } if (interp->match & MATCH_LEVEL_ONE_ONLY) @@ -724,17 +727,18 @@ write_symbols(struct xkb_keymap *keymap, struct buf *buf) } xkb_foreach_key(key, keymap) { - xkb_mod_index_t mod; + xkb_mod_index_t i; + const struct xkb_mod *mod; if (key->modmap == 0) continue; - for (mod = 0; mod < XKB_NUM_CORE_MODS; mod++) { - if (!(key->modmap & (1 << mod))) + darray_enumerate(i, mod, keymap->mods) { + if (!(key->modmap & (1 << i))) continue; write_buf(buf, "\t\tmodifier_map %s { %s };\n", - ModIndexToName(mod), + xkb_atom_text(keymap->ctx, mod->name), KeyNameText(keymap->ctx, key->name)); } } diff --git a/src/keymap.c b/src/keymap.c index 0471e3a..a54169a 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -107,7 +107,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap) darray_free(keymap->sym_interpret); darray_free(keymap->key_aliases); darray_free(keymap->group_names); - darray_free(keymap->vmods); + darray_free(keymap->mods); free(keymap->keycodes_section_name); free(keymap->symbols_section_name); free(keymap->types_section_name); @@ -122,9 +122,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap) XKB_EXPORT xkb_mod_index_t xkb_keymap_num_mods(struct xkb_keymap *keymap) { - /* We always have all the core modifiers (for now), plus any virtual - * modifiers we may have defined. */ - return XKB_NUM_CORE_MODS + darray_size(keymap->vmods); + return darray_size(keymap->mods); } /** @@ -133,20 +131,10 @@ xkb_keymap_num_mods(struct xkb_keymap *keymap) XKB_EXPORT const char * xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx) { - const char *name; - const struct xkb_vmod *vmod; - - if (idx >= xkb_keymap_num_mods(keymap)) + if (idx >= darray_size(keymap->mods)) return NULL; - /* First try to find a legacy modifier name. If that fails, try to - * find a virtual mod name. */ - name = ModIndexToName(idx); - if (name) - return name; - - vmod = &darray_item(keymap->vmods, idx - XKB_NUM_CORE_MODS); - return xkb_atom_text(keymap->ctx, vmod->name); + return xkb_atom_text(keymap->ctx, darray_item(keymap->mods, idx).name); } /** @@ -157,19 +145,15 @@ xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name) { xkb_mod_index_t i; xkb_atom_t atom; - const struct xkb_vmod *vmod; - - i = ModNameToIndex(name); - if (i != XKB_MOD_INVALID) - return i; + const struct xkb_mod *mod; atom = xkb_atom_lookup(keymap->ctx, name); if (atom == XKB_ATOM_NONE) return XKB_MOD_INVALID; - darray_enumerate(i, vmod, keymap->vmods) - if (vmod->name == atom) - return i + XKB_NUM_CORE_MODS; + darray_enumerate(i, mod, keymap->mods) + if (mod->name == atom) + return i; return XKB_MOD_INVALID; } diff --git a/src/keymap.h b/src/keymap.h index f50b091..0bc6509 100644 --- a/src/keymap.h +++ b/src/keymap.h @@ -103,13 +103,17 @@ */ #define XKB_NUM_GROUPS 4 -/* Don't allow more vmods than we can hold in xkb_mod_mask_t. */ -#define XKB_MAX_VIRTUAL_MODS \ - ((xkb_mod_index_t) (sizeof(xkb_mod_mask_t) * 8 - XKB_NUM_CORE_MODS)) +/* Don't allow more modifiers than we can hold in xkb_mod_mask_t. */ +#define XKB_MAX_MODS ((xkb_mod_index_t) (sizeof(xkb_mod_mask_t) * 8)) /* These should all be dynamic. */ #define XKB_NUM_INDICATORS 32 -#define XKB_NUM_CORE_MODS 8 + +enum mod_type { + MOD_REAL = (1 << 0), + MOD_VIRT = (1 << 1), + MOD_BOTH = (MOD_REAL | MOD_VIRT), +}; enum xkb_action_type { ACTION_TYPE_NONE = 0, @@ -358,8 +362,9 @@ struct xkb_key { typedef darray(xkb_atom_t) darray_xkb_atom_t; -struct xkb_vmod { +struct xkb_mod { xkb_atom_t name; + enum mod_type type; xkb_mod_mask_t mapping; /* vmod -> real mod mapping */ }; @@ -386,7 +391,7 @@ struct xkb_keymap { darray(struct xkb_sym_interpret) sym_interpret; - darray(struct xkb_vmod) vmods; + darray(struct xkb_mod) mods; /* Number of groups in the key with the most groups. */ xkb_layout_index_t num_groups; @@ -233,7 +233,7 @@ GetBuffer(size_t size) /* Get a mod mask's text, where the mask is in rmods+vmods format. */ const char * -VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask) +VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask) { xkb_mod_index_t i; xkb_mod_mask_t rmask, vmask; @@ -241,15 +241,16 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask) const char *mm = NULL; char *rtrn, *str; char buf[BUFFER_SIZE]; + const struct xkb_mod *mod; - rmask = cmask & 0xff; - vmask = cmask & (~0xff); + rmask = mask & 0xff; + vmask = mask & (~0xff); if (rmask == 0 && vmask == 0) return "none"; if (rmask != 0) - mm = ModMaskText(rmask); + mm = ModMaskText(keymap, rmask); if (vmask == 0) return mm; @@ -258,16 +259,18 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask) buf[0] = '\0'; rem = BUFFER_SIZE; - for (i = 0; i < darray_size(keymap->vmods) && rem > 1; i++) { - const char *name; - - if (!(vmask & (1 << (i + XKB_NUM_CORE_MODS)))) + darray_enumerate(i, mod, keymap->mods) { + if (mod->type != MOD_VIRT || !(vmask & (1 << i))) continue; - name = xkb_atom_text(keymap->ctx, darray_item(keymap->vmods, i).name); - len = snprintf(str, rem, "%s%s", (str != buf) ? "+" : "", name); + len = snprintf(str, rem, "%s%s", + (str != buf) ? "+" : "", + xkb_atom_text(keymap->ctx, mod->name)); rem -= len; str += len; + + if (rem <= 1) + break; } str = buf; @@ -286,70 +289,51 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask) return rtrn; } -/* - * IMPORTATNT - * The indices used for the legacy core modifiers is derived from - * the order of the names in this table. It matches the values - * ShiftMapIndex, LockMapIndex, etc. from X11/X.h. Take note before - * changing. - */ -static const char *modNames[XKB_NUM_CORE_MODS] = { - "Shift", - "Lock", - "Control", - "Mod1", - "Mod2", - "Mod3", - "Mod4", - "Mod5", -}; - xkb_mod_index_t -ModNameToIndex(const char *name) +ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name) { xkb_mod_index_t i; + const struct xkb_mod *mod; - for (i = 0; i < XKB_NUM_CORE_MODS; i++) - if (istreq(name, modNames[i])) + darray_enumerate(i, mod, keymap->mods) + if (mod->type == MOD_REAL && name == mod->name) return i; return XKB_MOD_INVALID; } -const char * -ModIndexToName(xkb_mod_index_t ndx) +xkb_atom_t +ModIndexToName(struct xkb_keymap *keymap, xkb_mod_index_t ndx) { - if (ndx < XKB_NUM_CORE_MODS) - return modNames[ndx]; - return NULL; + if (ndx >= darray_size(keymap->mods) || + darray_item(keymap->mods, ndx).type != MOD_REAL) + return XKB_ATOM_NONE; + + return darray_item(keymap->mods, ndx).name; } const char * -ModIndexText(xkb_mod_index_t ndx) +ModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx) { - const char *name; - char *buf; + xkb_atom_t name; - name = ModIndexToName(ndx); + name = ModIndexToName(keymap, ndx); if (name) - return name; + return xkb_atom_text(keymap->ctx, name); if (ndx == XKB_MOD_INVALID) return "none"; - buf = GetBuffer(32); - snprintf(buf, 32, "ILLEGAL_%02x", ndx); - - return buf; + return "illegal"; } -/* Gets the text for the real modifiers only. */ const char * -ModMaskText(xkb_mod_mask_t mask) +ModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask) { - int i, rem; - xkb_mod_index_t bit; + xkb_mod_index_t i; + int len, rem; char *str, *buf; + const struct xkb_mod *mod; if ((mask & 0xff) == 0xff) return "all"; @@ -361,16 +345,18 @@ ModMaskText(xkb_mod_mask_t mask) buf = GetBuffer(rem); str = buf; buf[0] = '\0'; - for (i = 0, bit = 1; i < XKB_NUM_CORE_MODS && rem > 1; i++, bit <<= 1) { - int len; - - if (!(mask & bit)) + darray_enumerate(i, mod, keymap->mods) { + if (mod->type != MOD_REAL || !(mask & (1 << i))) continue; len = snprintf(str, rem, "%s%s", - (str != buf ? "+" : ""), modNames[i]); + (str != buf ? "+" : ""), + ModIndexText(keymap, i)); rem -= len; str += len; + + if (rem <= 1) + break; } return buf; @@ -48,19 +48,19 @@ extern const LookupEntry actionTypeNames[]; extern const LookupEntry symInterpretMatchMaskNames[]; const char * -VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask); +VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask); xkb_mod_index_t -ModNameToIndex(const char *name); +ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name); -const char * -ModIndexToName(xkb_mod_index_t ndx); +xkb_atom_t +ModIndexToName(struct xkb_keymap *keymap, xkb_mod_index_t ndx); const char * -ModIndexText(xkb_mod_index_t ndx); +ModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx); const char * -ModMaskText(xkb_mod_mask_t mask); +ModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask); const char * ActionTypeText(enum xkb_action_type type); diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index 0c94346..5678074 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -210,7 +210,7 @@ siText(SymInterpInfo *si, CompatInfo *info) snprintf(buf, sizeof(buf), "%s+%s(%s)", KeysymText(si->interp.sym), SIMatchText(si->interp.match), - ModMaskText(si->interp.mods)); + ModMaskText(info->keymap, si->interp.mods)); return buf; } @@ -394,7 +394,7 @@ ResolveStateAndPredicate(ExprDef *expr, enum xkb_match_operation *pred_rtrn, } } - return ExprResolveModMask(info->keymap->ctx, expr, mods_rtrn); + return ExprResolveModMask(info->keymap, expr, mods_rtrn); } /***====================================================================***/ diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index d3e167f..f5caa58 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -85,8 +85,8 @@ static bool LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field, enum expr_value_type type, xkb_mod_index_t *val_rtrn) { - const char *name = xkb_atom_text(ctx, field); - *val_rtrn = ModNameToIndex(name); + const struct xkb_keymap *keymap = priv; + *val_rtrn = ModNameToIndex(keymap, field); return (*val_rtrn != XKB_MOD_INVALID); } @@ -96,6 +96,7 @@ LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, { const char *str; xkb_mod_index_t ndx; + const struct xkb_keymap *keymap = priv; if (type != EXPR_TYPE_INT) return false; @@ -106,7 +107,7 @@ LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, *val_rtrn = 0xff; else if (istreq(str, "none")) *val_rtrn = 0; - else if (LookupModIndex(ctx, priv, field, type, &ndx)) + else if (LookupModIndex(ctx, keymap, field, type, &ndx)) *val_rtrn = (1 << ndx); else return false; @@ -618,25 +619,28 @@ ExprResolveMask(struct xkb_context *ctx, const ExprDef *expr, } bool -ExprResolveModMask(struct xkb_context *ctx, const ExprDef *expr, +ExprResolveModMask(struct xkb_keymap *keymap, const ExprDef *expr, xkb_mod_mask_t *mask_rtrn) { - return ExprResolveMaskLookup(ctx, expr, mask_rtrn, LookupModMask, NULL); + return ExprResolveMaskLookup(keymap->ctx, expr, mask_rtrn, LookupModMask, + keymap); } static bool -LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field, - enum expr_value_type type, xkb_mod_index_t *val_rtrn) +LookupVModIndex(struct xkb_context *ctx, const void *priv, + xkb_atom_t field, enum expr_value_type type, + xkb_mod_index_t *val_rtrn) { - const struct xkb_vmod *vmod; + const struct xkb_mod *mod; xkb_mod_index_t i; + const struct xkb_keymap *keymap = priv; if (type != EXPR_TYPE_INT) return false; - darray_enumerate(i, vmod, keymap->vmods) { - if (vmod->name == field) { - *val_rtrn = XKB_NUM_CORE_MODS + i; + darray_enumerate(i, mod, keymap->mods) { + if (mod->type == MOD_VIRT && mod->name == field) { + *val_rtrn = i; return true; } } @@ -649,11 +653,12 @@ LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, enum expr_value_type type, xkb_mod_mask_t *val_rtrn) { xkb_mod_index_t ndx; + const struct xkb_keymap *keymap = priv; - if (LookupModMask(ctx, NULL, field, type, val_rtrn)) { + if (LookupModMask(ctx, keymap, field, type, val_rtrn)) { return true; } - else if (LookupVModIndex(priv, field, type, &ndx)) { + else if (LookupVModIndex(ctx, keymap, field, type, &ndx)) { *val_rtrn = (1 << ndx); return true; } @@ -661,7 +666,6 @@ LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, return false; } - bool ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr, xkb_mod_mask_t *mask_rtrn) @@ -698,7 +702,7 @@ bool ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def, xkb_mod_index_t *ndx_rtrn) { - const struct xkb_vmod *vmod; + const struct xkb_mod *mod; xkb_mod_index_t i; xkb_atom_t name = def->value.str; @@ -710,9 +714,9 @@ ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def, return false; } - darray_enumerate(i, vmod, keymap->vmods) { - if (vmod->name == name) { - *ndx_rtrn = XKB_NUM_CORE_MODS + i; + darray_enumerate(i, mod, keymap->mods) { + if (mod->type == MOD_VIRT && mod->name == name) { + *ndx_rtrn = i; return true; } } diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h index 14a6179..bab70cc 100644 --- a/src/xkbcomp/expr.h +++ b/src/xkbcomp/expr.h @@ -33,7 +33,7 @@ ExprResolveLhs(struct xkb_context *ctx, const ExprDef *expr, ExprDef **index_rtrn); bool -ExprResolveModMask(struct xkb_context *ctx, const ExprDef *expr, +ExprResolveModMask(struct xkb_keymap *keymap, const ExprDef *expr, xkb_mod_mask_t *mask_rtrn); bool diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c index 52198d1..81e584e 100644 --- a/src/xkbcomp/keymap.c +++ b/src/xkbcomp/keymap.c @@ -32,15 +32,15 @@ static void ComputeEffectiveMask(struct xkb_keymap *keymap, struct xkb_mods *mods) { - const struct xkb_vmod *vmod; + const struct xkb_mod *mod; xkb_mod_index_t i; /* The effective mask is only real mods for now. */ mods->mask = mods->mods & 0xff; - darray_enumerate(i, vmod, keymap->vmods) - if (mods->mods & (1 << (i + XKB_NUM_CORE_MODS))) - mods->mask |= vmod->mapping; + darray_enumerate(i, mod, keymap->mods) + if (mod->type == MOD_VIRT && mods->mods & (1 << i)) + mods->mask |= mod->mapping; } static void @@ -78,7 +78,7 @@ 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; + const struct xkb_sym_interpret *interp; const xkb_keysym_t *syms; int num_syms; @@ -184,7 +184,7 @@ ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key) static bool UpdateDerivedKeymapFields(struct xkb_keymap *keymap) { - struct xkb_vmod *vmod; + struct xkb_mod *mod; xkb_led_index_t led; unsigned int i, j; struct xkb_key *key; @@ -195,11 +195,11 @@ UpdateDerivedKeymapFields(struct xkb_keymap *keymap) if (!ApplyInterpsToKey(keymap, key)) return false; - /* Update keymap->vmods, the virtual -> real mod mapping. */ + /* Update keymap->mods, the virtual -> real mod mapping. */ xkb_foreach_key(key, keymap) - darray_enumerate(i, vmod, keymap->vmods) - if (key->vmodmap & (1 << (XKB_NUM_CORE_MODS + i))) - vmod->mapping |= key->modmap; + darray_enumerate(i, mod, keymap->mods) + if (mod->type == MOD_VIRT && key->vmodmap & (1 << i)) + mod->mapping |= key->modmap; /* Now update the level masks for all the types to reflect the vmods. */ for (i = 0; i < keymap->num_types; i++) { @@ -229,6 +229,28 @@ UpdateDerivedKeymapFields(struct xkb_keymap *keymap) return true; } +static bool +UpdateBuiltinKeymapFields(struct xkb_keymap *keymap) +{ + struct xkb_context *ctx = keymap->ctx; + + /* + * Add predefined (AKA real, core, X11) modifiers. + * The order is important! + */ + darray_appends(keymap->mods, + { .name = xkb_atom_intern(ctx, "Shift"), .type = MOD_REAL }, + { .name = xkb_atom_intern(ctx, "Lock"), .type = MOD_REAL }, + { .name = xkb_atom_intern(ctx, "Control"), .type = MOD_REAL }, + { .name = xkb_atom_intern(ctx, "Mod1"), .type = MOD_REAL }, + { .name = xkb_atom_intern(ctx, "Mod2"), .type = MOD_REAL }, + { .name = xkb_atom_intern(ctx, "Mod3"), .type = MOD_REAL }, + { .name = xkb_atom_intern(ctx, "Mod4"), .type = MOD_REAL }, + { .name = xkb_atom_intern(ctx, "Mod5"), .type = MOD_REAL }); + + return true; +} + typedef bool (*compile_file_fn)(XkbFile *file, struct xkb_keymap *keymap, enum merge_mode merge); @@ -294,6 +316,9 @@ CompileKeymap(XkbFile *file, struct xkb_keymap *keymap, enum merge_mode merge) if (!ok) return false; + if (!UpdateBuiltinKeymapFields(keymap)) + return false; + /* Compile sections. */ for (type = FIRST_KEYMAP_FILE_TYPE; type <= LAST_KEYMAP_FILE_TYPE; diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index 2324550..14d7668 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -440,7 +440,7 @@ AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi) } static bool -AddModMapEntry(SymbolsInfo * info, ModMapEntry * new) +AddModMapEntry(SymbolsInfo *info, ModMapEntry *new) { ModMapEntry *mm; bool clobber; @@ -462,8 +462,9 @@ AddModMapEntry(SymbolsInfo * info, ModMapEntry * new) log_err(info->keymap->ctx, "%s added to symbol map for multiple modifiers; " "Using %s, ignoring %s.\n", - KeysymText(new->u.keySym), ModIndexText(use), - ModIndexText(ignore)); + KeysymText(new->u.keySym), + ModIndexText(info->keymap, use), + ModIndexText(info->keymap, ignore)); mm->modifier = use; } return true; @@ -484,7 +485,8 @@ AddModMapEntry(SymbolsInfo * info, ModMapEntry * new) "Key %s added to map for multiple modifiers; " "Using %s, ignoring %s.\n", KeyNameText(info->keymap->ctx, new->u.keyName), - ModIndexText(use), ModIndexText(ignore)); + ModIndexText(info->keymap, use), + ModIndexText(info->keymap, ignore)); mm->modifier = use; } return true; @@ -1209,7 +1211,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def) bool ok; struct xkb_context *ctx = info->keymap->ctx; - ndx = ModNameToIndex(xkb_atom_text(ctx, def->modifier)); + ndx = ModNameToIndex(info->keymap, def->modifier); if (ndx == XKB_MOD_INVALID) { log_err(info->keymap->ctx, "Illegal modifier map definition; " @@ -1236,7 +1238,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def) log_err(info->keymap->ctx, "Modmap entries may contain only key names or keysyms; " "Illegal definition for %s modifier ignored\n", - ModIndexText(tmp.modifier)); + ModIndexText(info->keymap, tmp.modifier)); continue; } @@ -1571,7 +1573,7 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry) "Key %s not found in keycodes; " "Modifier map entry for %s not updated\n", KeyNameText(keymap->ctx, entry->u.keyName), - ModIndexText(entry->modifier)); + ModIndexText(info->keymap, entry->modifier)); return false; } } @@ -1582,7 +1584,7 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry) "Key \"%s\" not found in symbol map; " "Modifier map entry for %s not updated\n", KeysymText(entry->u.keySym), - ModIndexText(entry->modifier)); + ModIndexText(info->keymap, entry->modifier)); return false; } } diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c index 5e8a6c5..206e162 100644 --- a/src/xkbcomp/vmod.c +++ b/src/xkbcomp/vmod.c @@ -33,37 +33,37 @@ bool HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt) { xkb_mod_index_t i; - const char *name; - const struct xkb_vmod *vmod; - struct xkb_vmod new; + const struct xkb_mod *mod; + struct xkb_mod new; if (stmt->value) log_err(keymap->ctx, "Support for setting a value in a virtual_modifiers statement has been removed; " "Value ignored\n"); - name = xkb_atom_text(keymap->ctx, stmt->name); - if (ModNameToIndex(name) != XKB_MOD_INVALID) { - log_err(keymap->ctx, - "Can't add a virtual modifier named \"%s\"; " - "there is already a non-virtual modifier with this name! Ignored\n", - name); - return false; - } + darray_enumerate(i, mod, keymap->mods) { + if (mod->name == stmt->name) { + if (mod->type == MOD_VIRT) + return true; - darray_enumerate(i, vmod, keymap->vmods) - if (vmod->name == stmt->name) - return true; + log_err(keymap->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)); + return false; + } + } - if (darray_size(keymap->vmods) >= XKB_MAX_VIRTUAL_MODS) { + if (darray_size(keymap->mods) >= XKB_MAX_MODS) { log_err(keymap->ctx, - "Too many virtual modifiers defined (maximum %d)\n", - XKB_MAX_VIRTUAL_MODS); + "Too many modifiers defined (maximum %d)\n", + XKB_MAX_MODS); return false; } new.name = stmt->name; new.mapping = 0; - darray_append(keymap->vmods, new); + new.type = MOD_VIRT; + darray_append(keymap->mods, new); return true; } |