diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | commands.c | 4 | ||||
-rw-r--r-- | image.c | 6 | ||||
-rw-r--r-- | image.h | 3 | ||||
-rw-r--r-- | main.c | 19 | ||||
-rw-r--r-- | options.c | 23 | ||||
-rw-r--r-- | options.h | 3 | ||||
-rw-r--r-- | sxiv.1 | 14 |
8 files changed, 54 insertions, 20 deletions
@@ -1,4 +1,4 @@ -VERSION := git-20161030 +VERSION := git-20161201 PREFIX := /usr/local MANPREFIX := $(PREFIX)/share/man @@ -429,8 +429,8 @@ bool ci_slideshow(arg_t _) { if (prefix > 0) { img.ss.on = true; - img.ss.delay = prefix; - set_timeout(slideshow, img.ss.delay * 1000, true); + img.ss.delay = prefix * 10; + set_timeout(slideshow, img.ss.delay * 100, true); } else if (img.ss.on) { img.ss.on = false; reset_timeout(slideshow); @@ -68,14 +68,15 @@ void img_init(img_t *img, win_t *win) img->alpha = ALPHA_LAYER; img->multi.cap = img->multi.cnt = 0; img->multi.animate = options->animate; + img->multi.framedelay = options->framerate > 0 ? 1000 / options->framerate : 0; img->multi.length = 0; img->cmod = imlib_create_color_modifier(); imlib_context_set_color_modifier(img->cmod); img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE); - img->ss.on = options->slideshow > 0.0; - img->ss.delay = options->slideshow > 0.0 ? options->slideshow : SLIDESHOW_DELAY; + img->ss.on = options->slideshow > 0; + img->ss.delay = options->slideshow > 0 ? options->slideshow : SLIDESHOW_DELAY * 10; } #if HAVE_LIBEXIF @@ -263,6 +264,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) img->multi.cap * sizeof(img_frame_t)); } img->multi.frames[img->multi.cnt].im = im; + delay = img->multi.framedelay > 0 ? img->multi.framedelay : delay; img->multi.frames[img->multi.cnt].delay = delay > 0 ? delay : DEF_GIF_DELAY; img->multi.length += img->multi.frames[img->multi.cnt].delay; img->multi.cnt++; @@ -35,6 +35,7 @@ typedef struct { int cnt; int sel; bool animate; + int framedelay; int length; } multi_img_t; @@ -60,7 +61,7 @@ typedef struct { struct { bool on; - float delay; + int delay; } ss; multi_img_t multi; @@ -371,8 +371,12 @@ void update_info(void) bar_put(r, "%s%0*d/%d", mark, fw, fileidx + 1, filecnt); } else { bar_put(r, "%s", mark); - if (img.ss.on) - bar_put(r, "%2.1fs | ", img.ss.delay); + if (img.ss.on) { + if (img.ss.delay % 10 != 0) + bar_put(r, "%2.1fs | ", (float)img.ss.delay / 10); + else + bar_put(r, "%ds | ", img.ss.delay / 10); + } if (img.gamma != 0) bar_put(r, "G%+d | ", img.gamma); bar_put(r, "%3d%% | ", (int) (img.zoom * 100.0)); @@ -403,7 +407,7 @@ void redraw(void) if (mode == MODE_IMAGE) { img_render(&img); if (img.ss.on) { - t = img.ss.delay * 1000; + t = img.ss.delay * 100; if (img.multi.cnt > 0 && img.multi.animate) t = MAX(t, img.multi.length); set_timeout(slideshow, t, false); @@ -458,6 +462,11 @@ void clear_resize(void) resized = false; } +Bool is_input_ev(Display *dpy, XEvent *ev, XPointer arg) +{ + return ev->type == ButtonPress || ev->type == KeyPress; +} + void run_key_handler(const char *key, unsigned int mask) { pid_t pid; @@ -468,6 +477,7 @@ void run_key_handler(const char *key, unsigned int mask) int fcnt = marked ? markcnt : 1; char kstr[32]; struct stat *oldst, st; + XEvent dump; if (keyhandler.f.err != 0) { if (!keyhandler.warned) { @@ -538,6 +548,9 @@ void run_key_handler(const char *key, unsigned int mask) f++; } } + /* drop user input events that occured while running the key handler */ + while (XCheckIfEvent(win.env.dpy, &dump, is_input_ev, NULL)); + end: if (mode == MODE_IMAGE) { if (changed) { @@ -32,8 +32,9 @@ const options_t *options = (const options_t*) &_options; void print_usage(void) { - printf("usage: sxiv [-abcfhioqrtvZ] [-e WID] [-G GAMMA] [-g GEOMETRY] " - "[-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] FILES...\n"); + printf("usage: sxiv [-abcfhioqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] " + "[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] " + "FILES...\n"); } void print_version(void) @@ -44,7 +45,6 @@ void print_version(void) void parse_options(int argc, char **argv) { int n, opt; - float f; char *end, *s; const char *scalemodes = "dfwh"; @@ -60,7 +60,8 @@ void parse_options(int argc, char **argv) _options.zoom = 1.0; _options.animate = false; _options.gamma = 0; - _options.slideshow = 0.0; + _options.slideshow = 0; + _options.framerate = 0; _options.fullscreen = false; _options.embed = 0; @@ -72,11 +73,17 @@ void parse_options(int argc, char **argv) _options.thumb_mode = false; _options.clean_cache = false; - while ((opt = getopt(argc, argv, "abce:fG:g:hin:N:oqrS:s:tvZz:")) != -1) { + while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:oqrS:s:tvZz:")) != -1) { switch (opt) { case '?': print_usage(); exit(EXIT_FAILURE); + case 'A': + n = strtol(optarg, &end, 0); + if (*end != '\0' || n <= 0) + error(EXIT_FAILURE, 0, "Invalid argument for option -A: %s", optarg); + _options.framerate = n; + /* fall through */ case 'a': _options.animate = true; break; @@ -129,10 +136,10 @@ void parse_options(int argc, char **argv) _options.recursive = true; break; case 'S': - f = (float) strtof(optarg, &end); - if (*end != '\0' || f <= 0.0) + n = strtof(optarg, &end) * 10; + if (*end != '\0' || n <= 0) error(EXIT_FAILURE, 0, "Invalid argument for option -S: %s", optarg); - _options.slideshow = (float) f; + _options.slideshow = n; break; case 's': s = strchr(scalemodes, optarg[0]); @@ -36,7 +36,8 @@ typedef struct { float zoom; bool animate; int gamma; - float slideshow; + int slideshow; + int framerate; /* window: */ bool fullscreen; @@ -4,6 +4,8 @@ sxiv \- Simple X Image Viewer .SH SYNOPSIS .B sxiv .RB [ \-abcfhioqrtvZ ] +.RB [ \-A +.IR FRAMERATE ] .RB [ \-e .IR WID ] .RB [ \-G @@ -33,6 +35,10 @@ Please note, that the fullscreen mode requires an EWMH/NetWM compliant window manager. .SH OPTIONS .TP +.BI "\-A " FRAMERATE +Play animations with a constant frame rate set to +.IR FRAMERATE . +.TP .B \-a Play animations of multi-frame images. .TP @@ -81,7 +87,11 @@ Be quiet, disable warnings to standard error stream. Search the given directories recursively for images to view. .TP .BI "\-S " DELAY -Start in slideshow mode. Set the delay between images to DELAY (float, e.g. 1, 3.1, 0.01) seconds. +Start in slideshow mode. Set the delay between images to +.I DELAY +seconds. +.I DELAY +may be a floating point number. .TP .BI "\-s " MODE Set scale mode according to MODE character. Supported modes are: [d]own, @@ -330,7 +340,7 @@ Toggle visibility of alpha-channel, i.e. image transparency. .TP .B s Toggle slideshow mode and/or set the delay between images to -.I count (integer prefix only) +.I count seconds. .SH MOUSE COMMANDS The following mouse mappings are available in image mode: |