summaryrefslogtreecommitdiffstats
path: root/input/input.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-11-23 01:09:09 +0100
committerwm4 <wm4@nowhere>2019-11-23 01:18:49 +0100
commit2dc6b27ee7715cc7d50944a5bbde0a4d3e97771a (patch)
tree7b345680aee05968ed2f8c850d77ceae127aedf6 /input/input.c
parentf379cf0bf89ca369e6cea957ef20e9e6579ec230 (diff)
downloadmpv-2dc6b27ee7715cc7d50944a5bbde0a4d3e97771a.tar.bz2
mpv-2dc6b27ee7715cc7d50944a5bbde0a4d3e97771a.tar.xz
input: export input.conf comments ot input-bindings property
This is supposed to turn input.conf comments into inline documentation. Whether this will be useful depends on whether there'll be a script using this field. This changes a small aspect of input.conf parsing fundamentally: this attempts to strip comments/whitespace from the command string, which will later be used to generate the command when a key binding is executed. This should not have any negative effects, but there could be unknown bugs. (For some reason, every command is parsed when input.conf is parsed, but it still only stores the string for the command. I guess that saves some minor amount of memory.)
Diffstat (limited to 'input/input.c')
-rw-r--r--input/input.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/input/input.c b/input/input.c
index 77e882a2f2..80457fcd5c 100644
--- a/input/input.c
+++ b/input/input.c
@@ -64,6 +64,7 @@ struct cmd_bind {
int num_keys;
char *cmd;
char *location; // filename/line number of definition
+ char *desc; // human readable description
bool is_builtin;
struct cmd_bind_section *owner;
};
@@ -1149,7 +1150,7 @@ static bool bind_matches_key(struct cmd_bind *bind, int num_keys, const int *key
static void bind_keys(struct input_ctx *ictx, bool builtin, bstr section,
const int *keys, int num_keys, bstr command,
- const char *loc)
+ const char *loc, const char *desc)
{
struct cmd_bind_section *bs = get_bind_section(ictx, section);
struct cmd_bind *bind = NULL;
@@ -1175,6 +1176,7 @@ static void bind_keys(struct input_ctx *ictx, bool builtin, bstr section,
*bind = (struct cmd_bind) {
.cmd = bstrdup0(bs->binds, command),
.location = talloc_strdup(bs->binds, loc),
+ .desc = talloc_strdup(bs->binds, desc),
.owner = bs,
.is_builtin = builtin,
.num_keys = num_keys,
@@ -1250,11 +1252,18 @@ static int parse_config(struct input_ctx *ictx, bool builtin, bstr data,
}
}
- bind_keys(ictx, builtin, section, keys, num_keys, command, cur_loc);
+ // Print warnings if invalid commands are encountered.
+ struct mp_cmd *cmd = mp_input_parse_cmd(ictx, command, cur_loc);
+ const char *desc = NULL;
+ if (cmd) {
+ desc = cmd->desc;
+ command = bstr0(cmd->original);
+ }
+
+ bind_keys(ictx, builtin, section, keys, num_keys, command, cur_loc, desc);
n_binds++;
- // Print warnings if invalid commands are encountered.
- talloc_free(mp_input_parse_cmd(ictx, command, cur_loc));
+ talloc_free(cmd);
}
talloc_free(cur_loc);
@@ -1524,6 +1533,8 @@ struct mpv_node mp_input_get_bindings(struct input_ctx *ictx)
node_map_add_string(entry, "cmd", b->cmd);
node_map_add_flag(entry, "is_weak", b->is_builtin);
node_map_add_int64(entry, "priority", b_priority);
+ if (b->desc)
+ node_map_add_string(entry, "comment", b->desc);
char *key = mp_input_get_key_combo_name(b->keys, b->num_keys);
node_map_add_string(entry, "key", key);