input: deduplicate mp_input_bind_key

It's just a copypaste of bind_keys with some params set to
hard coded values, so use bind_keys instead.
This commit is contained in:
nanahi 2024-10-23 01:30:20 -04:00 committed by Kacper Michajłow
parent 5b946ac360
commit d97ba359d2
1 changed files with 2 additions and 34 deletions

View File

@ -1646,40 +1646,8 @@ void mp_input_run_cmd(struct input_ctx *ictx, const char **cmd)
void mp_input_bind_key(struct input_ctx *ictx, int key, bstr command)
{
input_lock(ictx);
struct cmd_bind_section *bs = get_bind_section(ictx, (bstr){0});
struct cmd_bind *bind = NULL;
for (int n = 0; n < bs->num_binds; n++) {
struct cmd_bind *b = &bs->binds[n];
if (bind_matches_key(b, 1, &key) && b->is_builtin == false) {
bind = b;
break;
}
}
if (!bind) {
struct cmd_bind empty = {{0}};
MP_TARRAY_APPEND(bs, bs->binds, bs->num_binds, empty);
bind = &bs->binds[bs->num_binds - 1];
}
bind_dealloc(bind);
*bind = (struct cmd_bind) {
.cmd = bstrdup0(bs->binds, command),
.location = talloc_strdup(bs->binds, "keybind-command"),
.owner = bs,
.is_builtin = false,
.num_keys = 1,
};
memcpy(bind->keys, &key, 1 * sizeof(bind->keys[0]));
if (mp_msg_test(ictx->log, MSGL_DEBUG)) {
char *s = mp_input_get_key_combo_name(&key, 1);
MP_TRACE(ictx, "add:section='%.*s' key='%s'%s cmd='%s' location='%s'\n",
BSTR_P(bind->owner->section), s, bind->is_builtin ? " builtin" : "",
bind->cmd, bind->location);
talloc_free(s);
}
bind_keys(ictx, false, (bstr){0}, &key, 1, command,
"keybind-command", NULL);
input_unlock(ictx);
}