From 6ca7b80750fccb9786c013a7af9f597506786d2c Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 30 Mar 2013 20:07:15 +0100 Subject: input: don't let multi-key bindings block simple key bindings Key bindings can include mutiple keys at once (additional to key modifiers like ctrl etc.). This becomes annoying when quickly switching between two bound keys, e.g. when seeking back and forth, you might end up hitting the "left" and "right" keys at once. The user doesn't expect to invoke the key binding "left-right", but would prefer a key stroke to invoke the binding it was supposed to invoke. So if there's no binding for a multi-key combination, try to find a binding for the key last held down. This preserves the ability to define multi-key combinations, while the common case works as expected. --- core/input/input.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/input/input.c b/core/input/input.c index f9d6333047..3f147c30e2 100644 --- a/core/input/input.c +++ b/core/input/input.c @@ -1142,11 +1142,9 @@ static struct cmd_bind *section_find_bind_for_key(struct input_ctx *ictx, return bs->cmd_binds ? find_bind_for_key(bs->cmd_binds, n, keys) : NULL; } -static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys) +static struct cmd_bind *find_any_bind_for_key(struct input_ctx *ictx, + int n, int *keys) { - if (ictx->test) - return handle_test(ictx, n, keys); - struct cmd_bind *cmd = section_find_bind_for_key(ictx, false, ictx->section, n, keys); if (ictx->default_bindings && cmd == NULL) @@ -1157,6 +1155,20 @@ static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys) if (ictx->default_bindings && cmd == NULL) cmd = section_find_bind_for_key(ictx, true, "default", n, keys); } + return cmd; +} + +static mp_cmd_t *get_cmd_from_keys(struct input_ctx *ictx, int n, int *keys) +{ + if (ictx->test) + return handle_test(ictx, n, keys); + + struct cmd_bind *cmd = find_any_bind_for_key(ictx, n, keys); + if (cmd == NULL && n > 1) { + // Hitting two keys at once, and if there's no binding for this + // combination, the key hit last should be checked. + cmd = find_any_bind_for_key(ictx, 1, (int[]){keys[n - 1]}); + } if (cmd == NULL) { char *key_buf = get_key_combo_name(keys, n); -- cgit v1.2.3