diff options
author | Ran Benita <ran234@gmail.com> | 2013-03-03 15:10:45 +0200 |
---|---|---|
committer | Daniel Stone <daniel@fooishbar.org> | 2013-03-18 22:20:04 +0000 |
commit | 82c3e3936078e2f8ea738615d2fdb0812a2f521b (patch) | |
tree | e82f899521dbe64e59a2a8e87f267dedb6985e85 | |
parent | 614f60e3fa213c0b692dc8e64709e8f9f228d7f7 (diff) | |
download | libxkbcommon-82c3e3936078e2f8ea738615d2fdb0812a2f521b.tar.gz libxkbcommon-82c3e3936078e2f8ea738615d2fdb0812a2f521b.tar.bz2 libxkbcommon-82c3e3936078e2f8ea738615d2fdb0812a2f521b.zip |
keycodes: remove unneeded alias conflict check
This is already checked when adding a new alias and merging aliases, so
it can never happen when we get to copying to the keymap.
Also the log verbosity decision there is quite useless, we should just
warn always and be done with it. So we can remove the file_id from
AliasInfo, and collapse the alias functions together.
Signed-off-by: Ran Benita <ran234@gmail.com>
-rw-r--r-- | src/xkbcomp/keycodes.c | 102 |
1 files changed, 35 insertions, 67 deletions
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index ae17caf..5b262d9 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -104,7 +104,6 @@ typedef struct { enum merge_mode merge; - unsigned file_id; xkb_atom_t alias; xkb_atom_t real; @@ -141,12 +140,11 @@ typedef struct { /***====================================================================***/ static void -InitAliasInfo(AliasInfo *info, enum merge_mode merge, unsigned file_id, +InitAliasInfo(AliasInfo *info, enum merge_mode merge, xkb_atom_t alias, xkb_atom_t real) { memset(info, 0, sizeof(*info)); info->merge = merge; - info->file_id = file_id; info->alias = alias; info->real = real; } @@ -344,8 +342,7 @@ AddKeyName(KeyNamesInfo *info, xkb_keycode_t kc, xkb_atom_t name, /***====================================================================***/ static int -HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge, - unsigned file_id); +HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge); static bool MergeAliases(KeyNamesInfo *into, KeyNamesInfo *from, enum merge_mode merge) @@ -369,7 +366,7 @@ MergeAliases(KeyNamesInfo *into, KeyNamesInfo *from, enum merge_mode merge) def.alias = alias->alias; def.real = alias->real; - if (!HandleAliasDef(into, &def, def.merge, alias->file_id)) + if (!HandleAliasDef(into, &def, def.merge)) return false; } @@ -479,55 +476,42 @@ HandleKeycodeDef(KeyNamesInfo *info, KeycodeDef *stmt, enum merge_mode merge) info->file_id, true); } -static void -HandleAliasCollision(KeyNamesInfo *info, AliasInfo *old, AliasInfo *new) +static int +HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge) { - const int verbosity = xkb_context_get_log_verbosity(info->ctx); - const bool report = ((new->file_id == old->file_id && verbosity > 0) || - verbosity > 9); - - if (new->real == old->real) { - if (report) - log_warn(info->ctx, "Alias of %s for %s declared more than once; " - "First definition ignored\n", - KeyNameText(info->ctx, new->alias), - KeyNameText(info->ctx, new->real)); - } - else { - xkb_atom_t use, ignore; + AliasInfo *old, new; + + darray_foreach(old, info->aliases) { + if (old->alias == def->alias) { + if (def->real == old->real) { + log_vrb(info->ctx, 1, + "Alias of %s for %s declared more than once; " + "First definition ignored\n", + KeyNameText(info->ctx, def->alias), + KeyNameText(info->ctx, def->real)); + } + else { + xkb_atom_t use, ignore; + + use = (merge == MERGE_AUGMENT ? old->real : def->real); + ignore = (merge == MERGE_AUGMENT ? def->real : old->real); - use = (new->merge == MERGE_AUGMENT ? old->real : new->real); - ignore = (new->merge == MERGE_AUGMENT ? new->real : old->real); - - if (report) - log_warn(info->ctx, "Multiple definitions for alias %s; " - "Using %s, ignoring %s\n", - KeyNameText(info->ctx, old->alias), - KeyNameText(info->ctx, use), - KeyNameText(info->ctx, ignore)); - - old->real = use; - } - - old->file_id = new->file_id; - old->merge = new->merge; -} + log_warn(info->ctx, + "Multiple definitions for alias %s; " + "Using %s, ignoring %s\n", + KeyNameText(info->ctx, old->alias), + KeyNameText(info->ctx, use), + KeyNameText(info->ctx, ignore)); -static int -HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge, - unsigned file_id) -{ - AliasInfo *alias, new; + old->real = use; + } - darray_foreach(alias, info->aliases) { - if (alias->alias == def->alias) { - InitAliasInfo(&new, merge, file_id, def->alias, def->real); - HandleAliasCollision(info, alias, &new); + old->merge = merge; return true; } } - InitAliasInfo(&new, merge, file_id, def->alias, def->real); + InitAliasInfo(&new, merge, def->alias, def->real); darray_append(info->aliases, new); return true; } @@ -602,8 +586,7 @@ HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge) ok = HandleKeycodeDef(info, (KeycodeDef *) stmt, merge); break; case STMT_ALIAS: - ok = HandleAliasDef(info, (KeyAliasDef *) stmt, merge, - info->file_id); + ok = HandleAliasDef(info, (KeyAliasDef *) stmt, merge); break; case STMT_VAR: ok = HandleKeyNameVar(info, (VarDef *) stmt); @@ -635,11 +618,12 @@ HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge) static void CopyAliasesToKeymap(KeyNamesInfo *info, struct xkb_keymap *keymap) { - struct xkb_key *key; - struct xkb_key_alias *a, new; AliasInfo *alias; darray_foreach(alias, info->aliases) { + struct xkb_key *key; + struct xkb_key_alias new; + /* Check that ->real is a key. */ key = FindNamedKey(keymap, alias->real, false); if (!key) { @@ -661,22 +645,6 @@ CopyAliasesToKeymap(KeyNamesInfo *info, struct xkb_keymap *keymap) continue; } - /* Check that ->alias in not already an alias, and if so handle it. */ - darray_foreach(a, keymap->key_aliases) { - AliasInfo old_alias; - - if (a->alias != alias->alias) - continue; - - InitAliasInfo(&old_alias, MERGE_AUGMENT, 0, a->alias, a->real); - HandleAliasCollision(info, &old_alias, alias); - a->alias = old_alias.alias; - a->real = old_alias.real; - alias->alias = 0; - } - if (alias->alias == 0) - continue; - /* Add the alias. */ new.alias = alias->alias; new.real = alias->real; |