diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c index d883ab3..0c94346 100644 --- a/src/xkbcomp/compat.c +++ b/src/xkbcomp/compat.c @@ -195,7 +195,6 @@ typedef struct { darray(SymInterpInfo) interps; LEDInfo ledDflt; darray(LEDInfo) leds; - VModInfo vmods; ActionsInfo *actions; struct xkb_keymap *keymap; } CompatInfo; @@ -260,7 +259,6 @@ InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id, info->dflt.interp.virtual_mod = XKB_MOD_INVALID; info->ledDflt.file_id = file_id; info->ledDflt.merge = MERGE_OVERRIDE; - InitVModInfo(&info->vmods, keymap); } static void @@ -584,7 +582,7 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field, if (arrayNdx) return ReportSINotArray(info, si, field); - if (!ResolveVirtualModifier(value, keymap, &ndx, &info->vmods)) + if (!ExprResolveVMod(keymap, value, &ndx)) return ReportSIBadType(info, si, field, "virtual modifier"); si->interp.virtual_mod = ndx; @@ -898,7 +896,7 @@ HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge) ok = HandleGlobalVar(info, (VarDef *) stmt); break; case STMT_VMOD: - ok = HandleVModDef((VModDef *) stmt, info->keymap, &info->vmods); + ok = HandleVModDef(info->keymap, (VModDef *) stmt); break; default: log_err(info->keymap->ctx, diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index cf6ff40..c8197d1 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -90,7 +90,7 @@ LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field, return (*val_rtrn != XKB_MOD_INVALID); } -bool +static bool LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, enum expr_value_type type, xkb_mod_mask_t *val_rtrn) { @@ -624,6 +624,44 @@ ExprResolveModMask(struct xkb_context *ctx, const ExprDef *expr, return ExprResolveMaskLookup(ctx, expr, mask_rtrn, LookupModMask, NULL); } +static bool +LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field, + enum expr_value_type type, xkb_mod_index_t *val_rtrn) +{ + const struct xkb_vmod *vmod; + xkb_mod_index_t i; + + if (type != EXPR_TYPE_INT) + return false; + + darray_enumerate(i, vmod, keymap->vmods) { + if (vmod->name == field) { + *val_rtrn = i; + return true; + } + } + + return false; +} + +static bool +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; + + if (LookupModMask(ctx, NULL, field, type, val_rtrn)) { + return true; + } + else if (LookupVModIndex(priv, field, type, &ndx)) { + *val_rtrn = (1 << (XKB_NUM_CORE_MODS + ndx)); + return true; + } + + return false; +} + + bool ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr, xkb_mod_mask_t *mask_rtrn) @@ -655,3 +693,33 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr, *sym_rtrn = ((xkb_keysym_t) val) + '0'; return true; } + +bool +ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def, + xkb_mod_index_t *ndx_rtrn) +{ + const struct xkb_vmod *vmod; + xkb_mod_index_t i; + xkb_atom_t name = def->value.str; + + if (def->op != EXPR_IDENT) { + log_err(keymap->ctx, + "Cannot resolve virtual modifier: " + "found %s where a virtual modifier name was expected\n", + expr_op_type_to_string(def->op)); + return false; + } + + darray_enumerate(i, vmod, keymap->vmods) { + if (vmod->name == name) { + *ndx_rtrn = i; + return true; + } + } + + log_err(keymap->ctx, + "Cannot resolve virtual modifier: " + "\"%s\" was not previously declared\n", + xkb_atom_text(keymap->ctx, name)); + return false; +} diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h index 21d9c5d..a5abce1 100644 --- a/src/xkbcomp/expr.h +++ b/src/xkbcomp/expr.h @@ -32,14 +32,6 @@ ExprResolveLhs(struct xkb_context *ctx, const ExprDef *expr, const char **elem_rtrn, const char **field_rtrn, ExprDef **index_rtrn); -bool -LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, - enum expr_value_type type, xkb_mod_mask_t *val_rtrn); - -bool -LookupVModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field, - enum expr_value_type type, xkb_mod_mask_t *val_rtrn); - bool LookupModIndex(struct xkb_context *ctx, const void *priv, xkb_atom_t field, enum expr_value_type type, xkb_mod_index_t *val_rtrn); @@ -52,6 +44,10 @@ bool ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr, xkb_mod_mask_t *mask_rtrn); +bool +ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def, + xkb_mod_index_t *ndx_rtrn); + bool ExprResolveBoolean(struct xkb_context *ctx, const ExprDef *expr, bool *set_rtrn); diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index bb6ccc6..06661ae 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -179,7 +179,6 @@ typedef struct { xkb_layout_index_t explicit_group; darray(KeyInfo) keys; KeyInfo dflt; - VModInfo vmods; ActionsInfo *actions; darray_xkb_atom_t group_names; darray(ModMapEntry) modMaps; @@ -196,7 +195,6 @@ InitSymbolsInfo(SymbolsInfo *info, struct xkb_keymap *keymap, info->file_id = file_id; info->merge = MERGE_OVERRIDE; InitKeyInfo(keymap->ctx, &info->dflt, file_id); - InitVModInfo(&info->vmods, keymap); info->actions = actions; info->explicit_group = XKB_LAYOUT_INVALID; } @@ -1268,7 +1266,7 @@ HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge) ok = HandleGlobalVar(info, (VarDef *) stmt); break; case STMT_VMOD: - ok = HandleVModDef((VModDef *) stmt, info->keymap, &info->vmods); + ok = HandleVModDef(info->keymap, (VModDef *) stmt); break; case STMT_MODMAP: ok = HandleModMapDef(info, (ModMapDef *) stmt); diff --git a/src/xkbcomp/types.c b/src/xkbcomp/types.c index 73c1427..5eff5f4 100644 --- a/src/xkbcomp/types.c +++ b/src/xkbcomp/types.c @@ -160,7 +160,6 @@ typedef struct { unsigned file_id; darray(KeyTypeInfo) types; - VModInfo vmods; struct xkb_keymap *keymap; } KeyTypesInfo; @@ -219,7 +218,6 @@ InitKeyTypesInfo(KeyTypesInfo *info, struct xkb_keymap *keymap, memset(info, 0, sizeof(*info)); info->keymap = keymap; info->file_id = file_id; - InitVModInfo(&info->vmods, keymap); } static void @@ -761,7 +759,7 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge) ok = true; break; case STMT_VMOD: /* virtual_modifiers NumLock, ... */ - ok = HandleVModDef((VModDef *) stmt, info->keymap, &info->vmods); + ok = HandleVModDef(info->keymap, (VModDef *) stmt); break; default: log_err(info->keymap->ctx, diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c index 51269be..5e8a6c5 100644 --- a/src/xkbcomp/vmod.c +++ b/src/xkbcomp/vmod.c @@ -29,18 +29,8 @@ #include "expr.h" #include "vmod.h" -void -InitVModInfo(VModInfo *info, struct xkb_keymap *keymap) -{ - xkb_mod_index_t i; - - memset(info, 0, sizeof(*info)); - for (i = 0; i < darray_size(keymap->vmods); i++) - info->defined |= (1 << i); -} - bool -HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info) +HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt) { xkb_mod_index_t i; const char *name; @@ -61,12 +51,9 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info) return false; } - darray_enumerate(i, vmod, keymap->vmods) { - if (vmod->name == stmt->name) { - info->available |= 1 << i; + darray_enumerate(i, vmod, keymap->vmods) + if (vmod->name == stmt->name) return true; - } - } if (darray_size(keymap->vmods) >= XKB_MAX_VIRTUAL_MODS) { log_err(keymap->ctx, @@ -78,73 +65,5 @@ HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info) new.name = stmt->name; new.mapping = 0; darray_append(keymap->vmods, new); - info->available |= (1 << (darray_size(keymap->vmods) - 1)); return true; } - -static bool -LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field, - enum expr_value_type type, xkb_mod_index_t *val_rtrn) -{ - const struct xkb_vmod *vmod; - xkb_mod_index_t i; - - if (type != EXPR_TYPE_INT) - return false; - - darray_enumerate(i, vmod, keymap->vmods) { - if (vmod->name == field) { - *val_rtrn = i; - return true; - } - } - - return false; -} - -bool -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; - - if (LookupModMask(ctx, NULL, field, type, val_rtrn)) { - return true; - } - else if (LookupVModIndex(priv, field, type, &ndx)) { - *val_rtrn = (1 << (XKB_NUM_CORE_MODS + ndx)); - return true; - } - - return false; -} - -bool -ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap, - xkb_mod_index_t *ndx_rtrn, VModInfo *info) -{ - const struct xkb_vmod *vmod; - xkb_mod_index_t i; - xkb_atom_t name = def->value.str; - - if (def->op != EXPR_IDENT) { - log_err(keymap->ctx, - "Cannot resolve virtual modifier: " - "found %s where a virtual modifier name was expected\n", - expr_op_type_to_string(def->op)); - return false; - } - - darray_enumerate(i, vmod, keymap->vmods) { - if ((info->available & (1 << i)) && vmod->name == name) { - *ndx_rtrn = i; - return true; - } - } - - log_err(keymap->ctx, - "Cannot resolve virtual modifier: " - "\"%s\" was not previously declared\n", - xkb_atom_text(keymap->ctx, name)); - return false; -} diff --git a/src/xkbcomp/vmod.h b/src/xkbcomp/vmod.h index 6fdd891..9915507 100644 --- a/src/xkbcomp/vmod.h +++ b/src/xkbcomp/vmod.h @@ -27,19 +27,7 @@ #ifndef XKBCOMP_VMOD_H #define XKBCOMP_VMOD_H -typedef struct { - xkb_mod_mask_t defined; - xkb_mod_mask_t available; -} VModInfo; - -void -InitVModInfo(VModInfo *info, struct xkb_keymap *keymap); - bool -HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, VModInfo *info); - -bool -ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap, - xkb_mod_index_t *ndx_rtrn, VModInfo *info); +HandleVModDef(struct xkb_keymap *keymap, VModDef *stmt); #endif