diff --git a/data/keyd.1.gz b/data/keyd.1.gz index f6652fb..fc27dd5 100644 Binary files a/data/keyd.1.gz and b/data/keyd.1.gz differ diff --git a/docs/keyd.scdoc b/docs/keyd.scdoc index 21006de..2882520 100644 --- a/docs/keyd.scdoc +++ b/docs/keyd.scdoc @@ -279,9 +279,11 @@ E.G ## Aliases -An *alias* may be assigned to a key and used as a valid left hand value. -Multiple keys may be bound to a single alias, but _a given key may only be -assigned to one alias at a time_. For example, the keys 'leftmeta' and +Each key may optionally be assigned to an *alias*. This alias may be used in place +of the key as a valid left hand value. Multiple keys may be bound to the same alias, +but only one alias may be assigned to a key at a given time. + +For example, the keys 'leftmeta' and 'rightmeta' are bound to the alias *meta* by default. Thus the binding 'meta = a' is equivalent to the bindings 'leftmeta = a' and 'rightmeta = a'. @@ -293,9 +295,11 @@ the form: where __ must be a valid key name. Note that may itself be a valid key name, in which case all references -to the key within the config file will be replaced with the new key. When used -judiciously, aliases can be used in conjunction with the include directive to -share bindings between keyboards with different physical layouts. +to the key within the config file will be replaced with the new key. +Additionally, if the assigned alias is a valid key name, the corresponding +keycode will be assigned to the key by default. This makes it possible to +redefine keys before any bindings are applied and is particularly useful in +conjunction with the include mechanism to account for variations in hardware. For example: diff --git a/src/config.c b/src/config.c index 7314f0a..22a186e 100644 --- a/src/config.c +++ b/src/config.c @@ -336,21 +336,32 @@ static void parse_aliases(const char *path, struct config *config, struct ini_se for (i = 0; i < section->nr_entries; i++) { uint8_t code; struct ini_entry *ent = §ion->entries[i]; + const char *name = ent->val; if ((code = lookup_keycode(ent->key))) { - ssize_t len = strlen(ent->val); + ssize_t len = strlen(name); if (len > MAX_ALIAS_LEN) { fprintf(stderr, "\tERROR: %s exceeds the maximum alias length (%d)\n", - ent->val, MAX_ALIAS_LEN); + name, MAX_ALIAS_LEN); } else { - strcpy(config->aliases[code], ent->val); + uint8_t alias_code; + + if ((alias_code = lookup_keycode(name))) { + struct descriptor *d = &config->layers[0].keymap[code]; + + d->op = OP_KEYSEQUENCE; + d->args[0].code = alias_code; + d->args[1].mods = 0; + } + + strcpy(config->aliases[code], name); } } else { fprintf(stderr, "\tERROR %s:%zd: Failed to define alias %s, %s is not a valid keycode\n", - path, ent->lnum, ent->key, ent->val); + path, ent->lnum, ent->key, name); } } }