diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-03-12 09:46:27 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-03-12 09:46:27 +0000 |
| commit | c58f9a9ef93fd3fd2be711906b8214a53665e45f (patch) | |
| tree | e760cd598211e03c91e4ff03a5acf7f444b48011 /config.c | |
| parent | changelog: user configurable key- and mouse bindings (diff) | |
config: mouse-bindings: verify button isn't already mapped
A button may only be mapped to a single action. Detect when the user
tried to map the same button to multiple actions and error out.
To clear a binding (for example, to free up a button from the default
bindings), one can set the action it is bound to to
`NONE` (e.g. `primary-paste=NONE`).
Diffstat (limited to 'config.c')
| -rw-r--r-- | config.c | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -49,6 +49,7 @@ static const uint32_t default_bright[] = { }; static const char *binding_action_map[] = { + [BIND_ACTION_NONE] = NULL, [BIND_ACTION_SCROLLBACK_UP] = "scrollback-up", [BIND_ACTION_SCROLLBACK_DOWN] = "scrollback-down", [BIND_ACTION_CLIPBOARD_COPY] = "clipboard-copy", @@ -454,6 +455,9 @@ parse_section_key_bindings( const char *path, unsigned lineno) { for (enum binding_action action = 0; action < BIND_ACTION_COUNT; action++) { + if (binding_action_map[action] == NULL) + continue; + if (strcmp(key, binding_action_map[action]) != 0) continue; @@ -488,9 +492,17 @@ parse_section_mouse_bindings( const char *path, unsigned lineno) { for (enum binding_action action = 0; action < BIND_ACTION_COUNT; action++) { + if (binding_action_map[action] == NULL) + continue; + if (strcmp(key, binding_action_map[action]) != 0) continue; + if (strcmp(value, "NONE") == 0) { + conf->bindings.mouse[action] = (struct mouse_binding){0, 0, BIND_ACTION_NONE}; + return true; + } + const char *map[] = { [BTN_LEFT] = "BTN_LEFT", [BTN_RIGHT] = "BTN_RIGHT", @@ -506,7 +518,19 @@ parse_section_mouse_bindings( if (map[i] == NULL || strcmp(map[i], value) != 0) continue; - conf->bindings.mouse[action] = (struct mouse_binding){i, 1, action}; + const int count = 1; + + /* Make sure button isn't already mapped to another action */ + for (enum binding_action j = 0; j < BIND_ACTION_COUNT; j++) { + const struct mouse_binding *collision = &conf->bindings.mouse[j]; + if (collision->button == i && collision->count == count) { + LOG_ERR("%s:%d: %s already mapped to %s", path, lineno, + value, binding_action_map[collision->action]); + return false; + } + } + + conf->bindings.mouse[action] = (struct mouse_binding){i, count, action}; return true; } |
