command: fix keybind command with sequence keys

The command is documented to use the same syntax as input.conf, but
it doesn't work with sequence keys because it uses
mp_input_get_key_from_name for checking key names, when it should
use mp_input_get_keys_from_string instead.

Fix this by using the correct function.
This commit is contained in:
nanahi 2024-10-23 03:17:32 -04:00 committed by Kacper Michajłow
parent 56e2689894
commit 1b9d070786
3 changed files with 19 additions and 11 deletions

View File

@ -1643,13 +1643,23 @@ void mp_input_run_cmd(struct input_ctx *ictx, const char **cmd)
input_unlock(ictx);
}
void mp_input_bind_key(struct input_ctx *ictx, int key, bstr command,
bool mp_input_bind_key(struct input_ctx *ictx, const char *key, bstr command,
const char *desc)
{
char *name = talloc_strdup(NULL, key);
int keys[MP_MAX_KEY_DOWN];
int num_keys = 0;
if (!mp_input_get_keys_from_string(name, MP_MAX_KEY_DOWN, &num_keys, keys)) {
talloc_free(name);
return false;
}
talloc_free(name);
input_lock(ictx);
bind_keys(ictx, false, (bstr){0}, &key, 1, command,
bind_keys(ictx, false, (bstr){0}, keys, num_keys, command,
"keybind-command", desc);
input_unlock(ictx);
return true;
}
struct mpv_node mp_input_get_bindings(struct input_ctx *ictx)

View File

@ -215,8 +215,8 @@ bool mp_input_use_media_keys(struct input_ctx *ictx);
// Like mp_input_parse_cmd_strv, but also run the command.
void mp_input_run_cmd(struct input_ctx *ictx, const char **cmd);
// Binds a command to a key.
void mp_input_bind_key(struct input_ctx *ictx, int key, bstr command,
// Binds a command to a key. Returns true if the bind is successful.
bool mp_input_bind_key(struct input_ctx *ictx, const char *key, bstr command,
const char *desc);
void mp_input_set_repeat_info(struct input_ctx *ictx, int rate, int delay);

View File

@ -6626,17 +6626,15 @@ static void cmd_key_bind(void *p)
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
int code = mp_input_get_key_from_name(cmd->args[0].v.s);
if (code < 0) {
MP_ERR(mpctx, "%s is not a valid input name.\n", cmd->args[0].v.s);
cmd->success = false;
return;
}
const char *key = cmd->args[0].v.s;
const char *target_cmd = cmd->args[1].v.s;
const char *comment = cmd->args[2].v.s;
if (comment && !*comment)
comment = NULL;
mp_input_bind_key(mpctx->input, code, bstr0(target_cmd), comment);
if (!mp_input_bind_key(mpctx->input, key, bstr0(target_cmd), comment)) {
MP_ERR(mpctx, "%s is not a valid input name.\n", key);
cmd->success = false;
}
}
static void cmd_apply_profile(void *p)