expr: unify the real and virtual modifier functions
This again pushes the mod type annotation to the original call site, to make it easier to grep to see where the real/virtual distinction matters. Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
39232e6dae
commit
a1124b5991
|
@ -278,7 +278,7 @@ CheckModifierField(struct xkb_keymap *keymap, enum xkb_action_type action,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ExprResolveVModMask(keymap, value, mods_rtrn))
|
if (!ExprResolveModMask(keymap, value, MOD_BOTH, mods_rtrn))
|
||||||
return ReportMismatch(keymap, action,
|
return ReportMismatch(keymap, action,
|
||||||
ACTION_FIELD_MODIFIERS, "modifier mask");
|
ACTION_FIELD_MODIFIERS, "modifier mask");
|
||||||
|
|
||||||
|
|
|
@ -394,7 +394,7 @@ ResolveStateAndPredicate(ExprDef *expr, enum xkb_match_operation *pred_rtrn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ExprResolveModMask(info->keymap, expr, mods_rtrn);
|
return ExprResolveModMask(info->keymap, expr, MOD_REAL, mods_rtrn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***====================================================================***/
|
/***====================================================================***/
|
||||||
|
@ -582,7 +582,7 @@ SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
|
||||||
if (arrayNdx)
|
if (arrayNdx)
|
||||||
return ReportSINotArray(info, si, field);
|
return ReportSINotArray(info, si, field);
|
||||||
|
|
||||||
if (!ExprResolveVMod(keymap, value, &ndx))
|
if (!ExprResolveMod(keymap, value, MOD_VIRT, &ndx))
|
||||||
return ReportSIBadType(info, si, field, "virtual modifier");
|
return ReportSIBadType(info, si, field, "virtual modifier");
|
||||||
|
|
||||||
si->interp.virtual_mod = ndx;
|
si->interp.virtual_mod = ndx;
|
||||||
|
@ -642,7 +642,7 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
|
||||||
if (arrayNdx)
|
if (arrayNdx)
|
||||||
return ReportIndicatorNotArray(info, led, field);
|
return ReportIndicatorNotArray(info, led, field);
|
||||||
|
|
||||||
if (!ExprResolveVModMask(keymap, value, &led->im.mods.mods))
|
if (!ExprResolveModMask(keymap, value, MOD_BOTH, &led->im.mods.mods))
|
||||||
return ReportIndicatorBadType(info, led, field, "modifier mask");
|
return ReportIndicatorBadType(info, led, field, "modifier mask");
|
||||||
|
|
||||||
led->defined |= LED_FIELD_MODS;
|
led->defined |= LED_FIELD_MODS;
|
||||||
|
|
|
@ -81,14 +81,21 @@ SimpleLookup(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Data passed in the *priv argument for LookupModMask. */
|
||||||
|
typedef struct {
|
||||||
|
const struct xkb_keymap *keymap;
|
||||||
|
enum mod_type mod_type;
|
||||||
|
} LookupModMaskPriv;
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
lookup_mod_mask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
|
LookupModMask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
|
||||||
enum expr_value_type type, enum mod_type mod_type,
|
enum expr_value_type type, xkb_mod_mask_t *val_rtrn)
|
||||||
xkb_mod_mask_t *val_rtrn)
|
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
xkb_mod_index_t ndx;
|
xkb_mod_index_t ndx;
|
||||||
const struct xkb_keymap *keymap = priv;
|
const LookupModMaskPriv *arg = priv;
|
||||||
|
const struct xkb_keymap *keymap = arg->keymap;
|
||||||
|
enum mod_type mod_type = arg->mod_type;
|
||||||
|
|
||||||
if (type != EXPR_TYPE_INT)
|
if (type != EXPR_TYPE_INT)
|
||||||
return false;
|
return false;
|
||||||
|
@ -113,20 +120,6 @@ lookup_mod_mask(struct xkb_context *ctx, const void *priv, xkb_atom_t field,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
return lookup_mod_mask(ctx, priv, field, type, MOD_REAL, val_rtrn);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
return lookup_mod_mask(ctx, priv, field, type, MOD_BOTH, val_rtrn);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ExprResolveBoolean(struct xkb_context *ctx, const ExprDef *expr,
|
ExprResolveBoolean(struct xkb_context *ctx, const ExprDef *expr,
|
||||||
bool *set_rtrn)
|
bool *set_rtrn)
|
||||||
|
@ -632,18 +625,11 @@ ExprResolveMask(struct xkb_context *ctx, const ExprDef *expr,
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ExprResolveModMask(struct xkb_keymap *keymap, const ExprDef *expr,
|
ExprResolveModMask(struct xkb_keymap *keymap, const ExprDef *expr,
|
||||||
xkb_mod_mask_t *mask_rtrn)
|
enum mod_type mod_type, xkb_mod_mask_t *mask_rtrn)
|
||||||
{
|
{
|
||||||
|
LookupModMaskPriv priv = { .keymap = keymap, .mod_type = mod_type };
|
||||||
return ExprResolveMaskLookup(keymap->ctx, expr, mask_rtrn, LookupModMask,
|
return ExprResolveMaskLookup(keymap->ctx, expr, mask_rtrn, LookupModMask,
|
||||||
keymap);
|
&priv);
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr,
|
|
||||||
xkb_mod_mask_t *mask_rtrn)
|
|
||||||
{
|
|
||||||
return ExprResolveMaskLookup(keymap->ctx, expr, mask_rtrn, LookupVModMask,
|
|
||||||
keymap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -671,8 +657,8 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def,
|
ExprResolveMod(struct xkb_keymap *keymap, const ExprDef *def,
|
||||||
xkb_mod_index_t *ndx_rtrn)
|
enum mod_type mod_type, xkb_mod_index_t *ndx_rtrn)
|
||||||
{
|
{
|
||||||
xkb_mod_index_t ndx;
|
xkb_mod_index_t ndx;
|
||||||
xkb_atom_t name = def->value.str;
|
xkb_atom_t name = def->value.str;
|
||||||
|
@ -685,7 +671,7 @@ ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ndx = ModNameToIndex(keymap, name, MOD_VIRT);
|
ndx = ModNameToIndex(keymap, name, mod_type);
|
||||||
if (ndx == XKB_MOD_INVALID) {
|
if (ndx == XKB_MOD_INVALID) {
|
||||||
log_err(keymap->ctx,
|
log_err(keymap->ctx,
|
||||||
"Cannot resolve virtual modifier: "
|
"Cannot resolve virtual modifier: "
|
||||||
|
|
|
@ -34,15 +34,11 @@ ExprResolveLhs(struct xkb_context *ctx, const ExprDef *expr,
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ExprResolveModMask(struct xkb_keymap *keymap, const ExprDef *expr,
|
ExprResolveModMask(struct xkb_keymap *keymap, const ExprDef *expr,
|
||||||
xkb_mod_mask_t *mask_rtrn);
|
enum mod_type mod_type, xkb_mod_mask_t *mask_rtrn);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ExprResolveVModMask(struct xkb_keymap *keymap, const ExprDef *expr,
|
ExprResolveMod(struct xkb_keymap *keymap, const ExprDef *def,
|
||||||
xkb_mod_mask_t *mask_rtrn);
|
enum mod_type mod_type, xkb_mod_index_t *ndx_rtrn);
|
||||||
|
|
||||||
bool
|
|
||||||
ExprResolveVMod(struct xkb_keymap *keymap, const ExprDef *def,
|
|
||||||
xkb_mod_index_t *ndx_rtrn);
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ExprResolveBoolean(struct xkb_context *ctx, const ExprDef *expr,
|
ExprResolveBoolean(struct xkb_context *ctx, const ExprDef *expr,
|
||||||
|
|
|
@ -883,9 +883,9 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
|
||||||
istreq(field, "virtualmodifiers")) {
|
istreq(field, "virtualmodifiers")) {
|
||||||
xkb_mod_mask_t mask;
|
xkb_mod_mask_t mask;
|
||||||
|
|
||||||
ok = ExprResolveVModMask(info->keymap, value, &mask);
|
ok = ExprResolveModMask(info->keymap, value, MOD_VIRT, &mask);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
keyi->vmodmap = mask & (~0xff);
|
keyi->vmodmap = mask;
|
||||||
keyi->defined |= KEY_FIELD_VMODMAP;
|
keyi->defined |= KEY_FIELD_VMODMAP;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -364,7 +364,7 @@ SetModifiers(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
|
||||||
"The modifiers field of a key type is not an array; "
|
"The modifiers field of a key type is not an array; "
|
||||||
"Illegal array subscript ignored\n");
|
"Illegal array subscript ignored\n");
|
||||||
|
|
||||||
if (!ExprResolveVModMask(info->keymap, value, &mods)) {
|
if (!ExprResolveModMask(info->keymap, value, MOD_BOTH, &mods)) {
|
||||||
log_err(info->keymap->ctx,
|
log_err(info->keymap->ctx,
|
||||||
"Key type mask field must be a modifier mask; "
|
"Key type mask field must be a modifier mask; "
|
||||||
"Key type definition ignored\n");
|
"Key type definition ignored\n");
|
||||||
|
@ -448,7 +448,7 @@ SetMapEntry(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
|
||||||
if (arrayNdx == NULL)
|
if (arrayNdx == NULL)
|
||||||
return ReportTypeShouldBeArray(info, type, "map entry");
|
return ReportTypeShouldBeArray(info, type, "map entry");
|
||||||
|
|
||||||
if (!ExprResolveVModMask(info->keymap, arrayNdx, &entry.mods.mods))
|
if (!ExprResolveModMask(info->keymap, arrayNdx, MOD_BOTH, &entry.mods.mods))
|
||||||
return ReportTypeBadType(info, type, "map entry", "modifier mask");
|
return ReportTypeBadType(info, type, "map entry", "modifier mask");
|
||||||
|
|
||||||
if (entry.mods.mods & (~type->mods)) {
|
if (entry.mods.mods & (~type->mods)) {
|
||||||
|
@ -536,7 +536,7 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
|
||||||
if (arrayNdx == NULL)
|
if (arrayNdx == NULL)
|
||||||
return ReportTypeShouldBeArray(info, type, "preserve entry");
|
return ReportTypeShouldBeArray(info, type, "preserve entry");
|
||||||
|
|
||||||
if (!ExprResolveVModMask(info->keymap, arrayNdx, &mods))
|
if (!ExprResolveModMask(info->keymap, arrayNdx, MOD_BOTH, &mods))
|
||||||
return ReportTypeBadType(info, type, "preserve entry",
|
return ReportTypeBadType(info, type, "preserve entry",
|
||||||
"modifier mask");
|
"modifier mask");
|
||||||
|
|
||||||
|
@ -553,7 +553,7 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
|
||||||
TypeTxt(info, type), before, after);
|
TypeTxt(info, type), before, after);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ExprResolveVModMask(info->keymap, value, &preserve_mods)) {
|
if (!ExprResolveModMask(info->keymap, value, MOD_BOTH, &preserve_mods)) {
|
||||||
log_err(info->keymap->ctx,
|
log_err(info->keymap->ctx,
|
||||||
"Preserve value in a key type is not a modifier mask; "
|
"Preserve value in a key type is not a modifier mask; "
|
||||||
"Ignoring preserve[%s] in type %s\n",
|
"Ignoring preserve[%s] in type %s\n",
|
||||||
|
|
Loading…
Reference in New Issue