mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-26 04:40:20 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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}},
|
||||
|
||||
Reference in New Issue
Block a user