Krolyxon
Commit 6a0fa25

Branches

Refs →

nsxiv6a0fa25

Slideshow mode is back, in a simplified version

Author
Bert Münnich
Date
2014-01-04 18:38 +0100
Committer
Bert Münnich · 2014-01-04 19:07 +0100
Parent
0e81802
Commit
6a0fa2507cc933cfb54fdf4d80c094bfcdf782cf

+111 −31

11 files changed

  1. M Makefile +1 −1
  2. M README.md +4 −0
  3. M commands.c +28 −4
  4. M commands.h +2 −1
  5. M config.def.h +5 −0
  6. M image.c +7 −4
  7. M image.h +6 −0
  8. M main.c +23 −4
  9. M options.c +24 −17
  10. M options.h +1 −0
  11. M sxiv.1 +10 −0
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20140103
1+VERSION = git-20140104
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
M README.md View
@@ -83,6 +83,7 @@ of small previews is displayed, making it easy to choose an image to open.
8383 -o Write list of marked files to stdout when quitting
8484 -q Be quiet, disable warnings
8585 -r Search given directories recursively for images
86+ -S DELAY Enable slideshow and set slideshow delay to DELAY seconds
8687 -s Scale all images to fit into window
8788 -t Start in thumbnail mode
8889 -v Print version information and exit
@@ -144,9 +145,12 @@ of small previews is displayed, making it easy to choose an image to open.
144145 ? Rotate image by 180 degrees
145146 |,_ Flip image horizontally/vertically
146147
148+ s Toggle slideshow or set delay to [count] seconds
149+
147150 a Toggle anti-aliasing
148151 W Resize window to fit image
149152
153+
150154 **Mouse button mappings:**
151155
152156 *Image mode:*
M commands.c View
@@ -38,6 +38,7 @@ void open_info(void);
3838 void redraw(void);
3939 void reset_cursor(void);
4040 void animate(void);
41+void slideshow(void);
4142 void set_timeout(timeout_f, int, bool);
4243 void reset_timeout(timeout_f);
4344
@@ -79,6 +80,10 @@ bool it_switch_mode(arg_t a)
7980 }
8081 img_close(&img, false);
8182 reset_timeout(reset_cursor);
83+ if (img.ss.on) {
84+ img.ss.on = false;
85+ reset_timeout(slideshow);
86+ }
8287 tns.sel = fileidx;
8388 tns.dirty = true;
8489 mode = MODE_THUMB;
@@ -475,20 +480,30 @@ bool i_flip(arg_t a)
475480 }
476481 }
477482
478−bool i_toggle_antialias(arg_t a)
483+bool i_slideshow(arg_t a)
479484 {
480485 if (mode == MODE_IMAGE) {
481− img_toggle_antialias(&img);
486+ if (prefix > 0) {
487+ img.ss.on = true;
488+ img.ss.delay = prefix;
489+ set_timeout(slideshow, img.ss.delay * 1000, true);
490+ } else if (img.ss.on) {
491+ img.ss.on = false;
492+ reset_timeout(slideshow);
493+ } else {
494+ img.ss.on = true;
495+ }
482496 return true;
483497 } else {
484498 return false;
485499 }
486500 }
487501
488−bool i_change_gamma(arg_t a)
502+bool i_toggle_antialias(arg_t a)
489503 {
490504 if (mode == MODE_IMAGE) {
491− return img_change_gamma(&img, (long) a);
505+ img_toggle_antialias(&img);
506+ return true;
492507 } else {
493508 return false;
494509 }
@@ -504,3 +519,12 @@ bool it_toggle_alpha(arg_t a)
504519 return true;
505520 }
506521
522+bool i_change_gamma(arg_t a)
523+{
524+ if (mode == MODE_IMAGE) {
525+ return img_change_gamma(&img, (long) a);
526+ } else {
527+ return false;
528+ }
529+}
530+
M commands.h View
@@ -66,8 +66,9 @@ bool i_fit_to_win(arg_t);
6666 bool i_fit_to_img(arg_t);
6767 bool i_rotate(arg_t);
6868 bool i_flip(arg_t);
69+bool i_slideshow(arg_t);
6970 bool i_toggle_antialias(arg_t);
70−bool i_change_gamma(arg_t);
7171 bool it_toggle_alpha(arg_t);
72+bool i_change_gamma(arg_t);
7273
7374 #endif /* COMMANDS_H */
M config.def.h View
@@ -39,6 +39,9 @@ static const float zoom_levels[] = {
3939 100.0, 150.0, 200.0, 400.0, 800.0
4040 };
4141
42+/* default slideshow delay (in sec, overwritten via -S option): */
43+enum { SLIDESHOW_DELAY = 5 };
44+
4245 /* default settings for multi-frame gif images: */
4346 enum {
4447 GIF_DELAY = 100, /* delay time (in ms) */
@@ -145,6 +148,8 @@ static const keymap_t keys[] = {
145148 { 0, XK_bar, i_flip, (arg_t) FLIP_HORIZONTAL },
146149 { 0, XK_underscore, i_flip, (arg_t) FLIP_VERTICAL },
147150
151+ { 0, XK_s, i_slideshow, (arg_t) None },
152+
148153 { 0, XK_a, i_toggle_antialias, (arg_t) None },
149154 { 0, XK_A, it_toggle_alpha, (arg_t) None },
150155
M image.c View
@@ -83,10 +83,13 @@ void img_init(img_t *img, win_t *win)
8383 img->alpha = !RENDER_WHITE_ALPHA;
8484 img->multi.cap = img->multi.cnt = 0;
8585 img->multi.animate = false;
86− img->multi.repeat = 0;
86+ img->multi.length = img->multi.repeat = 0;
8787
8888 img->cmod = imlib_create_color_modifier();
8989 img->gamma = MIN(MAX(options->gamma, -GAMMA_RANGE), GAMMA_RANGE);
90+
91+ img->ss.on = options->slideshow > 0;
92+ img->ss.delay = options->slideshow > 0 ? options->slideshow : SLIDESHOW_DELAY;
9093 }
9194
9295 void exif_auto_orientate(const fileinfo_t *file)
@@ -143,9 +146,8 @@ bool img_load_gif(img_t *img, const fileinfo_t *file)
143146 img->multi.frames = (img_frame_t*)
144147 s_malloc(sizeof(img_frame_t) * img->multi.cap);
145148 }
146− img->multi.cnt = 0;
147− img->multi.sel = 0;
148− img->multi.repeat = 0;
149+ img->multi.cnt = img->multi.sel = 0;
150+ img->multi.length = img->multi.repeat = 0;
149151
150152 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
151153 gif = DGifOpenFileName(file->path, NULL);
@@ -275,6 +277,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file)
275277 }
276278 img->multi.frames[img->multi.cnt].im = im;
277279 img->multi.frames[img->multi.cnt].delay = delay ? delay : GIF_DELAY;
280+ img->multi.length += img->multi.frames[img->multi.cnt].delay;
278281 img->multi.cnt++;
279282 }
280283 } while (rec != TERMINATE_RECORD_TYPE);
M image.h View
@@ -35,6 +35,7 @@ typedef struct {
3535 int cnt;
3636 int sel;
3737 bool animate;
38+ int length;
3839 int repeat;
3940 } multi_img_t;
4041
@@ -59,6 +60,11 @@ typedef struct {
5960 Imlib_Color_Modifier cmod;
6061 int gamma;
6162
63+ struct {
64+ bool on;
65+ int delay;
66+ } ss;
67+
6268 multi_img_t multi;
6369 } img_t;
6470
M main.c View
@@ -68,6 +68,7 @@ typedef struct {
6868 void redraw(void);
6969 void reset_cursor(void);
7070 void animate(void);
71+void slideshow(void);
7172 void clear_resize(void);
7273
7374 appmode_t mode;
@@ -96,9 +97,10 @@ struct {
9697 } info;
9798
9899 timeout_t timeouts[] = {
99− { { 0, 0 }, false, redraw },
100+ { { 0, 0 }, false, redraw },
100101 { { 0, 0 }, false, reset_cursor },
101− { { 0, 0 }, false, animate },
102+ { { 0, 0 }, false, animate },
103+ { { 0, 0 }, false, slideshow },
102104 { { 0, 0 }, false, clear_resize },
103105 };
104106
@@ -304,6 +306,7 @@ void load_image(int new)
304306 return;
305307
306308 win_set_cursor(&win, CURSOR_WATCH);
309+ reset_timeout(slideshow);
307310
308311 if (new != fileidx)
309312 alternate = fileidx;
@@ -363,6 +366,8 @@ void update_info(void)
363366 }
364367 } else {
365368 n = snprintf(rt, rlen, "%s", mark);
369+ if (img.ss.on)
370+ n += snprintf(rt + n, rlen - n, "%ds | ", img.ss.delay);
366371 if (img.gamma != 0)
367372 n += snprintf(rt + n, rlen - n, "G%+d | ", img.gamma);
368373 n += snprintf(rt + n, rlen - n, "%3d%% | ", (int) (img.zoom * 100.0));
@@ -389,10 +394,18 @@ void update_info(void)
389394
390395 void redraw(void)
391396 {
392− if (mode == MODE_IMAGE)
397+ int t;
398+
399+ if (mode == MODE_IMAGE) {
393400 img_render(&img);
394− else
401+ if (img.ss.on) {
402+ t = img.ss.delay * 1000;
403+ t = img.multi.animate ? MAX(t, img.multi.length) : t;
404+ set_timeout(slideshow, t, false);
405+ }
406+ } else {
395407 tns_render(&tns);
408+ }
396409 update_info();
397410 win_draw(&win);
398411 reset_timeout(redraw);
@@ -429,6 +442,12 @@ void animate(void)
429442 }
430443 }
431444
445+void slideshow(void)
446+{
447+ load_image(fileidx + 1 < filecnt ? fileidx + 1 : 0);
448+ redraw();
449+}
450+
432451 void clear_resize(void)
433452 {
434453 resized = false;
M options.c View
@@ -34,7 +34,7 @@ const options_t *options = (const options_t*) &_options;
3434 void print_usage(void)
3535 {
3636 printf("usage: sxiv [-bcdFfhioqrstvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] "
37− "[-N name] [-z ZOOM] FILES...\n");
37+ "[-N NAME] [-S DELAY] [-z ZOOM] FILES...\n");
3838 }
3939
4040 void print_version(void)
@@ -44,7 +44,7 @@ void print_version(void)
4444
4545 void parse_options(int argc, char **argv)
4646 {
47− int opt, t, gamma;
47+ int n, opt;
4848 char *end;
4949
5050 _options.from_stdin = false;
@@ -55,6 +55,7 @@ void parse_options(int argc, char **argv)
5555 _options.scalemode = SCALE_MODE;
5656 _options.zoom = 1.0;
5757 _options.gamma = 0;
58+ _options.slideshow = 0;
5859
5960 _options.fixed_win = false;
6061 _options.fullscreen = false;
@@ -66,7 +67,7 @@ void parse_options(int argc, char **argv)
6667 _options.thumb_mode = false;
6768 _options.clean_cache = false;
6869
69− while ((opt = getopt(argc, argv, "bcdFfG:g:hin:N:oqrstvZz:")) != -1) {
70+ while ((opt = getopt(argc, argv, "bcdFfG:g:hin:N:oqrS:stvZz:")) != -1) {
7071 switch (opt) {
7172 case '?':
7273 print_usage();
@@ -87,13 +88,12 @@ void parse_options(int argc, char **argv)
8788 _options.fullscreen = true;
8889 break;
8990 case 'G':
90− gamma = strtol(optarg, &end, 0);
91+ n = strtol(optarg, &end, 0);
9192 if (*end != '\0') {
92− fprintf(stderr, "sxiv: invalid argument for option -G: %s\n",
93− optarg);
93+ fprintf(stderr, "sxiv: invalid argument for option -G: %s\n", optarg);
9494 exit(EXIT_FAILURE);
9595 }
96− _options.gamma = gamma;
96+ _options.gamma = n;
9797 break;
9898 case 'g':
9999 _options.geometry = optarg;
@@ -105,13 +105,12 @@ void parse_options(int argc, char **argv)
105105 _options.from_stdin = true;
106106 break;
107107 case 'n':
108− if (sscanf(optarg, "%d", &t) <= 0 || t < 1) {
109− fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
110− optarg);
108+ n = strtol(optarg, &end, 0);
109+ if (*end != '\0' || n <= 0) {
110+ fprintf(stderr, "sxiv: invalid argument for option -n: %s\n", optarg);
111111 exit(EXIT_FAILURE);
112− } else {
113− _options.startnum = t - 1;
114112 }
113+ _options.startnum = n - 1;
115114 break;
116115 case 'N':
117116 _options.res_name = optarg;
@@ -125,6 +124,14 @@ void parse_options(int argc, char **argv)
125124 case 'r':
126125 _options.recursive = true;
127126 break;
127+ case 'S':
128+ n = strtol(optarg, &end, 0);
129+ if (*end != '\0' || n <= 0) {
130+ fprintf(stderr, "sxiv: invalid argument for option -S: %s\n", optarg);
131+ exit(EXIT_FAILURE);
132+ }
133+ _options.slideshow = n;
134+ break;
128135 case 's':
129136 _options.scalemode = SCALE_FIT;
130137 break;
@@ -139,13 +146,13 @@ void parse_options(int argc, char **argv)
139146 _options.zoom = 1.0;
140147 break;
141148 case 'z':
142− _options.scalemode = SCALE_ZOOM;
143− if (sscanf(optarg, "%d", &t) <= 0 || t <= 0) {
144− fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
145− optarg);
149+ n = strtol(optarg, &end, 0);
150+ if (*end != '\n' || n <= 0) {
151+ fprintf(stderr, "sxiv: invalid argument for option -z: %s\n", optarg);
146152 exit(EXIT_FAILURE);
147153 }
148− _options.zoom = (float) t / 100.0;
154+ _options.scalemode = SCALE_ZOOM;
155+ _options.zoom = (float) n / 100.0;
149156 break;
150157 }
151158 }
M options.h View
@@ -35,6 +35,7 @@ typedef struct {
3535 scalemode_t scalemode;
3636 float zoom;
3737 int gamma;
38+ int slideshow;
3839
3940 /* window: */
4041 bool fixed_win;
M sxiv.1 View
@@ -12,6 +12,8 @@ sxiv \- Simple X Image Viewer
1212 .IR NAME ]
1313 .RB [ \-n
1414 .IR NUM ]
15+.RB [ \-S
16+.IR DELAY ]
1517 .RB [ \-z
1618 .IR ZOOM ]
1719 .IR FILE ...
@@ -78,6 +80,9 @@ Be quiet, disable warnings to standard error stream.
7880 .B \-r
7981 Search the given directories recursively for images to view.
8082 .TP
83+.BI "\-S " DELAY
84+Start in slideshow mode. Set the delay between images to DELAY seconds.
85+.TP
8186 .B \-s
8287 Scale all images to fit into window.
8388 .TP
@@ -302,6 +307,11 @@ Increase gamma.
302307 Reset gamma.
303308 .SS Miscellaneous
304309 .TP
310+.B s
311+Toggle slideshow mode and/or set the delay between images to
312+.I count
313+seconds.
314+.TP
305315 .B a
306316 Toggle anti-aliasing.
307317 .TP