mirror of https://github.com/mpv-player/mpv
command: make "add <property> 0" not change the value
The value 0 was treated specially, and effectively forced the increment to 1. Interestingly, passing 0 or no value also does not include the scale (from touchpads etc.), but this is probably an accidental behavior that was never intentionally added. Simplify it and make the default increment 1. 0 now means what it should: the value will not be changed. This is not particularly useful, but on the other hand there is no need for surprising and unintuitive semantics. OARG_CYCLEDIR() failed to apply the default value, because m_option_type_cycle_dir was missing a copy handler - add this too.
This commit is contained in:
parent
2492b5f119
commit
f1205293a7
|
@ -146,7 +146,7 @@ const struct mp_cmd_def mp_cmds[] = {
|
|||
{ MP_CMD_RUN, "run", { ARG_STRING, ARG_STRING }, .vararg = true },
|
||||
|
||||
{ MP_CMD_SET, "set", { ARG_STRING, ARG_STRING } },
|
||||
{ MP_CMD_ADD, "add", { ARG_STRING, OARG_DOUBLE(0) },
|
||||
{ MP_CMD_ADD, "add", { ARG_STRING, OARG_DOUBLE(1) },
|
||||
.allow_auto_repeat = true},
|
||||
{ MP_CMD_CYCLE, "cycle", {
|
||||
ARG_STRING,
|
||||
|
|
|
@ -471,8 +471,15 @@ static int parse_cycle_dir(struct mp_log *log, const struct m_option *opt,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void copy_opt(const m_option_t *opt, void *dst, const void *src)
|
||||
{
|
||||
if (dst && src)
|
||||
memcpy(dst, src, opt->type->size);
|
||||
}
|
||||
|
||||
const struct m_option_type m_option_type_cycle_dir = {
|
||||
.name = "up|down",
|
||||
.parse = parse_cycle_dir,
|
||||
.copy = copy_opt,
|
||||
.size = sizeof(double),
|
||||
};
|
||||
|
|
|
@ -4286,13 +4286,11 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
|
|||
case MP_CMD_ADD:
|
||||
case MP_CMD_CYCLE:
|
||||
{
|
||||
char *property = cmd->args[0].v.s;
|
||||
struct m_property_switch_arg s = {
|
||||
.inc = 1,
|
||||
.inc = cmd->args[1].v.d * cmd->scale,
|
||||
.wrap = cmd->id == MP_CMD_CYCLE,
|
||||
};
|
||||
if (cmd->args[1].v.d)
|
||||
s.inc = cmd->args[1].v.d * cmd->scale;
|
||||
char *property = cmd->args[0].v.s;
|
||||
if (cmd->repeated && !check_property_autorepeat(property, mpctx)) {
|
||||
MP_VERBOSE(mpctx, "Dropping command '%.*s' from auto-repeated key.\n",
|
||||
BSTR_P(cmd->original));
|
||||
|
|
Loading…
Reference in New Issue