summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-10-12 09:21:26 +0200
committerwm4 <wm4@nowhere>2012-10-12 10:13:43 +0200
commite1b15dee4c250bf6509594e241eb2856c8d21e0f (patch)
tree180e8796a5e79b9f18fb08193db2e3ca0e8a16f3
parent32fe890cc1f9c90699fb9cd9eb5f42e597d9665a (diff)
downloadmpv-e1b15dee4c250bf6509594e241eb2856c8d21e0f.tar.bz2
mpv-e1b15dee4c250bf6509594e241eb2856c8d21e0f.tar.xz
commands: use "up" and "down" as 2nd argument for cycle command
Allow the values "up" and "down" as step argument for the cycle input command. Previously, this argument was a float, which specified an arbitrary step value and direction (similar to the add command). Instead of "1" and "-1", "up" and "down" is to be used. Float values are still accepted. That capability might be removed in the future, as there's probably hardly any actual use for arbitrary step values.
-rw-r--r--DOCS/man/en/input.rst6
-rw-r--r--etc/input.conf2
-rw-r--r--input/input.c29
3 files changed, 32 insertions, 5 deletions
diff --git a/DOCS/man/en/input.rst b/DOCS/man/en/input.rst
index db16697bd7..58565f0267 100644
--- a/DOCS/man/en/input.rst
+++ b/DOCS/man/en/input.rst
@@ -79,10 +79,10 @@ add <property> [<value>]
Add the given value to the property. On overflow or underflow, clamp the
property to the maximum. If <value> is omitted, assume ``1``.
-cycle <property> [<value>]
- Cycle the given property. Negative values cycle the property backwards. On
+cycle <property> [up|down]
+ Cycle the given property. ``up`` and ``down`` set the cycle direction. On
overflow, set the property back to the minimum, on underflow set it to the
- maximum. If <value> is omitted, assume ``1``.
+ maximum. If ``up`` or ``down`` is omitted, assume ``up``.
speed_mult <value>
Multiply the ``speed`` property by the given value.
diff --git a/etc/input.conf b/etc/input.conf
index edce5e0579..f85d3785d8 100644
--- a/etc/input.conf
+++ b/etc/input.conf
@@ -93,7 +93,7 @@ v cycle sub-visibility
# stretch SSA/ASS subtitles with anamorphic videos to match historical
V cycle ass-vsfilter-aspect-compat
j cycle sub # cycle through subtitles
-J cycle sub -1 # ...backwards
+J cycle sub down # ...backwards
F cycle sub-forced-only
SHARP cycle audio # switch audio streams
_ cycle video
diff --git a/input/input.c b/input/input.c
index 28a5af2112..afaa50a5ce 100644
--- a/input/input.c
+++ b/input/input.c
@@ -100,6 +100,13 @@ struct key_name {
M_CHOICES(c)}, \
.optional = true, .v.i = def }
+static int parse_cycle_dir(const struct m_option *opt, struct bstr name,
+ struct bstr param, void *dst);
+static const struct m_option_type m_option_type_cycle_dir = {
+ .name = "up|down",
+ .parse = parse_cycle_dir,
+};
+
static const mp_cmd_t mp_cmds[] = {
{ MP_CMD_IGNORE, "ignore", },
#ifdef CONFIG_RADIO
@@ -173,7 +180,12 @@ static const mp_cmd_t mp_cmds[] = {
{ MP_CMD_SET, "set", { ARG_STRING, ARG_STRING } },
{ MP_CMD_GET_PROPERTY, "get_property", { ARG_STRING } },
{ MP_CMD_ADD, "add", { ARG_STRING, OARG_FLOAT(0) } },
- { MP_CMD_CYCLE, "cycle", { ARG_STRING, OARG_FLOAT(0) } },
+ { MP_CMD_CYCLE, "cycle", {
+ ARG_STRING,
+ { .type = {"", NULL, &m_option_type_cycle_dir},
+ .optional = true,
+ .v.f = 1 },
+ }},
{ MP_CMD_SET_MOUSE_POS, "set_mouse_pos", { ARG_INT, ARG_INT } },
@@ -730,6 +742,21 @@ int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select,
return 1;
}
+static int parse_cycle_dir(const struct m_option *opt, struct bstr name,
+ struct bstr param, void *dst)
+{
+ float val;
+ if (bstrcmp0(param, "up") == 0) {
+ val = +1;
+ } else if (bstrcmp0(param, "down") == 0) {
+ val = -1;
+ } else {
+ return m_option_type_float.parse(opt, name, param, dst);
+ }
+ *(float *)dst = val;
+ return 1;
+}
+
static bool read_token(bstr str, bstr *out_rest, bstr *out_token)
{
bstr t = bstr_lstrip(str);