symbols: use xkb_mod_set instead of entire keymap

The keymap is not removed entirely from the Info (just constified),
since it is still needed in AddKeySymbols() for looking up aliases. This
dependency will be removed in the future.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2013-02-09 19:10:56 +02:00
parent f2cbeda9f0
commit 95aabeecb1
3 changed files with 40 additions and 32 deletions

View File

@ -90,7 +90,7 @@ XkbKeyByName(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases)
} }
xkb_atom_t xkb_atom_t
XkbResolveKeyAlias(struct xkb_keymap *keymap, xkb_atom_t name) XkbResolveKeyAlias(const struct xkb_keymap *keymap, xkb_atom_t name)
{ {
for (unsigned i = 0; i < keymap->num_key_aliases; i++) for (unsigned i = 0; i < keymap->num_key_aliases; i++)
if (keymap->key_aliases[i].alias == name) if (keymap->key_aliases[i].alias == name)

View File

@ -425,7 +425,7 @@ struct xkb_key *
XkbKeyByName(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases); XkbKeyByName(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases);
xkb_atom_t xkb_atom_t
XkbResolveKeyAlias(struct xkb_keymap *keymap, xkb_atom_t name); XkbResolveKeyAlias(const struct xkb_keymap *keymap, xkb_atom_t name);
void void
XkbEscapeMapName(char *name); XkbEscapeMapName(char *name);

View File

@ -177,14 +177,16 @@ typedef struct {
ActionsInfo *actions; ActionsInfo *actions;
darray(xkb_atom_t) group_names; darray(xkb_atom_t) group_names;
darray(ModMapEntry) modmaps; darray(ModMapEntry) modmaps;
struct xkb_mod_set mods;
struct xkb_context *ctx; struct xkb_context *ctx;
struct xkb_keymap *keymap; /* Needed for AddKeySymbols. */
const struct xkb_keymap *keymap;
} SymbolsInfo; } SymbolsInfo;
static void static void
InitSymbolsInfo(SymbolsInfo *info, struct xkb_keymap *keymap, InitSymbolsInfo(SymbolsInfo *info, const struct xkb_keymap *keymap,
ActionsInfo *actions) ActionsInfo *actions, const struct xkb_mod_set *mods)
{ {
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
info->ctx = keymap->ctx; info->ctx = keymap->ctx;
@ -192,6 +194,7 @@ InitSymbolsInfo(SymbolsInfo *info, struct xkb_keymap *keymap,
info->merge = MERGE_OVERRIDE; info->merge = MERGE_OVERRIDE;
InitKeyInfo(keymap->ctx, &info->default_key); InitKeyInfo(keymap->ctx, &info->default_key);
info->actions = actions; info->actions = actions;
CopyModSet(&info->mods, mods);
info->explicit_group = XKB_LAYOUT_INVALID; info->explicit_group = XKB_LAYOUT_INVALID;
} }
@ -200,6 +203,7 @@ ClearSymbolsInfo(SymbolsInfo *info)
{ {
KeyInfo *keyi; KeyInfo *keyi;
free(info->name); free(info->name);
ClearModSet(&info->mods);
darray_foreach(keyi, info->keys) darray_foreach(keyi, info->keys)
ClearKeyInfo(keyi); ClearKeyInfo(keyi);
darray_free(info->keys); darray_free(info->keys);
@ -407,6 +411,7 @@ MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from, bool same_file)
return true; return true;
} }
/* TODO: Make it so this function doesn't need the entire keymap. */
static bool static bool
AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi, bool same_file) AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi, bool same_file)
{ {
@ -457,15 +462,15 @@ AddModMapEntry(SymbolsInfo *info, ModMapEntry *new)
"Symbol \"%s\" added to modifier map for multiple modifiers; " "Symbol \"%s\" added to modifier map for multiple modifiers; "
"Using %s, ignoring %s\n", "Using %s, ignoring %s\n",
KeysymText(info->ctx, new->u.keySym), KeysymText(info->ctx, new->u.keySym),
ModIndexText(info->ctx, &info->keymap->mods, use), ModIndexText(info->ctx, &info->mods, use),
ModIndexText(info->ctx, &info->keymap->mods, ignore)); ModIndexText(info->ctx, &info->mods, ignore));
else else
log_err(info->ctx, log_err(info->ctx,
"Key \"%s\" added to modifier map for multiple modifiers; " "Key \"%s\" added to modifier map for multiple modifiers; "
"Using %s, ignoring %s\n", "Using %s, ignoring %s\n",
KeyNameText(info->ctx, new->u.keyName), KeyNameText(info->ctx, new->u.keyName),
ModIndexText(info->ctx, &info->keymap->mods, use), ModIndexText(info->ctx, &info->mods, use),
ModIndexText(info->ctx, &info->keymap->mods, ignore)); ModIndexText(info->ctx, &info->mods, ignore));
old->modifier = use; old->modifier = use;
return true; return true;
@ -491,6 +496,8 @@ MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
return; return;
} }
MoveModSet(&into->mods, &from->mods);
if (into->name == NULL) { if (into->name == NULL) {
into->name = from->name; into->name = from->name;
from->name = NULL; from->name = NULL;
@ -544,7 +551,7 @@ HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *include)
{ {
SymbolsInfo included; SymbolsInfo included;
InitSymbolsInfo(&included, info->keymap, info->actions); InitSymbolsInfo(&included, info->keymap, info->actions, &info->mods);
included.name = include->stmt; included.name = include->stmt;
include->stmt = NULL; include->stmt = NULL;
@ -559,7 +566,8 @@ HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *include)
return false; return false;
} }
InitSymbolsInfo(&next_incl, info->keymap, info->actions); InitSymbolsInfo(&next_incl, info->keymap, info->actions,
&included.mods);
if (stmt->modifier) { if (stmt->modifier) {
next_incl.explicit_group = atoi(stmt->modifier) - 1; next_incl.explicit_group = atoi(stmt->modifier) - 1;
if (next_incl.explicit_group >= XKB_MAX_GROUPS) { if (next_incl.explicit_group >= XKB_MAX_GROUPS) {
@ -754,8 +762,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
for (unsigned i = 0; i < nActs; i++) { for (unsigned i = 0; i < nActs; i++) {
union xkb_action *toAct = &darray_item(groupi->levels, i).action; union xkb_action *toAct = &darray_item(groupi->levels, i).action;
if (!HandleActionDef(info->ctx, info->actions, &info->keymap->mods, if (!HandleActionDef(info->ctx, info->actions, &info->mods, act, toAct))
act, toAct))
log_err(info->ctx, log_err(info->ctx,
"Illegal action definition for %s; " "Illegal action definition for %s; "
"Action for group %u/level %u ignored\n", "Action for group %u/level %u ignored\n",
@ -823,8 +830,8 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
istreq(field, "virtualmodifiers")) { istreq(field, "virtualmodifiers")) {
xkb_mod_mask_t mask; xkb_mod_mask_t mask;
if (!ExprResolveModMask(info->ctx, value, MOD_VIRT, if (!ExprResolveModMask(info->ctx, value, MOD_VIRT, &info->mods,
&info->keymap->mods, &mask)) { &mask)) {
log_err(info->ctx, log_err(info->ctx,
"Expected a virtual modifier mask, found %s; " "Expected a virtual modifier mask, found %s; "
"Ignoring virtual modifiers definition for key %s\n", "Ignoring virtual modifiers definition for key %s\n",
@ -1025,7 +1032,7 @@ HandleGlobalVar(SymbolsInfo *info, VarDef *stmt)
ret = true; ret = true;
} }
else { else {
ret = SetActionField(info->ctx, info->actions, &info->keymap->mods, ret = SetActionField(info->ctx, info->actions, &info->mods,
elem, field, arrayNdx, stmt->value); elem, field, arrayNdx, stmt->value);
} }
@ -1141,7 +1148,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
bool ok; bool ok;
struct xkb_context *ctx = info->ctx; struct xkb_context *ctx = info->ctx;
ndx = XkbModNameToIndex(&info->keymap->mods, def->modifier, MOD_REAL); ndx = XkbModNameToIndex(&info->mods, def->modifier, MOD_REAL);
if (ndx == XKB_MOD_INVALID) { if (ndx == XKB_MOD_INVALID) {
log_err(info->ctx, log_err(info->ctx,
"Illegal modifier map definition; " "Illegal modifier map definition; "
@ -1170,7 +1177,7 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
log_err(info->ctx, log_err(info->ctx,
"Modmap entries may contain only key names or keysyms; " "Modmap entries may contain only key names or keysyms; "
"Illegal definition for %s modifier ignored\n", "Illegal definition for %s modifier ignored\n",
ModIndexText(info->ctx, &info->keymap->mods, tmp.modifier)); ModIndexText(info->ctx, &info->mods, tmp.modifier));
continue; continue;
} }
@ -1199,8 +1206,7 @@ HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
ok = HandleGlobalVar(info, (VarDef *) stmt); ok = HandleGlobalVar(info, (VarDef *) stmt);
break; break;
case STMT_VMOD: case STMT_VMOD:
ok = HandleVModDef(info->ctx, &info->keymap->mods, ok = HandleVModDef(info->ctx, &info->mods, (VModDef *) stmt, merge);
(VModDef *) stmt, merge);
break; break;
case STMT_MODMAP: case STMT_MODMAP:
ok = HandleModMapDef(info, (ModMapDef *) stmt); ok = HandleModMapDef(info, (ModMapDef *) stmt);
@ -1389,9 +1395,9 @@ use_default:
} }
static bool 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; struct xkb_key *key;
GroupInfo *groupi; GroupInfo *groupi;
const GroupInfo *group0; const GroupInfo *group0;
@ -1492,10 +1498,10 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi)
} }
static bool static bool
CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry) CopyModMapDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info,
ModMapEntry *entry)
{ {
struct xkb_key *key; struct xkb_key *key;
struct xkb_keymap *keymap = info->keymap;
if (!entry->haveSymbol) { if (!entry->haveSymbol) {
key = XkbKeyByName(keymap, entry->u.keyName, true); key = XkbKeyByName(keymap, entry->u.keyName, true);
@ -1503,8 +1509,8 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
log_vrb(info->ctx, 5, log_vrb(info->ctx, 5,
"Key %s not found in keycodes; " "Key %s not found in keycodes; "
"Modifier map entry for %s not updated\n", "Modifier map entry for %s not updated\n",
KeyNameText(keymap->ctx, entry->u.keyName), KeyNameText(info->ctx, entry->u.keyName),
ModIndexText(info->ctx, &info->keymap->mods, entry->modifier)); ModIndexText(info->ctx, &info->mods, entry->modifier));
return false; return false;
} }
} }
@ -1515,7 +1521,7 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
"Key \"%s\" not found in symbol map; " "Key \"%s\" not found in symbol map; "
"Modifier map entry for %s not updated\n", "Modifier map entry for %s not updated\n",
KeysymText(info->ctx, entry->u.keySym), KeysymText(info->ctx, entry->u.keySym),
ModIndexText(info->ctx, &info->keymap->mods, entry->modifier)); ModIndexText(info->ctx, &info->mods, entry->modifier));
return false; return false;
} }
} }
@ -1533,12 +1539,14 @@ CopySymbolsToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info)
keymap->symbols_section_name = strdup_safe(info->name); keymap->symbols_section_name = strdup_safe(info->name);
XkbEscapeMapName(keymap->symbols_section_name); XkbEscapeMapName(keymap->symbols_section_name);
MoveModSet(&keymap->mods, &info->mods);
keymap->num_group_names = darray_size(info->group_names); keymap->num_group_names = darray_size(info->group_names);
keymap->group_names = darray_mem(info->group_names, 0); keymap->group_names = darray_mem(info->group_names, 0);
darray_init(info->group_names); darray_init(info->group_names);
darray_foreach(keyi, info->keys) darray_foreach(keyi, info->keys)
if (!CopySymbolsDef(info, keyi)) if (!CopySymbolsDefToKeymap(keymap, info, keyi))
info->errorCount++; info->errorCount++;
if (xkb_context_get_log_verbosity(keymap->ctx) > 3) { if (xkb_context_get_log_verbosity(keymap->ctx) > 3) {
@ -1549,14 +1557,14 @@ CopySymbolsToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info)
continue; continue;
if (key->num_groups < 1) if (key->num_groups < 1)
log_info(keymap->ctx, log_info(info->ctx,
"No symbols defined for %s\n", "No symbols defined for %s\n",
KeyNameText(keymap->ctx, key->name)); KeyNameText(info->ctx, key->name));
} }
} }
darray_foreach(mm, info->modmaps) darray_foreach(mm, info->modmaps)
if (!CopyModMapDef(info, mm)) if (!CopyModMapDefToKeymap(keymap, info, mm))
info->errorCount++; info->errorCount++;
/* XXX: If we don't ignore errorCount, things break. */ /* XXX: If we don't ignore errorCount, things break. */
@ -1574,7 +1582,7 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
if (!actions) if (!actions)
return false; return false;
InitSymbolsInfo(&info, keymap, actions); InitSymbolsInfo(&info, keymap, actions, &keymap->mods);
info.default_key.merge = merge; info.default_key.merge = merge;
HandleSymbolsFile(&info, file, merge); HandleSymbolsFile(&info, file, merge);