command: add the ability to set comment for keybind command

This allows the keybind to have a comment field which can be
read from input-bindings, and displayed by e.g. stats.lua.
This commit is contained in:
nanahi
2024-10-23 02:01:40 -04:00
committed by Kacper Michajłow
parent affa953dd4
commit 56e2689894
4 changed files with 15 additions and 8 deletions

View File

@@ -924,11 +924,12 @@ Remember to quote string arguments in input.conf (see `Flat command syntax`_).
empty string, ``KEYUP`` will be set on all keys. Otherwise, ``KEYUP`` will
only be set on the key specified by ``name``.
``keybind <name> <cmd>``
``keybind <name> <cmd> [<comment>]``
Binds a key to an input command. ``cmd`` must be a complete command
containing all the desired arguments and flags. Both ``name`` and
``cmd`` use the ``input.conf`` naming scheme. This is primarily
useful for the client API.
``cmd`` use the ``input.conf`` naming scheme. ``comment`` is an optional
string which can be read as the ``comment`` entry of ``input-bindings``.
This is primarily useful for the client API.
``audio-add <url> [<flags> [<title> [<lang>]]]``
Load the given audio file. See ``sub-add`` command.

View File

@@ -1643,11 +1643,12 @@ 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)
void mp_input_bind_key(struct input_ctx *ictx, int key, bstr command,
const char *desc)
{
input_lock(ictx);
bind_keys(ictx, false, (bstr){0}, &key, 1, command,
"keybind-command", NULL);
"keybind-command", desc);
input_unlock(ictx);
}

View File

@@ -216,7 +216,8 @@ bool mp_input_use_media_keys(struct input_ctx *ictx);
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);
void mp_input_bind_key(struct input_ctx *ictx, int key, bstr command,
const char *desc);
void mp_input_set_repeat_info(struct input_ctx *ictx, int rate, int delay);

View File

@@ -6633,7 +6633,10 @@ static void cmd_key_bind(void *p)
return;
}
const char *target_cmd = cmd->args[1].v.s;
mp_input_bind_key(mpctx->input, code, bstr0(target_cmd));
const char *comment = cmd->args[2].v.s;
if (comment && !*comment)
comment = NULL;
mp_input_bind_key(mpctx->input, code, bstr0(target_cmd), comment);
}
static void cmd_apply_profile(void *p)
@@ -7244,7 +7247,8 @@ const struct mp_cmd_def mp_cmds[] = {
{"single", 0}, {"double", 1}),
.flags = MP_CMD_OPT_ARG}}},
{ "keybind", cmd_key_bind, { {"name", OPT_STRING(v.s)},
{"cmd", OPT_STRING(v.s)} }},
{"cmd", OPT_STRING(v.s)},
{"comment", OPT_STRING(v.s), .flags = MP_CMD_OPT_ARG} }},
{ "keypress", cmd_key, { {"name", OPT_STRING(v.s)},
{"scale", OPT_DOUBLE(v.d), OPTDEF_DOUBLE(1)} },
.priv = &(const int){0}},