From e1b15dee4c250bf6509594e241eb2856c8d21e0f Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Oct 2012 09:21:26 +0200 Subject: 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. --- input/input.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'input') 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); -- cgit v1.2.3