From 20f0334e1314508683651b0e5c59fd637d1d13f5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 11 Aug 2020 09:55:33 +0200 Subject: config: add mouse specific bind actions This extends the "normal" bind action enum with mouse specific actions. When parsing key bindings, we only check up to the last valid keyboard binding, while mouse bindings support *both* key actions and mouse actions. The new actions are: * select-begin: starts an interactive selection * select-extend: interactively extend an existing selection * select-word: select word under cursor * select-word-whitespace: select word under cursor, where the only word separating characters are whitespace characters. The old hard-coded selection "bindings" have been converted to instead use these actions, via default bindings added to the configuration. --- config.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 8e51b608..69883b68 100644 --- a/config.c +++ b/config.c @@ -69,6 +69,12 @@ static const char *const binding_action_map[] = { [BIND_ACTION_PIPE_SCROLLBACK] = "pipe-scrollback", [BIND_ACTION_PIPE_VIEW] = "pipe-visible", [BIND_ACTION_PIPE_SELECTED] = "pipe-selected", + + /* Mouse-specific actions */ + [BIND_ACTION_SELECT_BEGIN] = "select-begin", + [BIND_ACTION_SELECT_WORD] = "select-word", + [BIND_ACTION_SELECT_WORD_WS] = "select-word-whitespace", + [BIND_ACTION_SELECT_EXTEND] = "select-extend", }; static_assert(ALEN(binding_action_map) == BIND_ACTION_COUNT, @@ -643,7 +649,8 @@ parse_section_csd(const char *key, const char *value, struct config *conf, } else { - LOG_AND_NOTIFY_ERR("%s:%u: [csd]: %s: invalid key", path, lineno, key); + LOG_AND_NOTIFY_ERR("%s:%u: [csd]: %s: invalid action", + path, lineno, key); return false; } @@ -859,7 +866,7 @@ parse_section_key_bindings( } for (enum bind_action_normal action = 0; - action < BIND_ACTION_COUNT; + action < BIND_ACTION_KEY_COUNT; action++) { if (binding_action_map[action] == NULL) @@ -932,7 +939,8 @@ parse_section_key_bindings( return true; } - LOG_AND_NOTIFY_ERR("%s:%u: [key-bindings]: %s: invalid key", path, lineno, key); + LOG_AND_NOTIFY_ERR("%s:%u: [key-bindings]: %s: invalid action", + path, lineno, key); return false; } @@ -1121,7 +1129,10 @@ parse_section_mouse_bindings( const char *key, const char *value, struct config *conf, const char *path, unsigned lineno) { - for (enum bind_action_normal action = 0; action < BIND_ACTION_COUNT; action++) { + for (enum bind_action_normal action = 0; + action < BIND_ACTION_COUNT; + action++) + { if (binding_action_map[action] == NULL) continue; @@ -1519,8 +1530,13 @@ add_default_mouse_bindings(struct config *conf) } while (0) const struct config_key_modifiers none = {}; + const struct config_key_modifiers ctrl = {.ctrl = true}; add_binding(BIND_ACTION_PRIMARY_PASTE, none, BTN_MIDDLE, 1); + add_binding(BIND_ACTION_SELECT_BEGIN, none, BTN_LEFT, 1); + add_binding(BIND_ACTION_SELECT_WORD, none, BTN_LEFT, 2); + add_binding(BIND_ACTION_SELECT_WORD_WS, ctrl, BTN_LEFT, 2); + add_binding(BIND_ACTION_SELECT_EXTEND, none, BTN_RIGHT, 1); #undef add_binding } -- cgit v1.3