From e889f417c7edd3d47a54b9464e1b6b72c3f7ae1c Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Wed, 7 Aug 2019 20:21:44 +0100 Subject: imv: Improve slideshow command --- src/imv.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/imv.c') diff --git a/src/imv.c b/src/imv.c index c1f5a3b..d0467eb 100644 --- a/src/imv.c +++ b/src/imv.c @@ -1601,15 +1601,24 @@ static void command_set_slideshow_duration(struct list *args, const char *argstr (void)argstr; struct imv *imv = data; if (args->len == 2) { - long int delta = strtol(args->items[1], NULL, 10); + const char *arg = args->items[1]; + const char prefix = *arg; - /* Ensure we can't go below 0 */ - if (delta < 0 && (size_t)labs(delta) > imv->slideshow.duration) { - imv->slideshow.duration = 0; + int new_duration = imv->slideshow.duration; + + long int arg_num = strtol(arg, NULL, 10); + + if (prefix == '+' || prefix == '-') { + new_duration += arg_num; } else { - imv->slideshow.duration += delta; + new_duration = arg_num; + } + + if (new_duration < 0) { + new_duration = 0; } + imv->slideshow.duration = new_duration; imv->need_redraw = true; } } -- cgit v1.2.3