mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
4ab283efe6
commit
6ca7b80750
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue