summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-03-30 20:07:15 +0100
committerwm4 <wm4@nowhere>2013-04-24 17:46:40 +0200
commit6ca7b80750fccb9786c013a7af9f597506786d2c (patch)
tree4c9f9d47e33577be5f8241ec5af189f6c234061b /core
parent4ab283efe6ca05580944fcc1bf589802f36cce87 (diff)
downloadmpv-6ca7b80750fccb9786c013a7af9f597506786d2c.tar.bz2
mpv-6ca7b80750fccb9786c013a7af9f597506786d2c.tar.xz
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.
Diffstat (limited to 'core')
-rw-r--r--core/input/input.c20
1 files changed, 16 insertions, 4 deletions
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);