vmod: remove support for resolving integer to virtual modifier
This is only relevant to the virtualModifier= statement in interpret statements in xkb_compat. The current code allows to write e.g. virtualModifier = 4 to get the virtual modifier whose index happens to be 4 (possibly declared in other files or sections, i.e. xkb_types). Doing this is undeterministic, will break without notice, and not used anywhere. Don't allow it. Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
d3ddcf70e8
commit
f410622b4b
|
@ -43,6 +43,14 @@ streq(const char *s1, const char *s2)
|
||||||
return strcmp(s1, s2) == 0;
|
return strcmp(s1, s2) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
streq_not_null(const char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
if (!s1 || !s2)
|
||||||
|
return false;
|
||||||
|
return streq(s1, s2);
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
istreq(const char *s1, const char *s2)
|
istreq(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -173,32 +173,29 @@ bool
|
||||||
ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
|
ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
|
||||||
xkb_mod_index_t *ndx_rtrn, VModInfo *info)
|
xkb_mod_index_t *ndx_rtrn, VModInfo *info)
|
||||||
{
|
{
|
||||||
int val;
|
xkb_mod_index_t i;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
if (def->op == EXPR_IDENT) {
|
if (def->op != EXPR_IDENT) {
|
||||||
xkb_mod_index_t i;
|
log_err(keymap->ctx,
|
||||||
xkb_mod_mask_t bit;
|
"Cannot resolve virtual modifier: "
|
||||||
const char *name = xkb_atom_text(keymap->ctx, def->value.str);
|
"found %s where a virtual modifier name was expected\n",
|
||||||
|
expr_op_type_to_string(def->op));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
|
name = xkb_atom_text(keymap->ctx, def->value.str);
|
||||||
if ((info->available & bit) && keymap->vmod_names[i] &&
|
|
||||||
streq(keymap->vmod_names[i], name)) {
|
for (i = 0; i < XkbNumVirtualMods; i++) {
|
||||||
*ndx_rtrn = i;
|
if ((info->available & (1 << i)) &&
|
||||||
return true;
|
streq_not_null(keymap->vmod_names[i], name)) {
|
||||||
}
|
*ndx_rtrn = i;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ExprResolveInteger(keymap->ctx, def, &val))
|
log_err(keymap->ctx,
|
||||||
return false;
|
"Cannot resolve virtual modifier: "
|
||||||
|
"\"%s\" was not previously declared\n", name);
|
||||||
if (val < 0 || val >= XkbNumVirtualMods) {
|
return false;
|
||||||
log_err(keymap->ctx,
|
|
||||||
"Illegal virtual modifier %d (must be 0..%d inclusive)\n",
|
|
||||||
val, XkbNumVirtualMods - 1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
*ndx_rtrn = (xkb_mod_index_t) val;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue