* Ran Benita <ran234@gmail.com>
*/
+#include "config.h"
+
#include "xkbcomp-priv.h"
#include "text.h"
#include "expr.h"
#include "action.h"
#include "vmod.h"
-#include "keycodes.h"
#include "include.h"
#include "keysym.h"
};
enum key_field {
- KEY_FIELD_REPEAT = (1 << 0),
- KEY_FIELD_TYPE_DFLT = (1 << 1),
+ KEY_FIELD_REPEAT = (1 << 0),
+ KEY_FIELD_DEFAULT_TYPE = (1 << 1),
KEY_FIELD_GROUPINFO = (1 << 2),
- KEY_FIELD_VMODMAP = (1 << 3),
+ KEY_FIELD_VMODMAP = (1 << 3),
};
typedef struct {
- unsigned int num_syms;
- unsigned int sym_index;
- union xkb_action act;
-} LevelInfo;
-
-typedef darray(xkb_keysym_t) darray_xkb_keysym_t;
-
-typedef struct {
enum group_field defined;
- darray_xkb_keysym_t syms;
- darray(LevelInfo) levels;
+ darray(struct xkb_level) levels;
xkb_atom_t type;
} GroupInfo;
-typedef struct _KeyInfo {
+typedef struct {
enum key_field defined;
- unsigned file_id;
enum merge_mode merge;
- unsigned long name; /* the 4 chars of the key name, as long */
+ xkb_atom_t name;
darray(GroupInfo) groups;
enum key_repeat repeat;
xkb_mod_mask_t vmodmap;
- xkb_atom_t dfltType;
+ xkb_atom_t default_type;
enum xkb_range_exceed_type out_of_range_group_action;
xkb_layout_index_t out_of_range_group_number;
} KeyInfo;
static void
+ClearLevelInfo(struct xkb_level *leveli)
+{
+ if (leveli->num_syms > 1)
+ free(leveli->u.syms);
+}
+
+static void
InitGroupInfo(GroupInfo *groupi)
{
memset(groupi, 0, sizeof(*groupi));
static void
ClearGroupInfo(GroupInfo *groupi)
{
- darray_free(groupi->syms);
+ struct xkb_level *leveli;
+ darray_foreach(leveli, groupi->levels)
+ ClearLevelInfo(leveli);
darray_free(groupi->levels);
}
static void
-InitKeyInfo(KeyInfo *keyi, unsigned file_id)
+CopyGroupInfo(GroupInfo *to, const GroupInfo *from)
{
- static const char dflt_key_name[XKB_KEY_NAME_LENGTH] = "*";
+ to->defined = from->defined;
+ to->type = from->type;
+ darray_init(to->levels);
+ darray_copy(to->levels, from->levels);
+ for (xkb_level_index_t j = 0; j < darray_size(to->levels); j++)
+ if (darray_item(from->levels, j).num_syms > 1)
+ darray_item(to->levels, j).u.syms =
+ memdup(darray_item(from->levels, j).u.syms,
+ darray_item(from->levels, j).num_syms,
+ sizeof(xkb_keysym_t));
+}
+static void
+InitKeyInfo(struct xkb_context *ctx, KeyInfo *keyi)
+{
memset(keyi, 0, sizeof(*keyi));
- keyi->file_id = file_id;
keyi->merge = MERGE_OVERRIDE;
- keyi->name = KeyNameToLong(dflt_key_name);
+ keyi->name = xkb_atom_intern_literal(ctx, "*");
keyi->out_of_range_group_action = RANGE_WRAP;
}
/***====================================================================***/
-typedef struct _ModMapEntry {
+typedef struct {
enum merge_mode merge;
bool haveSymbol;
- int modifier;
+ // NOTE: Can also be XKB_MOD_NONE, meaning
+ // “don’t add a modifier to the modmap”.
+ xkb_mod_index_t modifier;
union {
- unsigned long keyName;
+ xkb_atom_t keyName;
xkb_keysym_t keySym;
} u;
} ModMapEntry;
-typedef struct _SymbolsInfo {
+typedef struct {
char *name; /* e.g. pc+us+inet(evdev) */
int errorCount;
- unsigned file_id;
enum merge_mode merge;
xkb_layout_index_t explicit_group;
darray(KeyInfo) keys;
- KeyInfo dflt;
- VModInfo vmods;
+ KeyInfo default_key;
ActionsInfo *actions;
- darray_xkb_atom_t group_names;
- darray(ModMapEntry) modMaps;
+ darray(xkb_atom_t) group_names;
+ darray(ModMapEntry) modmaps;
+ struct xkb_mod_set mods;
- struct xkb_keymap *keymap;
+ struct xkb_context *ctx;
+ /* Needed for AddKeySymbols. */
+ const struct xkb_keymap *keymap;
} SymbolsInfo;
static void
-InitSymbolsInfo(SymbolsInfo *info, struct xkb_keymap *keymap,
- unsigned file_id, ActionsInfo *actions)
+InitSymbolsInfo(SymbolsInfo *info, const struct xkb_keymap *keymap,
+ ActionsInfo *actions, const struct xkb_mod_set *mods)
{
memset(info, 0, sizeof(*info));
+ info->ctx = keymap->ctx;
info->keymap = keymap;
- info->file_id = file_id;
info->merge = MERGE_OVERRIDE;
- InitKeyInfo(&info->dflt, file_id);
- InitVModInfo(&info->vmods, keymap);
+ InitKeyInfo(keymap->ctx, &info->default_key);
info->actions = actions;
+ info->mods = *mods;
info->explicit_group = XKB_LAYOUT_INVALID;
}
static void
-ClearSymbolsInfo(SymbolsInfo * info)
+ClearSymbolsInfo(SymbolsInfo *info)
{
KeyInfo *keyi;
free(info->name);
ClearKeyInfo(keyi);
darray_free(info->keys);
darray_free(info->group_names);
- darray_free(info->modMaps);
- ClearKeyInfo(&info->dflt);
+ darray_free(info->modmaps);
+ ClearKeyInfo(&info->default_key);
+}
+
+static const char *
+KeyInfoText(SymbolsInfo *info, KeyInfo *keyi)
+{
+ return KeyNameText(info->ctx, keyi->name);
}
static bool
MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber,
- bool report, xkb_layout_index_t group, unsigned long key_name)
+ bool report, xkb_layout_index_t group, xkb_atom_t key_name)
{
- xkb_level_index_t i, numLevels;
- enum { INTO = (1 << 0), FROM = (1 << 1) } using;
+ xkb_level_index_t i, levels_in_both;
+ struct xkb_level *level;
/* 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 ignore = (clobber ? into->type : from->type);
if (report)
- log_warn(info->keymap->ctx,
+ log_warn(info->ctx,
"Multiple definitions for group %d type of key %s; "
"Using %s, ignoring %s\n",
- group + 1, LongKeyNameText(key_name),
- xkb_atom_text(info->keymap->ctx, use),
- xkb_atom_text(info->keymap->ctx, ignore));
+ group + 1, KeyNameText(info->ctx, key_name),
+ xkb_atom_text(info->ctx, use),
+ xkb_atom_text(info->ctx, ignore));
into->type = use;
}
return true;
}
- /* First we merge the actions and ensure @into has all the levels. */
- numLevels = MAX(darray_size(into->levels), darray_size(from->levels));
- for (i = 0; i < numLevels; i++) {
- union xkb_action *intoAct, *fromAct;
+ /* Merge the actions and syms. */
+ levels_in_both = MIN(darray_size(into->levels), darray_size(from->levels));
+ for (i = 0; i < levels_in_both; i++) {
+ struct xkb_level *intoLevel = &darray_item(into->levels, i);
+ struct xkb_level *fromLevel = &darray_item(from->levels, i);
- if (i >= darray_size(from->levels))
- continue;
-
- if (i >= darray_size(into->levels)) {
- darray_append(into->levels, darray_item(from->levels, i));
- darray_item(into->levels, i).num_syms = 0;
- darray_item(into->levels, i).sym_index = 0;
- continue;
+ if (fromLevel->action.type == ACTION_TYPE_NONE) {
+ /* it's empty for consistency with other comparisons */
}
-
- intoAct = &darray_item(into->levels, i).act;
- fromAct = &darray_item(from->levels, i).act;
-
- if (fromAct->type == ACTION_TYPE_NONE) {
- }
- else if (intoAct->type == ACTION_TYPE_NONE) {
- *intoAct = *fromAct;
+ else if (intoLevel->action.type == ACTION_TYPE_NONE) {
+ intoLevel->action = fromLevel->action;
}
else {
- union xkb_action *use = (clobber ? fromAct : intoAct);
- union xkb_action *ignore = (clobber ? intoAct : fromAct);
+ union xkb_action *use, *ignore;
+ use = (clobber ? &fromLevel->action : &intoLevel->action);
+ ignore = (clobber ? &intoLevel->action : &fromLevel->action);
if (report)
- log_warn(info->keymap->ctx,
+ log_warn(info->ctx,
"Multiple actions for level %d/group %u on key %s; "
"Using %s, ignoring %s\n",
- i + 1, group + 1, LongKeyNameText(key_name),
+ i + 1, group + 1, KeyNameText(info->ctx, key_name),
ActionTypeText(use->type),
ActionTypeText(ignore->type));
- *intoAct = *use;
+ intoLevel->action = *use;
}
- }
- into->defined |= (from->defined & GROUP_FIELD_ACTS);
-
- /* Then merge the keysyms. */
- /*
- * We want to avoid copying and allocating if not necessary. So
- * here we do a pre-scan of the levels to check if we'll only use
- * @into's or @from's keysyms, and if so we'll just assign them.
- * However if one level uses @into's and another uses @from's, we
- * will need to construct a new syms array.
- */
- using = 0;
- for (i = 0; i < numLevels; i++) {
- unsigned int intoSize, fromSize;
-
- intoSize = darray_item(into->levels, i).num_syms;
- if (i < darray_size(from->levels))
- fromSize = darray_item(from->levels, i).num_syms;
- else
- fromSize = 0;
-
- if (intoSize == 0 && fromSize == 0)
- using |= 0;
- else if (intoSize == 0)
- using |= FROM;
- else if (fromSize == 0)
- using |= INTO;
- else
- using |= (clobber ? FROM : INTO);
- }
-
- if (using == 0 || using == INTO) {
- }
- else if (using == FROM) {
- darray_free(into->syms);
- into->syms = from->syms;
- darray_init(from->syms);
- for (i = 0; i < darray_size(from->levels); i++) {
- darray_item(into->levels, i).num_syms =
- darray_item(from->levels, i).num_syms;
- darray_item(into->levels, i).sym_index =
- darray_item(from->levels, i).sym_index;
+ if (fromLevel->num_syms == 0) {
+ /* it's empty for consistency with other comparisons */
}
- }
- else {
- darray_xkb_keysym_t syms = darray_new();
-
- for (i = 0; i < numLevels; i++) {
- unsigned int intoSize, fromSize;
-
- intoSize = darray_item(into->levels, i).num_syms;
- if (i < darray_size(from->levels))
- fromSize = darray_item(from->levels, i).num_syms;
+ else if (intoLevel->num_syms == 0) {
+ intoLevel->num_syms = fromLevel->num_syms;
+ if (fromLevel->num_syms > 1)
+ intoLevel->u.syms = fromLevel->u.syms;
else
- fromSize = 0;
-
- /* Empty level. */
- if (intoSize == 0 && fromSize == 0)
- continue;
-
- if (intoSize != 0 && fromSize != 0 && report)
- log_info(info->keymap->ctx,
- "Multiple symbols for group %u, level %d on key %s; "
+ intoLevel->u.sym = fromLevel->u.sym;
+ fromLevel->num_syms = 0;
+ }
+ else if (!XkbLevelsSameSyms(fromLevel, intoLevel)) {
+ if (report)
+ log_warn(info->ctx,
+ "Multiple symbols for level %d/group %u on key %s; "
"Using %s, ignoring %s\n",
- group + 1, i + 1, LongKeyNameText(key_name),
+ i + 1, group + 1, KeyNameText(info->ctx, key_name),
(clobber ? "from" : "to"),
(clobber ? "to" : "from"));
- if (intoSize == 0 || (fromSize != 0 && clobber)) {
- unsigned sym_index = darray_item(from->levels, i).sym_index;
- darray_item(into->levels, i).sym_index = darray_size(syms);
- darray_item(into->levels, i).num_syms = fromSize;
- darray_append_items(syms, &darray_item(from->syms, sym_index),
- fromSize);
- }
- else
- {
- unsigned sym_index = darray_item(into->levels, i).sym_index;
- darray_item(into->levels, i).sym_index = darray_size(syms);
- darray_item(into->levels, i).num_syms = intoSize;
- darray_append_items(syms, &darray_item(into->syms, sym_index),
- intoSize);
+ if (clobber) {
+ ClearLevelInfo(intoLevel);
+ intoLevel->num_syms = fromLevel->num_syms;
+ if (fromLevel->num_syms > 1)
+ intoLevel->u.syms = fromLevel->u.syms;
+ else
+ intoLevel->u.sym = fromLevel->u.sym;
+ fromLevel->num_syms = 0;
}
}
- darray_free(into->syms);
- into->syms = syms;
}
+ /* If @from has extra levels, get them as well. */
+ darray_foreach_from(level, from->levels, levels_in_both) {
+ darray_append(into->levels, *level);
+ level->num_syms = 0;
+ }
+ into->defined |= (from->defined & GROUP_FIELD_ACTS);
into->defined |= (from->defined & GROUP_FIELD_SYMS);
return true;
return false;
}
-
static bool
-MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from)
+MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from, bool same_file)
{
xkb_layout_index_t i;
xkb_layout_index_t groups_in_both;
enum key_field collide = 0;
- bool clobber, report;
- int verbosity = xkb_context_get_log_verbosity(info->keymap->ctx);
+ const int verbosity = xkb_context_get_log_verbosity(info->ctx);
+ const bool clobber = (from->merge != MERGE_AUGMENT);
+ const bool report = (same_file && verbosity > 0) || verbosity > 9;
if (from->merge == MERGE_REPLACE) {
ClearKeyInfo(into);
*into = *from;
- InitKeyInfo(from, info->file_id);
+ InitKeyInfo(info->ctx, from);
return true;
}
- clobber = (from->merge != MERGE_AUGMENT);
- report = (verbosity > 9 ||
- (into->file_id == from->file_id && verbosity > 0));
-
- groups_in_both = MIN(darray_size(into->groups),
- darray_size(from->groups));
+ groups_in_both = MIN(darray_size(into->groups), darray_size(from->groups));
for (i = 0; i < groups_in_both; i++)
MergeGroups(info,
&darray_item(into->groups, i),
into->repeat = from->repeat;
into->defined |= KEY_FIELD_REPEAT;
}
- if (UseNewKeyField(KEY_FIELD_TYPE_DFLT, into->defined, from->defined,
+ if (UseNewKeyField(KEY_FIELD_DEFAULT_TYPE, into->defined, from->defined,
clobber, report, &collide)) {
- into->dfltType = from->dfltType;
- into->defined |= KEY_FIELD_TYPE_DFLT;
+ into->default_type = from->default_type;
+ into->defined |= KEY_FIELD_DEFAULT_TYPE;
}
if (UseNewKeyField(KEY_FIELD_GROUPINFO, into->defined, from->defined,
clobber, report, &collide)) {
}
if (collide)
- log_warn(info->keymap->ctx,
+ log_warn(info->ctx,
"Symbol map for key %s redefined; "
"Using %s definition for conflicting fields\n",
- LongKeyNameText(into->name),
+ KeyNameText(info->ctx, into->name),
(clobber ? "first" : "last"));
ClearKeyInfo(from);
- InitKeyInfo(from, info->file_id);
+ InitKeyInfo(info->ctx, from);
return true;
}
+/* TODO: Make it so this function doesn't need the entire keymap. */
static bool
-AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi)
+AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi, bool same_file)
{
- unsigned long real_name;
+ xkb_atom_t real_name;
KeyInfo *iter;
/*
* following loop) is enough, and we won't get multiple KeyInfo's
* for the same key because of aliases.
*/
- if (FindKeyNameForAlias(info->keymap, keyi->name, &real_name))
+ real_name = XkbResolveKeyAlias(info->keymap, keyi->name);
+ if (real_name != XKB_ATOM_NONE)
keyi->name = real_name;
darray_foreach(iter, info->keys)
if (iter->name == keyi->name)
- return MergeKeys(info, iter, keyi);
+ return MergeKeys(info, iter, keyi, same_file);
darray_append(info->keys, *keyi);
- InitKeyInfo(keyi, info->file_id);
+ InitKeyInfo(info->ctx, keyi);
return true;
}
static bool
-AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
+AddModMapEntry(SymbolsInfo *info, ModMapEntry *new)
{
- ModMapEntry *mm;
- bool clobber;
-
- clobber = (new->merge != MERGE_AUGMENT);
- darray_foreach(mm, info->modMaps) {
- if (new->haveSymbol && mm->haveSymbol
- && (new->u.keySym == mm->u.keySym)) {
- unsigned use, ignore;
- if (mm->modifier != new->modifier) {
- if (clobber) {
- use = new->modifier;
- ignore = mm->modifier;
- }
- else {
- use = mm->modifier;
- ignore = new->modifier;
- }
- 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));
- mm->modifier = use;
- }
- return true;
- }
- if ((!new->haveSymbol) && (!mm->haveSymbol) &&
- (new->u.keyName == mm->u.keyName)) {
- unsigned use, ignore;
- if (mm->modifier != new->modifier) {
- if (clobber) {
- use = new->modifier;
- ignore = mm->modifier;
- }
- else {
- use = mm->modifier;
- ignore = new->modifier;
- }
- log_err(info->keymap->ctx,
- "Key %s added to map for multiple modifiers; "
- "Using %s, ignoring %s.\n",
- LongKeyNameText(new->u.keyName), ModIndexText(use),
- ModIndexText(ignore));
- mm->modifier = use;
- }
+ ModMapEntry *old;
+ bool clobber = (new->merge != MERGE_AUGMENT);
+
+ darray_foreach(old, info->modmaps) {
+ xkb_mod_index_t use, ignore;
+
+ if ((new->haveSymbol != old->haveSymbol) ||
+ (new->haveSymbol && new->u.keySym != old->u.keySym) ||
+ (!new->haveSymbol && new->u.keyName != old->u.keyName))
+ continue;
+
+ if (new->modifier == old->modifier)
return true;
- }
+
+ use = (clobber ? new->modifier : old->modifier);
+ ignore = (clobber ? old->modifier : new->modifier);
+
+ if (new->haveSymbol)
+ log_warn(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_warn(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));
+
+ old->modifier = use;
+ return true;
}
- darray_append(info->modMaps, *new);
+ darray_append(info->modmaps, *new);
return true;
}
MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
enum merge_mode merge)
{
- unsigned int i;
- KeyInfo *keyi;
- ModMapEntry *mm;
xkb_atom_t *group_name;
xkb_layout_index_t group_names_in_both;
return;
}
+ into->mods = from->mods;
+
if (into->name == NULL) {
into->name = from->name;
from->name = NULL;
group_names_in_both = MIN(darray_size(into->group_names),
darray_size(from->group_names));
- for (i = 0; i < group_names_in_both; i++) {
+ for (xkb_layout_index_t i = 0; i < group_names_in_both; i++) {
if (!darray_item(from->group_names, i))
continue;
darray_foreach_from(group_name, from->group_names, group_names_in_both)
darray_append(into->group_names, *group_name);
- darray_foreach(keyi, from->keys) {
- merge = (merge == MERGE_DEFAULT ? keyi->merge : merge);
- if (!AddKeySymbols(into, keyi))
- into->errorCount++;
+ if (darray_empty(into->keys)) {
+ into->keys = from->keys;
+ darray_init(from->keys);
+ }
+ else {
+ KeyInfo *keyi;
+ darray_foreach(keyi, from->keys) {
+ keyi->merge = (merge == MERGE_DEFAULT ? keyi->merge : merge);
+ if (!AddKeySymbols(into, keyi, false))
+ into->errorCount++;
+ }
}
- darray_foreach(mm, from->modMaps) {
- mm->merge = (merge == MERGE_DEFAULT ? mm->merge : merge);
- if (!AddModMapEntry(into, mm))
- into->errorCount++;
+ if (darray_empty(into->modmaps)) {
+ into->modmaps = from->modmaps;
+ darray_init(from->modmaps);
+ }
+ else {
+ ModMapEntry *mm;
+ darray_foreach(mm, from->modmaps) {
+ mm->merge = (merge == MERGE_DEFAULT ? mm->merge : merge);
+ if (!AddModMapEntry(into, mm))
+ into->errorCount++;
+ }
}
}
HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge);
static bool
-HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *stmt)
+HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *include)
{
- enum merge_mode merge = MERGE_DEFAULT;
- XkbFile *rtrn;
- SymbolsInfo included, next_incl;
+ SymbolsInfo included;
- InitSymbolsInfo(&included, info->keymap, info->file_id, info->actions);
- if (stmt->stmt) {
- free(included.name);
- included.name = stmt->stmt;
- stmt->stmt = NULL;
- }
+ InitSymbolsInfo(&included, info->keymap, info->actions, &info->mods);
+ included.name = include->stmt;
+ include->stmt = NULL;
+
+ for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
+ SymbolsInfo next_incl;
+ XkbFile *file;
- for (; stmt; stmt = stmt->next_incl) {
- if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_SYMBOLS,
- &rtrn, &merge)) {
+ file = ProcessIncludeFile(info->ctx, stmt, FILE_TYPE_SYMBOLS);
+ if (!file) {
info->errorCount += 10;
ClearSymbolsInfo(&included);
return false;
}
- InitSymbolsInfo(&next_incl, info->keymap, rtrn->id, info->actions);
- next_incl.merge = next_incl.dflt.merge = MERGE_OVERRIDE;
+ InitSymbolsInfo(&next_incl, info->keymap, info->actions,
+ &included.mods);
if (stmt->modifier) {
next_incl.explicit_group = atoi(stmt->modifier) - 1;
- if (next_incl.explicit_group >= XKB_NUM_GROUPS) {
- log_err(info->keymap->ctx,
+ if (next_incl.explicit_group >= XKB_MAX_GROUPS) {
+ log_err(info->ctx,
"Cannot set explicit group to %d - must be between 1..%d; "
"Ignoring group number\n",
- next_incl.explicit_group + 1, XKB_NUM_GROUPS);
+ next_incl.explicit_group + 1, XKB_MAX_GROUPS);
next_incl.explicit_group = info->explicit_group;
}
}
next_incl.explicit_group = info->explicit_group;
}
- HandleSymbolsFile(&next_incl, rtrn, MERGE_OVERRIDE);
+ HandleSymbolsFile(&next_incl, file, MERGE_OVERRIDE);
- MergeIncludedSymbols(&included, &next_incl, merge);
+ MergeIncludedSymbols(&included, &next_incl, stmt->merge);
ClearSymbolsInfo(&next_incl);
- FreeXkbFile(rtrn);
+ FreeXkbFile(file);
}
- MergeIncludedSymbols(info, &included, merge);
+ MergeIncludedSymbols(info, &included, include->merge);
ClearSymbolsInfo(&included);
return (info->errorCount == 0);
}
}
- if (i >= XKB_NUM_GROUPS) {
- log_err(info->keymap->ctx,
+ if (i >= XKB_MAX_GROUPS) {
+ log_err(info->ctx,
"Too many groups of %s for key %s (max %u); "
"Ignoring %s defined for extra groups\n",
- name, LongKeyNameText(keyi->name), XKB_NUM_GROUPS + 1, name);
+ name, KeyInfoText(info, keyi), XKB_MAX_GROUPS, name);
return false;
}
return true;
}
- if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, ndx_rtrn)) {
- log_err(info->keymap->ctx,
+ if (!ExprResolveGroup(info->ctx, arrayNdx, ndx_rtrn)) {
+ log_err(info->ctx,
"Illegal group index for %s of key %s\n"
"Definition with non-integer array index ignored\n",
- name, LongKeyNameText(keyi->name));
+ name, KeyInfoText(info, keyi));
return false;
}
return true;
}
-bool
-LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn)
-{
- xkb_keysym_t sym;
-
- if (!str || istreq(str, "any") || istreq(str, "nosymbol")) {
- *sym_rtrn = XKB_KEY_NoSymbol;
- return 1;
- }
-
- if (istreq(str, "none") || istreq(str, "voidsymbol")) {
- *sym_rtrn = XKB_KEY_VoidSymbol;
- return 1;
- }
-
- sym = xkb_keysym_from_name(str);
- if (sym != XKB_KEY_NoSymbol) {
- *sym_rtrn = sym;
- return 1;
- }
-
- return 0;
-}
-
static bool
AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
ExprDef *value)
{
xkb_layout_index_t ndx;
GroupInfo *groupi;
- unsigned int nSyms;
xkb_level_index_t nLevels;
- xkb_level_index_t i;
- int j;
if (!GetGroupIndex(info, keyi, arrayNdx, SYMBOLS, &ndx))
return false;
return true;
}
- if (value->op != EXPR_KEYSYM_LIST) {
- log_err(info->keymap->ctx,
+ if (value->expr.op != EXPR_KEYSYM_LIST) {
+ log_err(info->ctx,
"Expected a list of symbols, found %s; "
"Ignoring symbols for group %u of %s\n",
- expr_op_type_to_string(value->op), ndx + 1,
- LongKeyNameText(keyi->name));
+ expr_op_type_to_string(value->expr.op), ndx + 1,
+ KeyInfoText(info, keyi));
return false;
}
if (groupi->defined & GROUP_FIELD_SYMS) {
- log_err(info->keymap->ctx,
+ log_err(info->ctx,
"Symbols for key %s, group %u already defined; "
"Ignoring duplicate definition\n",
- LongKeyNameText(keyi->name), ndx + 1);
+ KeyInfoText(info, keyi), ndx + 1);
return false;
}
- nSyms = darray_size(value->value.list.syms);
- nLevels = darray_size(value->value.list.symsMapIndex);
-
- if (darray_size(groupi->syms) < nSyms)
- darray_resize0(groupi->syms, nSyms);
-
+ nLevels = darray_size(value->keysym_list.symsMapIndex);
if (darray_size(groupi->levels) < nLevels)
darray_resize0(groupi->levels, nLevels);
groupi->defined |= GROUP_FIELD_SYMS;
- for (i = 0; i < nLevels; i++) {
- LevelInfo *leveli = &darray_item(groupi->levels, i);
-
- leveli->sym_index = darray_item(value->value.list.symsMapIndex, i);
- leveli->num_syms = darray_item(value->value.list.symsNumEntries, i);
-
- for (j = 0; j < leveli->num_syms; j++) {
- if (!LookupKeysym(darray_item(value->value.list.syms,
- leveli->sym_index + j),
- &darray_item(groupi->syms,
- leveli->sym_index + j))) {
- const char *group_name = "unnamed";
-
- if (ndx < darray_size(info->group_names) &&
- darray_item(info->group_names, ndx))
- group_name = xkb_atom_text(info->keymap->ctx,
- darray_item(info->group_names,
- ndx));
-
- log_warn(info->keymap->ctx,
- "Could not resolve keysym %s for key %s, group %u (%s), level %u\n",
- darray_item(value->value.list.syms, i),
- LongKeyNameText(keyi->name),
- ndx + 1, group_name, nSyms);
-
- leveli->sym_index = 0;
- leveli->num_syms = 0;
- break;
- }
+ for (xkb_level_index_t i = 0; i < nLevels; i++) {
+ unsigned int sym_index;
+ struct xkb_level *leveli = &darray_item(groupi->levels, i);
+
+ sym_index = darray_item(value->keysym_list.symsMapIndex, i);
+ leveli->num_syms = darray_item(value->keysym_list.symsNumEntries, i);
+ if (leveli->num_syms > 1)
+ leveli->u.syms = calloc(leveli->num_syms, sizeof(*leveli->u.syms));
- if (leveli->num_syms == 1 &&
- darray_item(groupi->syms,
- leveli->sym_index + j) == XKB_KEY_NoSymbol) {
- leveli->sym_index = 0;
- leveli->num_syms = 0;
+ for (unsigned j = 0; j < leveli->num_syms; j++) {
+ xkb_keysym_t keysym = darray_item(value->keysym_list.syms,
+ sym_index + j);
+
+ if (leveli->num_syms == 1) {
+ if (keysym == XKB_KEY_NoSymbol)
+ leveli->num_syms = 0;
+ else
+ leveli->u.sym = keysym;
+ }
+ else if (leveli->num_syms > 1) {
+ leveli->u.syms[j] = keysym;
}
}
}
AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
ExprDef *value)
{
- unsigned int i;
xkb_layout_index_t ndx;
GroupInfo *groupi;
unsigned int nActs;
ExprDef *act;
- union xkb_action *toAct;
if (!GetGroupIndex(info, keyi, arrayNdx, ACTIONS, &ndx))
return false;
return true;
}
- if (value->op != EXPR_ACTION_LIST) {
- log_wsgo(info->keymap->ctx,
+ if (value->expr.op != EXPR_ACTION_LIST) {
+ log_wsgo(info->ctx,
"Bad expression type (%d) for action list value; "
"Ignoring actions for group %u of %s\n",
- value->op, ndx, LongKeyNameText(keyi->name));
+ value->expr.op, ndx, KeyInfoText(info, keyi));
return false;
}
if (groupi->defined & GROUP_FIELD_ACTS) {
- log_wsgo(info->keymap->ctx,
+ log_wsgo(info->ctx,
"Actions for key %s, group %u already defined\n",
- LongKeyNameText(keyi->name), ndx);
+ KeyInfoText(info, keyi), ndx);
return false;
}
nActs = 0;
- for (act = value->value.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->value.child;
- for (i = 0; i < nActs; i++) {
- toAct = &darray_item(groupi->levels, i).act;
+ act = value->actions.actions;
+ for (unsigned i = 0; i < nActs; i++) {
+ union xkb_action *toAct = &darray_item(groupi->levels, i).action;
- if (!HandleActionDef(act, info->keymap, toAct, info->actions))
- log_err(info->keymap->ctx,
+ if (!HandleActionDef(info->ctx, info->actions, &info->mods, act, toAct))
+ log_err(info->ctx,
"Illegal action definition for %s; "
"Action for group %u/level %u ignored\n",
- LongKeyNameText(keyi->name), ndx + 1, i + 1);
+ KeyInfoText(info, keyi), ndx + 1, i + 1);
act = (ExprDef *) act->common.next;
}
SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
ExprDef *arrayNdx, ExprDef *value)
{
- bool ok = true;
- struct xkb_context *ctx = info->keymap->ctx;
-
if (istreq(field, "type")) {
xkb_layout_index_t ndx;
xkb_atom_t val;
- if (!ExprResolveString(ctx, value, &val))
- log_vrb(ctx, 1,
+ if (!ExprResolveString(info->ctx, value, &val)) {
+ log_err(info->ctx,
"The type field of a key symbol map must be a string; "
"Ignoring illegal type definition\n");
+ return false;
+ }
- if (arrayNdx == NULL) {
- keyi->dfltType = val;
- keyi->defined |= KEY_FIELD_TYPE_DFLT;
+ if (!arrayNdx) {
+ keyi->default_type = val;
+ keyi->defined |= KEY_FIELD_DEFAULT_TYPE;
}
- else if (!ExprResolveGroup(ctx, arrayNdx, &ndx)) {
- log_err(ctx,
+ else if (!ExprResolveGroup(info->ctx, arrayNdx, &ndx)) {
+ log_err(info->ctx,
"Illegal group index for type of key %s; "
"Definition with non-integer array index ignored\n",
- LongKeyNameText(keyi->name));
+ KeyInfoText(info, keyi));
return false;
}
else {
darray_item(keyi->groups, ndx).defined |= GROUP_FIELD_TYPE;
}
}
- else if (istreq(field, "symbols"))
+ else if (istreq(field, "symbols")) {
return AddSymbolsToKey(info, keyi, arrayNdx, value);
- else if (istreq(field, "actions"))
+ }
+ else if (istreq(field, "actions")) {
return AddActionsToKey(info, keyi, arrayNdx, value);
+ }
else if (istreq(field, "vmods") ||
istreq(field, "virtualmods") ||
istreq(field, "virtualmodifiers")) {
xkb_mod_mask_t mask;
- ok = ExprResolveVModMask(info->keymap, value, &mask);
- if (ok) {
- keyi->vmodmap = (mask >> XKB_NUM_CORE_MODS) & 0xffff;
- keyi->defined |= KEY_FIELD_VMODMAP;
- }
- else {
- log_err(info->keymap->ctx,
+ if (!ExprResolveModMask(info->ctx, value, MOD_VIRT, &info->mods,
+ &mask)) {
+ log_err(info->ctx,
"Expected a virtual modifier mask, found %s; "
"Ignoring virtual modifiers definition for key %s\n",
- expr_op_type_to_string(value->op),
- LongKeyNameText(keyi->name));
+ expr_op_type_to_string(value->expr.op),
+ KeyInfoText(info, keyi));
+ return false;
}
+
+ keyi->vmodmap = mask;
+ keyi->defined |= KEY_FIELD_VMODMAP;
}
else if (istreq(field, "locking") ||
istreq(field, "lock") ||
istreq(field, "locks")) {
- log_err(info->keymap->ctx,
+ log_vrb(info->ctx, 1,
"Key behaviors not supported; "
"Ignoring locking specification for key %s\n",
- LongKeyNameText(keyi->name));
+ KeyInfoText(info, keyi));
}
else if (istreq(field, "radiogroup") ||
istreq(field, "permanentradiogroup") ||
istreq(field, "allownone")) {
- log_err(info->keymap->ctx,
+ log_vrb(info->ctx, 1,
"Radio groups not supported; "
"Ignoring radio group specification for key %s\n",
- LongKeyNameText(keyi->name));
+ KeyInfoText(info, keyi));
}
else if (istreq_prefix("overlay", field) ||
istreq_prefix("permanentoverlay", field)) {
- log_err(info->keymap->ctx,
+ log_vrb(info->ctx, 1,
"Overlays not supported; "
"Ignoring overlay specification for key %s\n",
- LongKeyNameText(keyi->name));
+ KeyInfoText(info, keyi));
}
else if (istreq(field, "repeating") ||
istreq(field, "repeats") ||
istreq(field, "repeat")) {
unsigned int val;
- ok = ExprResolveEnum(ctx, value, &val, repeatEntries);
- if (!ok) {
- log_err(info->keymap->ctx,
+ if (!ExprResolveEnum(info->ctx, value, &val, repeatEntries)) {
+ log_err(info->ctx,
"Illegal repeat setting for %s; "
"Non-boolean repeat setting ignored\n",
- LongKeyNameText(keyi->name));
+ KeyInfoText(info, keyi));
return false;
}
+
keyi->repeat = val;
keyi->defined |= KEY_FIELD_REPEAT;
}
istreq(field, "wrapgroups")) {
bool set;
- if (!ExprResolveBoolean(ctx, value, &set)) {
- log_err(info->keymap->ctx,
+ if (!ExprResolveBoolean(info->ctx, value, &set)) {
+ log_err(info->ctx,
"Illegal groupsWrap setting for %s; "
"Non-boolean value ignored\n",
- LongKeyNameText(keyi->name));
+ KeyInfoText(info, keyi));
return false;
}
- if (set)
- keyi->out_of_range_group_action = RANGE_WRAP;
- else
- keyi->out_of_range_group_action = RANGE_SATURATE;
-
+ keyi->out_of_range_group_action = (set ? RANGE_WRAP : RANGE_SATURATE);
keyi->defined |= KEY_FIELD_GROUPINFO;
}
else if (istreq(field, "groupsclamp") ||
istreq(field, "clampgroups")) {
bool set;
- if (!ExprResolveBoolean(ctx, value, &set)) {
- log_err(info->keymap->ctx,
+ if (!ExprResolveBoolean(info->ctx, value, &set)) {
+ log_err(info->ctx,
"Illegal groupsClamp setting for %s; "
"Non-boolean value ignored\n",
- LongKeyNameText(keyi->name));
+ KeyInfoText(info, keyi));
return false;
}
- if (set)
- keyi->out_of_range_group_action = RANGE_SATURATE;
- else
- keyi->out_of_range_group_action = RANGE_WRAP;
-
+ keyi->out_of_range_group_action = (set ? RANGE_SATURATE : RANGE_WRAP);
keyi->defined |= KEY_FIELD_GROUPINFO;
}
else if (istreq(field, "groupsredirect") ||
istreq(field, "redirectgroups")) {
xkb_layout_index_t grp;
- if (!ExprResolveGroup(ctx, value, &grp)) {
- log_err(info->keymap->ctx,
+ if (!ExprResolveGroup(info->ctx, value, &grp)) {
+ log_err(info->ctx,
"Illegal group index for redirect of key %s; "
"Definition with non-integer group ignored\n",
- LongKeyNameText(keyi->name));
+ KeyInfoText(info, keyi));
return false;
}
keyi->defined |= KEY_FIELD_GROUPINFO;
}
else {
- log_err(info->keymap->ctx,
+ log_err(info->ctx,
"Unknown field %s in a symbol interpretation; "
"Definition ignored\n",
field);
- ok = false;
+ return false;
}
- return ok;
+ return true;
}
-static int
+static bool
SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
{
- xkb_layout_index_t grp, grp_to_use;
+ xkb_layout_index_t group, group_to_use;
xkb_atom_t name;
if (!arrayNdx) {
- log_vrb(info->keymap->ctx, 1,
+ log_vrb(info->ctx, 1,
"You must specify an index when specifying a group name; "
"Group name definition without array subscript ignored\n");
return false;
}
- if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &grp)) {
- log_err(info->keymap->ctx,
+ if (!ExprResolveGroup(info->ctx, arrayNdx, &group)) {
+ log_err(info->ctx,
"Illegal index in group name definition; "
"Definition with non-integer array index ignored\n");
return false;
}
- if (!ExprResolveString(info->keymap->ctx, value, &name)) {
- log_err(info->keymap->ctx,
+ if (!ExprResolveString(info->ctx, value, &name)) {
+ log_err(info->ctx,
"Group name must be a string; "
- "Illegal name for group %d ignored\n", grp);
+ "Illegal name for group %d ignored\n", group);
return false;
}
- grp_to_use = XKB_LAYOUT_INVALID;
if (info->explicit_group == XKB_LAYOUT_INVALID) {
- grp_to_use = grp - 1;
+ group_to_use = group - 1;
}
- else if (grp - 1 == 0) {
- grp_to_use = info->explicit_group;
+ else if (group - 1 == 0) {
+ group_to_use = info->explicit_group;
}
else {
- log_warn(info->keymap->ctx,
+ log_warn(info->ctx,
"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",
- info->name, grp,
- xkb_atom_text(info->keymap->ctx, name));
+ info->name, group,
+ xkb_atom_text(info->ctx, name));
return false;
}
- if (grp_to_use >= darray_size(info->group_names))
- darray_resize0(info->group_names, grp_to_use + 1);
- darray_item(info->group_names, grp_to_use) = name;
+ if (group_to_use >= darray_size(info->group_names))
+ darray_resize0(info->group_names, group_to_use + 1);
+ darray_item(info->group_names, group_to_use) = name;
+
return true;
}
-static int
+static bool
HandleGlobalVar(SymbolsInfo *info, VarDef *stmt)
{
const char *elem, *field;
ExprDef *arrayNdx;
bool ret;
- if (ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field,
- &arrayNdx) == 0)
- return 0; /* internal error, already reported */
+ if (!ExprResolveLhs(info->ctx, stmt->name, &elem, &field, &arrayNdx))
+ return false;
+
if (elem && istreq(elem, "key")) {
- ret = SetSymbolsField(info, &info->dflt, field, arrayNdx,
+ ret = SetSymbolsField(info, &info->default_key, field, arrayNdx,
stmt->value);
}
else if (!elem && (istreq(field, "name") ||
}
else if (!elem && (istreq(field, "groupswrap") ||
istreq(field, "wrapgroups"))) {
- log_err(info->keymap->ctx,
+ log_err(info->ctx,
"Global \"groupswrap\" not supported; Ignored\n");
ret = true;
}
else if (!elem && (istreq(field, "groupsclamp") ||
istreq(field, "clampgroups"))) {
- log_err(info->keymap->ctx,
+ log_err(info->ctx,
"Global \"groupsclamp\" not supported; Ignored\n");
ret = true;
}
else if (!elem && (istreq(field, "groupsredirect") ||
istreq(field, "redirectgroups"))) {
- log_err(info->keymap->ctx,
+ log_err(info->ctx,
"Global \"groupsredirect\" not supported; Ignored\n");
ret = true;
}
else if (!elem && istreq(field, "allownone")) {
- log_err(info->keymap->ctx,
+ log_err(info->ctx,
"Radio groups not supported; "
"Ignoring \"allownone\" specification\n");
ret = true;
}
else {
- ret = SetActionField(info->keymap, elem, field, arrayNdx, stmt->value,
- info->actions);
+ ret = SetActionField(info->ctx, info->actions, &info->mods,
+ elem, field, arrayNdx, stmt->value);
}
return ret;
ExprDef *arrayNdx;
for (; def; def = (VarDef *) def->common.next) {
- if (def->name && def->name->op == EXPR_FIELD_REF) {
- log_err(info->keymap->ctx,
+ if (def->name && def->name->expr.op == EXPR_FIELD_REF) {
+ log_err(info->ctx,
"Cannot set a global default value from within a key statement; "
"Move statements to the global file scope\n");
continue;
}
if (!def->name) {
- if (!def->value || def->value->op == EXPR_KEYSYM_LIST)
+ if (!def->value || def->value->expr.op == EXPR_KEYSYM_LIST)
field = "symbols";
else
field = "actions";
arrayNdx = NULL;
}
else {
- ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
+ ok = ExprResolveLhs(info->ctx, def->name, &elem, &field,
&arrayNdx);
}
if (groupi->defined) {
warn = true;
ClearGroupInfo(groupi);
+ InitGroupInfo(groupi);
}
}
if (warn)
- log_warn(info->keymap->ctx,
+ log_warn(info->ctx,
"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, LongKeyNameText(keyi->name));
+ info->name, KeyInfoText(info, keyi));
darray_resize0(keyi->groups, info->explicit_group + 1);
if (info->explicit_group > 0) {
return true;
}
-static int
+static bool
HandleSymbolsDef(SymbolsInfo *info, SymbolsDef *stmt)
{
KeyInfo keyi;
- xkb_layout_index_t i;
- keyi = info->dflt;
+ keyi = info->default_key;
darray_init(keyi.groups);
- darray_copy(keyi.groups, info->dflt.groups);
- for (i = 0; i < darray_size(keyi.groups); i++) {
- darray_init(darray_item(keyi.groups, i).syms);
- darray_copy(darray_item(keyi.groups, i).syms,
- darray_item(info->dflt.groups, i).syms);
- darray_init(darray_item(keyi.groups, i).levels);
- darray_copy(darray_item(keyi.groups, i).levels,
- darray_item(info->dflt.groups, i).levels);
- }
+ darray_copy(keyi.groups, info->default_key.groups);
+ for (xkb_layout_index_t i = 0; i < darray_size(keyi.groups); i++)
+ CopyGroupInfo(&darray_item(keyi.groups, i),
+ &darray_item(info->default_key.groups, i));
keyi.merge = stmt->merge;
- keyi.name = KeyNameToLong(stmt->keyName);
+ keyi.name = stmt->keyName;
- if (!HandleSymbolsBody(info, (VarDef *) stmt->symbols, &keyi)) {
+ if (!HandleSymbolsBody(info, stmt->symbols, &keyi)) {
info->errorCount++;
return false;
}
return false;
}
- if (!AddKeySymbols(info, &keyi)) {
+ if (!AddKeySymbols(info, &keyi, true)) {
info->errorCount++;
return false;
}
static bool
HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
{
- ExprDef *key;
ModMapEntry tmp;
xkb_mod_index_t ndx;
bool ok;
- struct xkb_context *ctx = info->keymap->ctx;
-
- if (!LookupModIndex(ctx, NULL, def->modifier, EXPR_TYPE_INT, &ndx)) {
- log_err(info->keymap->ctx,
- "Illegal modifier map definition; "
- "Ignoring map for non-modifier \"%s\"\n",
- xkb_atom_text(ctx, def->modifier));
- return false;
+ struct xkb_context *ctx = info->ctx;
+ 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;
tmp.modifier = ndx;
+ tmp.merge = def->merge;
- for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) {
+ for (ExprDef *key = def->keys; key; key = (ExprDef *) key->common.next) {
xkb_keysym_t sym;
- if (key->op == EXPR_VALUE && key->value_type == EXPR_TYPE_KEYNAME) {
+ if (key->expr.op == EXPR_VALUE &&
+ key->expr.value_type == EXPR_TYPE_KEYNAME) {
tmp.haveSymbol = false;
- tmp.u.keyName = KeyNameToLong(key->value.keyName);
+ tmp.u.keyName = key->key_name.key_name;
}
else if (ExprResolveKeySym(ctx, key, &sym)) {
tmp.haveSymbol = true;
tmp.u.keySym = sym;
}
else {
- log_err(info->keymap->ctx,
+ log_err(info->ctx,
"Modmap entries may contain only key names or keysyms; "
"Illegal definition for %s modifier ignored\n",
- ModIndexText(tmp.modifier));
+ ModIndexText(info->ctx, &info->mods, tmp.modifier));
continue;
}
HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
{
bool ok;
- ParseCommon *stmt;
free(info->name);
info->name = strdup_safe(file->name);
- stmt = file->defs;
- for (stmt = file->defs; stmt; stmt = stmt->next) {
+ for (ParseCommon *stmt = file->defs; stmt; stmt = stmt->next) {
switch (stmt->type) {
case STMT_INCLUDE:
ok = HandleIncludeSymbols(info, (IncludeStmt *) stmt);
ok = HandleGlobalVar(info, (VarDef *) stmt);
break;
case STMT_VMOD:
- ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
- &info->vmods);
+ ok = HandleVModDef(info->ctx, &info->mods, (VModDef *) stmt, merge);
break;
case STMT_MODMAP:
ok = HandleModMapDef(info, (ModMapDef *) stmt);
break;
default:
- log_err(info->keymap->ctx,
- "Interpretation files may not include other types; "
+ log_err(info->ctx,
+ "Symbols files may not include other types; "
"Ignoring %s\n", stmt_type_to_string(stmt->type));
ok = false;
break;
info->errorCount++;
if (info->errorCount > 10) {
- log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n",
- file->topName);
+ log_err(info->ctx, "Abandoning symbols file \"%s\"\n",
+ file->name);
break;
}
}
static struct xkb_key *
FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
{
- struct xkb_key *key, *ret = NULL;
- xkb_layout_index_t group, min_group = UINT32_MAX;
- xkb_level_index_t level, min_level = UINT16_MAX;
-
- xkb_foreach_key(key, keymap) {
- for (group = 0; group < key->num_groups; group++) {
- for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
- level++) {
- if (XkbKeyNumSyms(key, group, level) != 1 ||
- (XkbKeySymEntry(key, group, level))[0] != sym)
- continue;
-
- /*
- * If the keysym was found in a group or level > 0, we must
- * keep looking since we might find a key in which the keysym
- * is in a lower group or level.
- */
- if (group < min_group ||
- (group == min_group && level < min_level)) {
- ret = key;
- if (group == 0 && level == 0) {
- return ret;
- }
- else {
- min_group = group;
- min_level = level;
- }
+ struct xkb_key *key;
+ xkb_layout_index_t group;
+ bool got_one_group, got_one_level;
+
+ group = 0;
+ do {
+ xkb_level_index_t level = 0;
+ got_one_group = false;
+ do {
+ got_one_level = false;
+ xkb_keys_foreach(key, keymap) {
+ if (group < key->num_groups &&
+ level < XkbKeyNumLevels(key, group)) {
+ got_one_group = got_one_level = true;
+ if (key->groups[group].levels[level].num_syms == 1 &&
+ key->groups[group].levels[level].u.sym == sym)
+ return key;
}
}
- }
- }
+ level++;
+ } while (got_one_level);
+ group++;
+ } while (got_one_group);
- return ret;
+ return NULL;
}
-static bool
-FindNamedType(struct xkb_keymap *keymap, xkb_atom_t name, unsigned *type_rtrn)
-{
- unsigned int i;
-
- for (i = 0; i < keymap->num_types; i++) {
- if (keymap->types[i].name == name) {
- *type_rtrn = i;
- return true;
- }
- }
-
- return false;
-}
-
-/**
- * Assign a type to the given sym and return the Atom for the type assigned.
+/*
+ * Find an appropriate type for a group and return its name.
*
* Simple recipe:
* - ONE_LEVEL for width 0/1
- * - ALPHABETIC for 2 shift levels, with lower/upercase
+ * - ALPHABETIC for 2 shift levels, with lower/upercase keysyms
* - KEYPAD for keypad keys.
* - TWO_LEVEL for other 2 shift level keys.
* and the same for four level keys.
*
- * @param width Number of sysms in syms.
- * @param syms The keysyms for the given key (must be size width).
- * @param typeNameRtrn Set to the Atom of the type name.
- *
- * @returns true if a type could be found, false otherwise.
- *
- * FIXME: I need to take the KeyInfo so I can look at symsMapIndex and
- * all that fun stuff rather than just assuming there's always one
- * symbol per level.
+ * FIXME: Decide how to handle multiple-syms-per-level, and do it.
*/
-static bool
-FindAutomaticType(struct xkb_context *ctx, xkb_level_index_t width,
- const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
- bool *autoType)
+static xkb_atom_t
+FindAutomaticType(struct xkb_context *ctx, GroupInfo *groupi)
{
- *autoType = false;
- if ((width == 1) || (width == 0)) {
- *typeNameRtrn = xkb_atom_intern(ctx, "ONE_LEVEL");
- *autoType = true;
- }
- else if (width == 2) {
- if (syms && xkb_keysym_is_lower(syms[0]) &&
- xkb_keysym_is_upper(syms[1])) {
- *typeNameRtrn = xkb_atom_intern(ctx, "ALPHABETIC");
+ xkb_keysym_t sym0, sym1;
+ const xkb_level_index_t width = darray_size(groupi->levels);
+
+#define GET_SYM(level) \
+ (darray_item(groupi->levels, level).num_syms == 0 ? \
+ XKB_KEY_NoSymbol : \
+ darray_item(groupi->levels, level).num_syms == 1 ? \
+ darray_item(groupi->levels, level).u.sym : \
+ /* num_syms > 1 */ \
+ darray_item(groupi->levels, level).u.syms[0])
+
+ if (width == 1 || width <= 0)
+ return xkb_atom_intern_literal(ctx, "ONE_LEVEL");
+
+ sym0 = GET_SYM(0);
+ sym1 = GET_SYM(1);
+
+ if (width == 2) {
+ if (xkb_keysym_is_lower(sym0) && xkb_keysym_is_upper(sym1))
+ return xkb_atom_intern_literal(ctx, "ALPHABETIC");
+
+ if (xkb_keysym_is_keypad(sym0) || xkb_keysym_is_keypad(sym1))
+ return xkb_atom_intern_literal(ctx, "KEYPAD");
+
+ return xkb_atom_intern_literal(ctx, "TWO_LEVEL");
+ }
+
+ if (width <= 4) {
+ if (xkb_keysym_is_lower(sym0) && xkb_keysym_is_upper(sym1)) {
+ xkb_keysym_t sym2, sym3;
+ sym2 = GET_SYM(2);
+ sym3 = (width == 4 ? GET_SYM(3) : XKB_KEY_NoSymbol);
+
+ if (xkb_keysym_is_lower(sym2) && xkb_keysym_is_upper(sym3))
+ return xkb_atom_intern_literal(ctx, "FOUR_LEVEL_ALPHABETIC");
+
+ return xkb_atom_intern_literal(ctx, "FOUR_LEVEL_SEMIALPHABETIC");
}
- else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
- xkb_keysym_is_keypad(syms[1]))) {
- *typeNameRtrn = xkb_atom_intern(ctx, "KEYPAD");
- *autoType = true;
+
+ if (xkb_keysym_is_keypad(sym0) || xkb_keysym_is_keypad(sym1))
+ return xkb_atom_intern_literal(ctx, "FOUR_LEVEL_KEYPAD");
+
+ return xkb_atom_intern_literal(ctx, "FOUR_LEVEL");
+ }
+
+ return XKB_ATOM_NONE;
+
+#undef GET_SYM
+}
+
+static const struct xkb_key_type *
+FindTypeForGroup(struct xkb_keymap *keymap, KeyInfo *keyi,
+ xkb_layout_index_t group, bool *explicit_type)
+{
+ unsigned int i;
+ GroupInfo *groupi = &darray_item(keyi->groups, group);
+ xkb_atom_t type_name = groupi->type;
+
+ *explicit_type = true;
+
+ if (type_name == XKB_ATOM_NONE) {
+ if (keyi->default_type != XKB_ATOM_NONE) {
+ type_name = keyi->default_type;
}
else {
- *typeNameRtrn = xkb_atom_intern(ctx, "TWO_LEVEL");
- *autoType = true;
+ type_name = FindAutomaticType(keymap->ctx, groupi);
+ if (type_name != XKB_ATOM_NONE)
+ *explicit_type = false;
}
}
- else if (width <= 4) {
- if (syms && xkb_keysym_is_lower(syms[0]) &&
- xkb_keysym_is_upper(syms[1]))
- if (xkb_keysym_is_lower(syms[2]) && xkb_keysym_is_upper(syms[3]))
- *typeNameRtrn =
- xkb_atom_intern(ctx, "FOUR_LEVEL_ALPHABETIC");
- else
- *typeNameRtrn = xkb_atom_intern(ctx,
- "FOUR_LEVEL_SEMIALPHABETIC");
- else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
- xkb_keysym_is_keypad(syms[1])))
- *typeNameRtrn = xkb_atom_intern(ctx, "FOUR_LEVEL_KEYPAD");
- else
- *typeNameRtrn = xkb_atom_intern(ctx, "FOUR_LEVEL");
- /* XXX: why not set autoType here? */
+ if (type_name == XKB_ATOM_NONE) {
+ log_warn(keymap->ctx,
+ "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,
+ (unsigned long) darray_size(groupi->levels));
+ goto use_default;
+ }
+
+ for (i = 0; i < keymap->num_types; i++)
+ if (keymap->types[i].name == type_name)
+ break;
+
+ if (i >= keymap->num_types) {
+ log_warn(keymap->ctx,
+ "The type \"%s\" for key '%s' group %d was not previously defined; "
+ "Using the default type\n",
+ xkb_atom_text(keymap->ctx, type_name),
+ KeyNameText(keymap->ctx, keyi->name), group + 1);
+ goto use_default;
}
- return width <= 4;
+
+ return &keymap->types[i];
+
+use_default:
+ /*
+ * Index 0 is guaranteed to contain something, usually
+ * ONE_LEVEL or at least some default one-level type.
+ */
+ return &keymap->types[0];
}
static bool
-CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi)
+CopySymbolsDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info,
+ KeyInfo *keyi)
{
- struct xkb_keymap *keymap = info->keymap;
struct xkb_key *key;
GroupInfo *groupi;
const GroupInfo *group0;
xkb_layout_index_t i;
- bool haveActions;
- unsigned int sizeSyms;
- unsigned int symIndex;
/*
* The name is guaranteed to be real and not an alias (see
* AddKeySymbols), so 'false' is safe here.
*/
- key = FindNamedKey(keymap, keyi->name, false);
+ key = XkbKeyByName(keymap, keyi->name, false);
if (!key) {
- log_vrb(info->keymap->ctx, 5,
+ log_vrb(info->ctx, 5,
"Key %s not found in keycodes; Symbols ignored\n",
- LongKeyNameText(keyi->name));
+ KeyInfoText(info, keyi));
return false;
}
if (groupi->defined)
continue;
- groupi->type = group0->type;
- darray_copy(groupi->syms, group0->syms);
- darray_copy(groupi->levels, group0->levels);
- groupi->defined = group0->defined;
+ CopyGroupInfo(groupi, group0);
}
- /* See if we need to allocate an actions array. */
- haveActions = false;
- darray_foreach(groupi, keyi->groups) {
- LevelInfo *leveli;
- darray_foreach(leveli, groupi->levels) {
- if (leveli->act.type != ACTION_TYPE_NONE) {
- haveActions = true;
- goto out_of_loops;
- }
- }
- }
-out_of_loops:
+ key->groups = calloc(key->num_groups, sizeof(*key->groups));
- /*
- * Find and assign the groups' types in the keymap. Also find the
- * key width according to the largest type.
- */
- key->kt_index = calloc(key->num_groups, sizeof(*key->kt_index));
- key->width = 0;
+ /* Find and assign the groups' types in the keymap. */
darray_enumerate(i, groupi, keyi->groups) {
- struct xkb_key_type *type;
- bool autoType = false;
-
- /* Find the type of the group, if it is missing. */
- if (groupi->type == XKB_ATOM_NONE) {
- if (keyi->dfltType != XKB_ATOM_NONE)
- groupi->type = keyi->dfltType;
- else if (FindAutomaticType(keymap->ctx,
- darray_size(groupi->levels),
- darray_mem(groupi->syms, 0),
- &groupi->type, &autoType)) { }
- else
- log_vrb(info->keymap->ctx, 5,
- "No automatic type for %d levels; "
- "Using %s for the %s key\n",
- (int) darray_size(groupi->levels),
- xkb_atom_text(keymap->ctx, groupi->type),
- LongKeyNameText(keyi->name));
- }
+ const struct xkb_key_type *type;
+ bool explicit_type;
- /* Find the type in the keymap, if it was defined in xkb_types. */
- if (FindNamedType(keymap, groupi->type, &key->kt_index[i])) {
- if (!autoType || darray_size(groupi->levels) > 2)
- key->explicit_groups |= (1 << i);
- }
- else {
- log_vrb(info->keymap->ctx, 3,
- "Type \"%s\" is not defined; "
- "Using default type for the %s key\n",
- xkb_atom_text(keymap->ctx, groupi->type),
- LongKeyNameText(keyi->name));
- /*
- * Index 0 is guaranteed to contain something, usually
- * ONE_LEVEL or at least some default one-level type.
- */
- key->kt_index[i] = 0;
- }
+ type = FindTypeForGroup(keymap, keyi, i, &explicit_type);
- /* If the type specifies fewer levels than the key has, shrink the key. */
- type = &keymap->types[key->kt_index[i]];
+ /* Always have as many levels as the type specifies. */
if (type->num_levels < darray_size(groupi->levels)) {
- log_vrb(info->keymap->ctx, 1,
+ struct xkb_level *leveli;
+
+ log_vrb(info->ctx, 1,
"Type \"%s\" has %d levels, but %s has %d levels; "
"Ignoring extra symbols\n",
- xkb_atom_text(keymap->ctx, type->name),
- type->num_levels,
- LongKeyNameText(keyi->name),
+ xkb_atom_text(keymap->ctx, type->name), type->num_levels,
+ KeyInfoText(info, keyi),
(int) darray_size(groupi->levels));
- darray_resize(groupi->levels, type->num_levels);
+
+ darray_foreach_from(leveli, groupi->levels, type->num_levels)
+ ClearLevelInfo(leveli);
}
+ darray_resize0(groupi->levels, type->num_levels);
- /*
- * Why type->num_levels and not darray_size(groupi->levels)?
- * Because the type may have more levels, and each group must
- * have at least as many levels as its type. Because the
- * key->syms array is indexed by (group * width + level), we
- * must take the largest one.
- * Maybe we can change it to save some space.
- */
- key->width = MAX(key->width, type->num_levels);
+ key->groups[i].explicit_type = explicit_type;
+ key->groups[i].type = type;
}
- /* Find the size of the syms array. */
- sizeSyms = 0;
- darray_foreach(groupi, keyi->groups)
- sizeSyms += darray_size(groupi->syms);
-
- /* Initialize the xkb_key, now that we know the sizes. */
- key->syms = calloc(sizeSyms, sizeof(*key->syms));
- key->sym_index = calloc(key->num_groups * key->width,
- sizeof(*key->sym_index));
- key->num_syms = calloc(key->num_groups * key->width,
- sizeof(*key->num_syms));
+ /* Copy levels. */
+ darray_enumerate(i, groupi, keyi->groups)
+ darray_steal(groupi->levels, &key->groups[i].levels, NULL);
+
key->out_of_range_group_number = keyi->out_of_range_group_number;
key->out_of_range_group_action = keyi->out_of_range_group_action;
- if (haveActions) {
- key->actions = calloc(key->num_groups * key->width,
- sizeof(*key->actions));
- key->explicit |= EXPLICIT_INTERP;
- }
+
if (keyi->defined & KEY_FIELD_VMODMAP) {
key->vmodmap = keyi->vmodmap;
key->explicit |= EXPLICIT_VMODMAP;
key->explicit |= EXPLICIT_REPEAT;
}
- /* Copy keysyms and actions. */
- symIndex = 0;
- darray_enumerate(i, groupi, keyi->groups) {
- xkb_level_index_t j;
- LevelInfo *leveli;
-
- /* We rely on calloc having zeroized the arrays up to key->width. */
- darray_enumerate(j, leveli, groupi->levels) {
- if (leveli->act.type != ACTION_TYPE_NONE)
- key->actions[i * key->width + j] = leveli->act;
-
- if (leveli->num_syms <= 0)
- continue;
-
- memcpy(&key->syms[symIndex],
- &darray_item(groupi->syms, leveli->sym_index),
- leveli->num_syms * sizeof(*key->syms));
- key->sym_index[i * key->width + j] = symIndex;
- key->num_syms[i * key->width + j] = leveli->num_syms;
- symIndex += key->num_syms[i * key->width + j];
+ darray_foreach(groupi, keyi->groups) {
+ if (groupi->defined & GROUP_FIELD_ACTS) {
+ key->explicit |= EXPLICIT_INTERP;
+ break;
}
}
}
static bool
-CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
+CopyModMapDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info,
+ ModMapEntry *entry)
{
struct xkb_key *key;
- struct xkb_keymap *keymap = info->keymap;
if (!entry->haveSymbol) {
- key = FindNamedKey(keymap, entry->u.keyName, true);
+ key = XkbKeyByName(keymap, entry->u.keyName, true);
if (!key) {
- log_vrb(info->keymap->ctx, 5,
+ log_vrb(info->ctx, 5,
"Key %s not found in keycodes; "
"Modifier map entry for %s not updated\n",
- LongKeyNameText(entry->u.keyName),
- ModIndexText(entry->modifier));
+ KeyNameText(info->ctx, entry->u.keyName),
+ ModIndexText(info->ctx, &info->mods, entry->modifier));
return false;
}
}
else {
key = FindKeyForSymbol(keymap, entry->u.keySym);
if (!key) {
- log_vrb(info->keymap->ctx, 5,
+ log_vrb(info->ctx, 5,
"Key \"%s\" not found in symbol map; "
"Modifier map entry for %s not updated\n",
- KeysymText(entry->u.keySym),
- ModIndexText(entry->modifier));
+ KeysymText(info->ctx, entry->u.keySym),
+ ModIndexText(info->ctx, &info->mods, entry->modifier));
return false;
}
}
- key->modmap |= (1 << entry->modifier);
+ // Handle modMap None
+ if (entry->modifier != XKB_MOD_NONE) {
+ // Convert modifier index to modifier mask
+ key->modmap |= (1u << entry->modifier);
+ }
+
return true;
}
{
KeyInfo *keyi;
ModMapEntry *mm;
- struct xkb_key *key;
keymap->symbols_section_name = strdup_safe(info->name);
+ XkbEscapeMapName(keymap->symbols_section_name);
+
+ keymap->mods = info->mods;
- keymap->group_names = info->group_names;
- darray_init(info->group_names);
+ darray_steal(info->group_names,
+ &keymap->group_names, &keymap->num_group_names);
darray_foreach(keyi, info->keys)
- if (!CopySymbolsDef(info, keyi))
+ if (!CopySymbolsDefToKeymap(keymap, info, keyi))
info->errorCount++;
if (xkb_context_get_log_verbosity(keymap->ctx) > 3) {
- xkb_foreach_key(key, keymap) {
- if (key->name[0] == '\0')
+ struct xkb_key *key;
+
+ xkb_keys_foreach(key, keymap) {
+ if (key->name == XKB_ATOM_NONE)
continue;
if (key->num_groups < 1)
- log_info(keymap->ctx,
+ log_info(info->ctx,
"No symbols defined for %s\n",
- KeyNameText(key->name));
+ KeyNameText(info->ctx, key->name));
}
}
- darray_foreach(mm, info->modMaps)
- if (!CopyModMapDef(info, mm))
+ darray_foreach(mm, info->modmaps)
+ if (!CopyModMapDefToKeymap(keymap, info, mm))
info->errorCount++;
/* XXX: If we don't ignore errorCount, things break. */
if (!actions)
return false;
- InitSymbolsInfo(&info, keymap, file->id, actions);
- info.dflt.merge = merge;
+ InitSymbolsInfo(&info, keymap, actions, &keymap->mods);
+ info.default_key.merge = merge;
HandleSymbolsFile(&info, file, merge);
- if (darray_empty(info.keys))
- goto err_info;
-
if (info.errorCount != 0)
goto err_info;