aliases: Assign keycodes of valid alias key names by default

master
Raheman Vaiya 4 years ago
parent 67a2af0f7f
commit c1655dffbc
  1. BIN
      data/keyd.1.gz
  2. 16
      docs/keyd.scdoc
  3. 19
      src/config.c

Binary file not shown.

@ -279,9 +279,11 @@ E.G
## Aliases ## Aliases
An *alias* may be assigned to a key and used as a valid left hand value. Each key may optionally be assigned to an *alias*. This alias may be used in place
Multiple keys may be bound to a single alias, but _a given key may only be of the key as a valid left hand value. Multiple keys may be bound to the same alias,
assigned to one alias at a time_. For example, the keys 'leftmeta' and 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 = 'rightmeta' are bound to the alias *meta* by default. Thus the binding 'meta =
a' is equivalent to the bindings 'leftmeta = a' and 'rightmeta = a'. a' is equivalent to the bindings 'leftmeta = a' and 'rightmeta = a'.
@ -293,9 +295,11 @@ the form:
where _<key>_ must be a valid key name. where _<key>_ must be a valid key name.
Note that <name> may itself be a valid key name, in which case all references Note that <name> 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 to the key within the config file will be replaced with the new key.
judiciously, aliases can be used in conjunction with the include directive to Additionally, if the assigned alias is a valid key name, the corresponding
share bindings between keyboards with different physical layouts. 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: For example:

@ -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++) { for (i = 0; i < section->nr_entries; i++) {
uint8_t code; uint8_t code;
struct ini_entry *ent = &section->entries[i]; struct ini_entry *ent = &section->entries[i];
const char *name = ent->val;
if ((code = lookup_keycode(ent->key))) { if ((code = lookup_keycode(ent->key))) {
ssize_t len = strlen(ent->val); ssize_t len = strlen(name);
if (len > MAX_ALIAS_LEN) { if (len > MAX_ALIAS_LEN) {
fprintf(stderr, fprintf(stderr,
"\tERROR: %s exceeds the maximum alias length (%d)\n", "\tERROR: %s exceeds the maximum alias length (%d)\n",
ent->val, MAX_ALIAS_LEN); name, MAX_ALIAS_LEN);
} else { } 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 { } else {
fprintf(stderr, fprintf(stderr,
"\tERROR %s:%zd: Failed to define alias %s, %s is not a valid keycode\n", "\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);
} }
} }
} }

Loading…
Cancel
Save