* Ran Benita <ran234@gmail.com>
*/
+#include "config.h"
+
#include "xkbcomp-priv.h"
#include "text.h"
#include "expr.h"
#include "include.h"
#include "keysym.h"
+
+// TODO: convert log_err to log_err_with_code
+// TODO: convert log_vrb to log_vrb_with_code
+
enum key_repeat {
KEY_REPEAT_UNDEFINED = 0,
KEY_REPEAT_YES = 1,
typedef struct {
enum merge_mode merge;
bool haveSymbol;
+ // NOTE: Can also be XKB_MOD_NONE, meaning
+ // “don’t add a modifier to the modmap”.
xkb_mod_index_t modifier;
union {
xkb_atom_t keyName;
/* First find the type of the merged group. */
if (into->type != from->type) {
if (from->type == XKB_ATOM_NONE) {
+ /* it's empty for consistency with other comparisons */
}
else if (into->type == XKB_ATOM_NONE) {
into->type = from->type;
xkb_atom_t use = (clobber ? from->type : into->type);
xkb_atom_t ignore = (clobber ? into->type : from->type);
- if (report)
- log_warn(info->ctx,
+ if (report) {
+ log_warn_with_code(info->ctx,
+ XKB_WARNING_CONFLICTING_KEY_TYPE,
"Multiple definitions for group %d type of key %s; "
"Using %s, ignoring %s\n",
group + 1, KeyNameText(info->ctx, key_name),
xkb_atom_text(info->ctx, use),
xkb_atom_text(info->ctx, ignore));
+ }
into->type = use;
}
struct xkb_level *fromLevel = &darray_item(from->levels, i);
if (fromLevel->action.type == ACTION_TYPE_NONE) {
+ /* it's empty for consistency with other comparisons */
}
else if (intoLevel->action.type == ACTION_TYPE_NONE) {
intoLevel->action = fromLevel->action;
use = (clobber ? &fromLevel->action : &intoLevel->action);
ignore = (clobber ? &intoLevel->action : &fromLevel->action);
- if (report)
- log_warn(info->ctx,
+ if (report) {
+ log_warn_with_code(info->ctx,
+ XKB_WARNING_CONFLICTING_KEY_ACTION,
"Multiple actions for level %d/group %u on key %s; "
"Using %s, ignoring %s\n",
i + 1, group + 1, KeyNameText(info->ctx, key_name),
ActionTypeText(use->type),
ActionTypeText(ignore->type));
+ }
intoLevel->action = *use;
}
if (fromLevel->num_syms == 0) {
+ /* it's empty for consistency with other comparisons */
}
else if (intoLevel->num_syms == 0) {
intoLevel->num_syms = fromLevel->num_syms;
fromLevel->num_syms = 0;
}
else if (!XkbLevelsSameSyms(fromLevel, intoLevel)) {
- if (report)
- log_warn(info->ctx,
+ if (report) {
+ log_warn_with_code(info->ctx,
+ XKB_WARNING_CONFLICTING_KEY_SYMBOL,
"Multiple symbols for level %d/group %u on key %s; "
"Using %s, ignoring %s\n",
i + 1, group + 1, KeyNameText(info->ctx, key_name),
(clobber ? "from" : "to"),
(clobber ? "to" : "from"));
+ }
if (clobber) {
ClearLevelInfo(intoLevel);
into->defined |= KEY_FIELD_GROUPINFO;
}
- if (collide)
- log_warn(info->ctx,
+ if (collide) {
+ log_warn_with_code(info->ctx,
+ XKB_WARNING_CONFLICTING_KEY_FIELDS,
"Symbol map for key %s redefined; "
"Using %s definition for conflicting fields\n",
KeyNameText(info->ctx, into->name),
(clobber ? "first" : "last"));
+ }
ClearKeyInfo(from);
InitKeyInfo(info->ctx, from);
use = (clobber ? new->modifier : old->modifier);
ignore = (clobber ? old->modifier : new->modifier);
- if (new->haveSymbol)
- log_err(info->ctx,
- "Symbol \"%s\" added to modifier map for multiple modifiers; "
- "Using %s, ignoring %s\n",
- KeysymText(info->ctx, new->u.keySym),
- ModIndexText(info->ctx, &info->mods, use),
- ModIndexText(info->ctx, &info->mods, ignore));
- else
- log_err(info->ctx,
- "Key \"%s\" added to modifier map for multiple modifiers; "
- "Using %s, ignoring %s\n",
- KeyNameText(info->ctx, new->u.keyName),
- ModIndexText(info->ctx, &info->mods, use),
- ModIndexText(info->ctx, &info->mods, ignore));
-
+ if (new->haveSymbol) {
+ log_warn_with_code(info->ctx,
+ XKB_WARNING_CONFLICTING_MODMAP,
+ "Symbol \"%s\" added to modifier map for multiple modifiers; "
+ "Using %s, ignoring %s\n",
+ KeysymText(info->ctx, new->u.keySym),
+ ModIndexText(info->ctx, &info->mods, use),
+ ModIndexText(info->ctx, &info->mods, ignore));
+ } else {
+ log_warn_with_code(info->ctx,
+ XKB_WARNING_CONFLICTING_MODMAP,
+ "Key \"%s\" added to modifier map for multiple modifiers; "
+ "Using %s, ignoring %s\n",
+ KeyNameText(info->ctx, new->u.keyName),
+ ModIndexText(info->ctx, &info->mods, use),
+ ModIndexText(info->ctx, &info->mods, ignore));
+ }
old->modifier = use;
return true;
}
}
if (!ExprResolveGroup(info->ctx, arrayNdx, ndx_rtrn)) {
- log_err(info->ctx,
+ log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX,
"Illegal group index for %s of key %s\n"
"Definition with non-integer array index ignored\n",
name, KeyInfoText(info, keyi));
}
nActs = 0;
- for (act = value->unary.child; act; act = (ExprDef *) act->common.next)
+ for (act = value->actions.actions; act; act = (ExprDef *) act->common.next)
nActs++;
if (darray_size(groupi->levels) < nActs)
groupi->defined |= GROUP_FIELD_ACTS;
- act = value->unary.child;
+ act = value->actions.actions;
for (unsigned i = 0; i < nActs; i++) {
union xkb_action *toAct = &darray_item(groupi->levels, i).action;
keyi->defined |= KEY_FIELD_DEFAULT_TYPE;
}
else if (!ExprResolveGroup(info->ctx, arrayNdx, &ndx)) {
- log_err(info->ctx,
+ log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX,
"Illegal group index for type of key %s; "
"Definition with non-integer array index ignored\n",
KeyInfoText(info, keyi));
xkb_layout_index_t grp;
if (!ExprResolveGroup(info->ctx, value, &grp)) {
- log_err(info->ctx,
+ log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX,
"Illegal group index for redirect of key %s; "
"Definition with non-integer group ignored\n",
KeyInfoText(info, keyi));
}
if (!ExprResolveGroup(info->ctx, arrayNdx, &group)) {
- log_err(info->ctx,
+ log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX,
"Illegal index in group name definition; "
"Definition with non-integer array index ignored\n");
return false;
group_to_use = info->explicit_group;
}
else {
- log_warn(info->ctx,
+ log_warn_with_code(info->ctx,
+ XKB_WARNING_NON_BASE_GROUP_NAME,
"An explicit group was specified for the '%s' map, "
"but it provides a name for a group other than Group1 (%d); "
"Ignoring group name '%s'\n",
}
}
- if (warn)
- log_warn(info->ctx,
+ if (warn) {
+ log_warn_with_code(info->ctx,
+ XKB_WARNING_MULTIPLE_GROUPS_AT_ONCE,
"For the map %s an explicit group specified, "
"but key %s has more than one group defined; "
"All groups except first one will be ignored\n",
info->name, KeyInfoText(info, keyi));
+ }
darray_resize0(keyi->groups, info->explicit_group + 1);
if (info->explicit_group > 0) {
xkb_mod_index_t ndx;
bool ok;
struct xkb_context *ctx = info->ctx;
-
- ndx = XkbModNameToIndex(&info->mods, def->modifier, MOD_REAL);
- if (ndx == XKB_MOD_INVALID) {
- log_err(info->ctx,
- "Illegal modifier map definition; "
- "Ignoring map for non-modifier \"%s\"\n",
- xkb_atom_text(ctx, def->modifier));
- return false;
+ const char *modifier_name = xkb_atom_text(ctx, def->modifier);
+
+ if (istreq(modifier_name, "none")) {
+ // Handle special "None" entry
+ ndx = XKB_MOD_NONE;
+ } else {
+ // Handle normal entry
+ ndx = XkbModNameToIndex(&info->mods, def->modifier, MOD_REAL);
+ if (ndx == XKB_MOD_INVALID) {
+ log_err(info->ctx,
+ "Illegal modifier map definition; "
+ "Ignoring map for non-modifier \"%s\"\n",
+ xkb_atom_text(ctx, def->modifier));
+ return false;
+ }
}
ok = true;
}
if (type_name == XKB_ATOM_NONE) {
- log_warn(keymap->ctx,
+ log_warn_with_code(keymap->ctx,
+ XKB_WARNING_CANNOT_INFER_KEY_TYPE,
"Couldn't find an automatic type for key '%s' group %d with %lu levels; "
"Using the default type\n",
KeyNameText(keymap->ctx, keyi->name), group + 1,
break;
if (i >= keymap->num_types) {
- log_warn(keymap->ctx,
+ log_warn_with_code(keymap->ctx,
+ XKB_WARNING_UNDEFINED_KEY_TYPE,
"The type \"%s\" for key '%s' group %d was not previously defined; "
"Using the default type\n",
xkb_atom_text(keymap->ctx, type_name),
*/
key = XkbKeyByName(keymap, keyi->name, false);
if (!key) {
- log_vrb(info->ctx, 5,
+ log_vrb_with_code(info->ctx, 5,
+ XKB_WARNING_UNDEFINED_KEYCODE,
"Key %s not found in keycodes; Symbols ignored\n",
KeyInfoText(info, keyi));
return false;
if (type->num_levels < darray_size(groupi->levels)) {
struct xkb_level *leveli;
- log_vrb(info->ctx, 1,
+ log_vrb_with_code(info->ctx, 1,
+ XKB_WARNING_EXTRA_SYMBOLS_IGNORED,
"Type \"%s\" has %d levels, but %s has %d levels; "
"Ignoring extra symbols\n",
xkb_atom_text(keymap->ctx, type->name), type->num_levels,
if (!entry->haveSymbol) {
key = XkbKeyByName(keymap, entry->u.keyName, true);
if (!key) {
- log_vrb(info->ctx, 5,
+ log_vrb_with_code(info->ctx, 5,
+ XKB_WARNING_UNDEFINED_KEYCODE,
"Key %s not found in keycodes; "
"Modifier map entry for %s not updated\n",
KeyNameText(info->ctx, entry->u.keyName),
else {
key = FindKeyForSymbol(keymap, entry->u.keySym);
if (!key) {
- log_vrb(info->ctx, 5,
+ log_vrb_with_code(info->ctx, 5,
+ XKB_WARNING_UNRESOLVED_KEYMAP_SYMBOL,
"Key \"%s\" not found in symbol map; "
"Modifier map entry for %s not updated\n",
KeysymText(info->ctx, entry->u.keySym),
}
}
- key->modmap |= (1u << entry->modifier);
+ // Handle modMap None
+ if (entry->modifier != XKB_MOD_NONE) {
+ // Convert modifier index to modifier mask
+ key->modmap |= (1u << entry->modifier);
+ }
+
return true;
}