summaryrefslogtreecommitdiff
path: root/src/xkbcomp/keycodes.c
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2013-03-04 12:27:06 +0200
committerDaniel Stone <daniel@fooishbar.org>2013-03-18 22:20:05 +0000
commitf8d3ec9f6fcfea682ca6383fda88c6a00b0c9c41 (patch)
tree4edc2716d3dbe30e37aed148a1e7171e159e0d3f /src/xkbcomp/keycodes.c
parentea3cf26db5c6b71a7e3cb755c03db6757fd6634f (diff)
downloadlibxkbcommon-f8d3ec9f6fcfea682ca6383fda88c6a00b0c9c41.tar.gz
libxkbcommon-f8d3ec9f6fcfea682ca6383fda88c6a00b0c9c41.tar.bz2
libxkbcommon-f8d3ec9f6fcfea682ca6383fda88c6a00b0c9c41.zip
keymap: don't use darray for key aliases
With a little tweak to the copy-to-keymap routine in keycodes.c we can use a normal array. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/xkbcomp/keycodes.c')
-rw-r--r--src/xkbcomp/keycodes.c88
1 files changed, 44 insertions, 44 deletions
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;
}