diff options
-rw-r--r-- | src/keymap.c | 10 | ||||
-rw-r--r-- | src/keymap.h | 3 | ||||
-rw-r--r-- | src/xkbcomp/keycodes.c | 88 | ||||
-rw-r--r-- | src/xkbcomp/keymap-dump.c | 13 |
4 files changed, 56 insertions, 58 deletions
diff --git a/src/keymap.c b/src/keymap.c index 758a35b..480a4ce 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -107,7 +107,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap) } free(keymap->types); darray_free(keymap->sym_interprets); - darray_free(keymap->key_aliases); + free(keymap->key_aliases); free(keymap->group_names); darray_free(keymap->mods); darray_free(keymap->leds); @@ -499,11 +499,9 @@ XkbKeyByName(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases) xkb_atom_t XkbResolveKeyAlias(struct xkb_keymap *keymap, xkb_atom_t name) { - const struct xkb_key_alias *alias; - - darray_foreach(alias, keymap->key_aliases) - if (name == alias->alias) - return alias->real; + for (unsigned i = 0; i < keymap->num_key_aliases; i++) + if (keymap->key_aliases[i].alias == name) + return keymap->key_aliases[i].real; return XKB_ATOM_NONE; } diff --git a/src/keymap.h b/src/keymap.h index f4b80eb..0f3d6bb 100644 --- a/src/keymap.h +++ b/src/keymap.h @@ -380,7 +380,8 @@ struct xkb_keymap { struct xkb_key *keys; /* aliases in no particular order */ - darray(struct xkb_key_alias) key_aliases; + unsigned int num_key_aliases; + struct xkb_key_alias *key_aliases; struct xkb_key_type *types; unsigned int num_types; diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index 53e3fff..d7d475e 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -90,7 +90,8 @@ * following members of struct xkb_keymap are finalized: * xkb_keycode_t min_key_code; * xkb_keycode_t max_key_code; - * darray(struct xkb_key_alias) key_aliases; + * unsigned int num_aliases; + * struct xkb_key_alias *key_aliases; * char *keycodes_section_name; * The 'name' field of leds declared in xkb_keycodes: * darray(struct xkb_led) leds; @@ -617,75 +618,74 @@ HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge) /***====================================================================***/ -static void -CopyAliasesToKeymap(KeyNamesInfo *info, struct xkb_keymap *keymap) +static bool +CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info) { + xkb_keycode_t kc; + xkb_led_index_t idx; + LedNameInfo *ledi; AliasInfo *alias; + unsigned i; - darray_foreach(alias, info->aliases) { - struct xkb_key *key; - struct xkb_key_alias new; + keymap->keycodes_section_name = strdup_safe(info->name); + + keymap->min_key_code = info->min_key_code; + keymap->max_key_code = info->max_key_code; + /* Copy key names. */ + keymap->keys = calloc(info->max_key_code + 1, sizeof(*keymap->keys)); + for (kc = info->min_key_code; kc <= info->max_key_code; kc++) { + keymap->keys[kc].keycode = kc; + keymap->keys[kc].name = darray_item(info->key_names, kc).name; + } + + /* + * Do some sanity checking on the aliases. We can't do it before + * because keys and their aliases may be added out-of-order. + */ + keymap->num_key_aliases = 0; + darray_foreach(alias, info->aliases) { /* Check that ->real is a key. */ - key = XkbKeyByName(keymap, alias->real, false); - if (!key) { + if (!XkbKeyByName(keymap, alias->real, false)) { log_vrb(info->ctx, 5, "Attempt to alias %s to non-existent key %s; Ignored\n", KeyNameText(info->ctx, alias->alias), KeyNameText(info->ctx, alias->real)); + alias->real = XKB_ATOM_NONE; continue; } /* Check that ->alias is not a key. */ - key = XkbKeyByName(keymap, alias->alias, false); - if (key) { + if (XkbKeyByName(keymap, alias->alias, false)) { log_vrb(info->ctx, 5, "Attempt to create alias with the name of a real key; " "Alias \"%s = %s\" ignored\n", KeyNameText(info->ctx, alias->alias), KeyNameText(info->ctx, alias->real)); + alias->real = XKB_ATOM_NONE; continue; } - /* Add the alias. */ - new.alias = alias->alias; - new.real = alias->real; - darray_append(keymap->key_aliases, new); + keymap->num_key_aliases++; } - darray_free(info->aliases); -} - -static bool -CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info) -{ - xkb_keycode_t kc; - xkb_led_index_t idx; - LedNameInfo *ledi; - - keymap->keys = calloc(info->max_key_code + 1, sizeof(*keymap->keys)); - if (!keymap->keys) - return false; - - keymap->min_key_code = info->min_key_code; - keymap->max_key_code = info->max_key_code; - - for (kc = info->min_key_code; kc <= info->max_key_code; kc++) { - keymap->keys[kc].keycode = kc; - keymap->keys[kc].name = darray_item(info->key_names, kc).name; + /* Copy key aliases. */ + keymap->key_aliases = calloc(keymap->num_key_aliases, + sizeof(*keymap->key_aliases)); + i = 0; + darray_foreach(alias, info->aliases) { + if (alias->real != XKB_ATOM_NONE) { + keymap->key_aliases[i].alias = alias->alias; + keymap->key_aliases[i].real = alias->real; + i++; + } } - keymap->keycodes_section_name = strdup_safe(info->name); - + /* Copy LED names. */ darray_resize0(keymap->leds, darray_size(info->led_names)); - darray_enumerate(idx, ledi, info->led_names) { - if (ledi->name == XKB_ATOM_NONE) - continue; - - darray_item(keymap->leds, idx).name = ledi->name; - } - - CopyAliasesToKeymap(info, keymap); + darray_enumerate(idx, ledi, info->led_names) + if (ledi->name != XKB_ATOM_NONE) + darray_item(keymap->leds, idx).name = ledi->name; return true; } diff --git a/src/xkbcomp/keymap-dump.c b/src/xkbcomp/keymap-dump.c index 5ca2a10..5c57e17 100644 --- a/src/xkbcomp/keymap-dump.c +++ b/src/xkbcomp/keymap-dump.c @@ -148,8 +148,7 @@ static bool write_keycodes(struct xkb_keymap *keymap, struct buf *buf) { const struct xkb_key *key; - const struct xkb_key_alias *alias; - xkb_led_index_t i; + xkb_led_index_t idx; const struct xkb_led *led; if (keymap->keycodes_section_name) @@ -166,16 +165,16 @@ write_keycodes(struct xkb_keymap *keymap, struct buf *buf) KeyNameText(keymap->ctx, key->name), key->keycode); } - darray_enumerate(i, led, keymap->leds) + darray_enumerate(idx, led, keymap->leds) if (led->name != XKB_ATOM_NONE) write_buf(buf, "\tindicator %d = \"%s\";\n", - i + 1, xkb_atom_text(keymap->ctx, led->name)); + idx + 1, xkb_atom_text(keymap->ctx, led->name)); - darray_foreach(alias, keymap->key_aliases) + for (unsigned i = 0; i < keymap->num_key_aliases; i++) write_buf(buf, "\talias %-14s = %s;\n", - KeyNameText(keymap->ctx, alias->alias), - KeyNameText(keymap->ctx, alias->real)); + KeyNameText(keymap->ctx, keymap->key_aliases[i].alias), + KeyNameText(keymap->ctx, keymap->key_aliases[i].real)); write_buf(buf, "};\n\n"); return true; |