From 6a0fa2507cc933cfb54fdf4d80c094bfcdf782cf Mon Sep 17 00:00:00 2001 From: Bert Münnich Date: Sat, 4 Jan 2014 18:38:40 +0100 Subject: Slideshow mode is back, in a simplified version --- Makefile | 2 +- README.md | 4 ++++ commands.c | 32 ++++++++++++++++++++++++++++---- commands.h | 3 ++- config.def.h | 5 +++++ image.c | 11 +++++++---- image.h | 6 ++++++ main.c | 27 +++++++++++++++++++++++---- options.c | 41 ++++++++++++++++++++++++----------------- options.h | 1 + sxiv.1 | 10 ++++++++++ 11 files changed, 111 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index caf8bc7..482a0b2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = git-20140103 +VERSION = git-20140104 PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man diff --git a/README.md b/README.md index 23b94f4..7ac00fb 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ of small previews is displayed, making it easy to choose an image to open. -o Write list of marked files to stdout when quitting -q Be quiet, disable warnings -r Search given directories recursively for images + -S DELAY Enable slideshow and set slideshow delay to DELAY seconds -s Scale all images to fit into window -t Start in thumbnail mode -v Print version information and exit @@ -144,9 +145,12 @@ of small previews is displayed, making it easy to choose an image to open. ? Rotate image by 180 degrees |,_ Flip image horizontally/vertically + s Toggle slideshow or set delay to [count] seconds + a Toggle anti-aliasing W Resize window to fit image + **Mouse button mappings:** *Image mode:* diff --git a/commands.c b/commands.c index 9c3d7bf..211d80b 100644 --- a/commands.c +++ b/commands.c @@ -38,6 +38,7 @@ void open_info(void); void redraw(void); void reset_cursor(void); void animate(void); +void slideshow(void); void set_timeout(timeout_f, int, bool); void reset_timeout(timeout_f); @@ -79,6 +80,10 @@ bool it_switch_mode(arg_t a) } img_close(&img, false); reset_timeout(reset_cursor); + if (img.ss.on) { + img.ss.on = false; + reset_timeout(slideshow); + } tns.sel = fileidx; tns.dirty = true; mode = MODE_THUMB; @@ -475,20 +480,30 @@ bool i_flip(arg_t a) } } -bool i_toggle_antialias(arg_t a) +bool i_slideshow(arg_t a) { if (mode == MODE_IMAGE) { - img_toggle_antialias(&img); + if (prefix > 0) { + img.ss.on = true; + img.ss.delay = prefix; + set_timeout(slideshow, img.ss.delay * 1000, true); + } else if (img.ss.on) { + img.ss.on = false; + reset_timeout(slideshow); + } else { + img.ss.on = true; + } return true; } else { return false; } } -bool i_change_gamma(arg_t a) +bool i_toggle_antialias(arg_t a) { if (mode == MODE_IMAGE) { - return img_change_gamma(&img, (long) a); + img_toggle_antialias(&img); + return true; } else { return false; } @@ -504,3 +519,12 @@ bool it_toggle_alpha(arg_t a) return true; } +bool i_change_gamma(arg_t a) +{ + if (mode == MODE_IMAGE) { + return img_change_gamma(&img, (long) a); + } else { + return false; + } +} + diff --git a/commands.h b/commands.h index 1002d92..7d084e2 100644 --- a/commands.h +++ b/commands.h @@ -66,8 +66,9 @@ bool i_fit_to_win(arg_t); bool i_fit_to_img(arg_t); bool i_rotate(arg_t); bool i_flip(arg_t); +bool i_slideshow(arg_t); bool i_toggle_antialias(arg_t); -bool i_change_gamma(arg_t); bool it_toggle_alpha(arg_t); +bool i_change_gamma(arg_t); #endif /* COMMANDS_H */ diff --git a/config.def.h b/config.def.h index 86ba0f5..6c03bc1 100644 --- a/config.def.h +++ b/config.def.h @@ -39,6 +39,9 @@ static const float zoom_levels[] = { 100.0, 150.0, 200.0, 400.0, 800.0 }; +/* default slideshow delay (in sec, overwritten via -S option): */ +enum { SLIDESHOW_DELAY = 5 }; + /* default settings for multi-frame gif images: */ enum { GIF_DELAY = 100, /* delay time (in ms) */ @@ -145,6 +148,8 @@ static const keymap_t keys[] = { { 0, XK_bar, i_flip, (arg_t) FLIP_HORIZONTAL }, { 0, XK_underscore, i_flip, (arg_t) FLIP_VERTICAL }, + { 0, XK_s, i_slideshow, (arg_t) None }, + { 0, XK_a, i_toggle_antialias, (arg_t) None }, { 0, XK_A, it_toggle_alpha, (arg_t) None }, diff --git a/image.c b/image.c index d044a21..21ab3bd 100644 --- a/image.c +++ b/image.c @@ -83,10 +83,13 @@ void img_init(img_t *img, win_t *win) img->alpha = !RENDER_WHITE_ALPHA; img->multi.cap = img->multi.cnt = 0; img->multi.animate = false; - img->multi.repeat = 0; + img->multi.length = img->multi.repeat = 0; img->cmod = imlib_create_color_modifier(); img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE); + + img->ss.on = options->slideshow > 0; + img->ss.delay = options->slideshow > 0 ? options->slideshow : SLIDESHOW_DELAY; } void exif_auto_orientate(const fileinfo_t *file) @@ -143,9 +146,8 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) img->multi.frames = (img_frame_t*) s_malloc(sizeof(img_frame_t) * img->multi.cap); } - img->multi.cnt = 0; - img->multi.sel = 0; - img->multi.repeat = 0; + img->multi.cnt = img->multi.sel = 0; + img->multi.length = img->multi.repeat = 0; #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5 gif = DGifOpenFileName(file->path, NULL); @@ -275,6 +277,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) } img->multi.frames[img->multi.cnt].im = im; img->multi.frames[img->multi.cnt].delay = delay ? delay : GIF_DELAY; + img->multi.length += img->multi.frames[img->multi.cnt].delay; img->multi.cnt++; } } while (rec != TERMINATE_RECORD_TYPE); diff --git a/image.h b/image.h index 7bcfb0b..f83ed6b 100644 --- a/image.h +++ b/image.h @@ -35,6 +35,7 @@ typedef struct { int cnt; int sel; bool animate; + int length; int repeat; } multi_img_t; @@ -59,6 +60,11 @@ typedef struct { Imlib_Color_Modifier cmod; int gamma; + struct { + bool on; + int delay; + } ss; + multi_img_t multi; } img_t; diff --git a/main.c b/main.c index 5789ff0..8094265 100644 --- a/main.c +++ b/main.c @@ -68,6 +68,7 @@ typedef struct { void redraw(void); void reset_cursor(void); void animate(void); +void slideshow(void); void clear_resize(void); appmode_t mode; @@ -96,9 +97,10 @@ struct { } info; timeout_t timeouts[] = { - { { 0, 0 }, false, redraw }, + { { 0, 0 }, false, redraw }, { { 0, 0 }, false, reset_cursor }, - { { 0, 0 }, false, animate }, + { { 0, 0 }, false, animate }, + { { 0, 0 }, false, slideshow }, { { 0, 0 }, false, clear_resize }, }; @@ -304,6 +306,7 @@ void load_image(int new) return; win_set_cursor(&win, CURSOR_WATCH); + reset_timeout(slideshow); if (new != fileidx) alternate = fileidx; @@ -363,6 +366,8 @@ void update_info(void) } } else { n = snprintf(rt, rlen, "%s", mark); + if (img.ss.on) + n += snprintf(rt + n, rlen - n, "%ds | ", img.ss.delay); if (img.gamma != 0) n += snprintf(rt + n, rlen - n, "G%+d | ", img.gamma); n += snprintf(rt + n, rlen - n, "%3d%% | ", (int) (img.zoom * 100.0)); @@ -389,10 +394,18 @@ void update_info(void) void redraw(void) { - if (mode == MODE_IMAGE) + int t; + + if (mode == MODE_IMAGE) { img_render(&img); - else + if (img.ss.on) { + t = img.ss.delay * 1000; + t = img.multi.animate ? MAX(t, img.multi.length) : t; + set_timeout(slideshow, t, false); + } + } else { tns_render(&tns); + } update_info(); win_draw(&win); reset_timeout(redraw); @@ -429,6 +442,12 @@ void animate(void) } } +void slideshow(void) +{ + load_image(fileidx + 1 < filecnt ? fileidx + 1 : 0); + redraw(); +} + void clear_resize(void) { resized = false; diff --git a/options.c b/options.c index e4d597c..6753050 100644 --- a/options.c +++ b/options.c @@ -34,7 +34,7 @@ const options_t *options = (const options_t*) &_options; void print_usage(void) { printf("usage: sxiv [-bcdFfhioqrstvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] " - "[-N name] [-z ZOOM] FILES...\n"); + "[-N NAME] [-S DELAY] [-z ZOOM] FILES...\n"); } void print_version(void) @@ -44,7 +44,7 @@ void print_version(void) void parse_options(int argc, char **argv) { - int opt, t, gamma; + int n, opt; char *end; _options.from_stdin = false; @@ -55,6 +55,7 @@ void parse_options(int argc, char **argv) _options.scalemode = SCALE_MODE; _options.zoom = 1.0; _options.gamma = 0; + _options.slideshow = 0; _options.fixed_win = false; _options.fullscreen = false; @@ -66,7 +67,7 @@ void parse_options(int argc, char **argv) _options.thumb_mode = false; _options.clean_cache = false; - while ((opt = getopt(argc, argv, "bcdFfG:g:hin:N:oqrstvZz:")) != -1) { + while ((opt = getopt(argc, argv, "bcdFfG:g:hin:N:oqrS:stvZz:")) != -1) { switch (opt) { case '?': print_usage(); @@ -87,13 +88,12 @@ void parse_options(int argc, char **argv) _options.fullscreen = true; break; case 'G': - gamma = strtol(optarg, &end, 0); + n = strtol(optarg, &end, 0); if (*end != '\0') { - fprintf(stderr, "sxiv: invalid argument for option -G: %s\n", - optarg); + fprintf(stderr, "sxiv: invalid argument for option -G: %s\n", optarg); exit(EXIT_FAILURE); } - _options.gamma = gamma; + _options.gamma = n; break; case 'g': _options.geometry = optarg; @@ -105,13 +105,12 @@ void parse_options(int argc, char **argv) _options.from_stdin = true; break; case 'n': - if (sscanf(optarg, "%d", &t) <= 0 || t < 1) { - fprintf(stderr, "sxiv: invalid argument for option -n: %s\n", - optarg); + n = strtol(optarg, &end, 0); + if (*end != '\0' || n <= 0) { + fprintf(stderr, "sxiv: invalid argument for option -n: %s\n", optarg); exit(EXIT_FAILURE); - } else { - _options.startnum = t - 1; } + _options.startnum = n - 1; break; case 'N': _options.res_name = optarg; @@ -125,6 +124,14 @@ void parse_options(int argc, char **argv) case 'r': _options.recursive = true; break; + case 'S': + n = strtol(optarg, &end, 0); + if (*end != '\0' || n <= 0) { + fprintf(stderr, "sxiv: invalid argument for option -S: %s\n", optarg); + exit(EXIT_FAILURE); + } + _options.slideshow = n; + break; case 's': _options.scalemode = SCALE_FIT; break; @@ -139,13 +146,13 @@ void parse_options(int argc, char **argv) _options.zoom = 1.0; break; case 'z': - _options.scalemode = SCALE_ZOOM; - if (sscanf(optarg, "%d", &t) <= 0 || t <= 0) { - fprintf(stderr, "sxiv: invalid argument for option -z: %s\n", - optarg); + n = strtol(optarg, &end, 0); + if (*end != '\n' || n <= 0) { + fprintf(stderr, "sxiv: invalid argument for option -z: %s\n", optarg); exit(EXIT_FAILURE); } - _options.zoom = (float) t / 100.0; + _options.scalemode = SCALE_ZOOM; + _options.zoom = (float) n / 100.0; break; } } diff --git a/options.h b/options.h index 982602f..d91cca2 100644 --- a/options.h +++ b/options.h @@ -35,6 +35,7 @@ typedef struct { scalemode_t scalemode; float zoom; int gamma; + int slideshow; /* window: */ bool fixed_win; diff --git a/sxiv.1 b/sxiv.1 index 1fca2dd..9442edb 100644 --- a/sxiv.1 +++ b/sxiv.1 @@ -12,6 +12,8 @@ sxiv \- Simple X Image Viewer .IR NAME ] .RB [ \-n .IR NUM ] +.RB [ \-S +.IR DELAY ] .RB [ \-z .IR ZOOM ] .IR FILE ... @@ -78,6 +80,9 @@ Be quiet, disable warnings to standard error stream. .B \-r Search the given directories recursively for images to view. .TP +.BI "\-S " DELAY +Start in slideshow mode. Set the delay between images to DELAY seconds. +.TP .B \-s Scale all images to fit into window. .TP @@ -302,6 +307,11 @@ Increase gamma. Reset gamma. .SS Miscellaneous .TP +.B s +Toggle slideshow mode and/or set the delay between images to +.I count +seconds. +.TP .B a Toggle anti-aliasing. .TP -- cgit v1.2.3-54-g00ecf