nsxivbb577d2
Added command to toggle gif animations
+38 −18
5 files changed
- M commands.c +20 −2
- M commands.h +1 −0
- M config.h +4 −3
- M image.c +7 −11
- M main.c +6 −2
| @@ -41,7 +41,7 @@ extern int filecnt, fileidx; | |||
| 41 | 41 | ||
| 42 | 42 | extern int timo_cursor; | |
| 43 | 43 | extern int timo_redraw; | |
| 44 | − | extern int timo_delay; | |
| 44 | + | extern int timo_adelay; | |
| 45 | 45 | ||
| 46 | 46 | int it_quit(arg_t a) { | |
| 47 | 47 | cleanup(); | |
| @@ -149,7 +149,24 @@ int it_last(arg_t a) { | |||
| 149 | 149 | } | |
| 150 | 150 | ||
| 151 | 151 | int i_navigate_frame(arg_t a) { | |
| 152 | − | return img_frame_navigate(&img, (int) a); | |
| 152 | + | if (mode == MODE_IMAGE && !img.multi.animate) | |
| 153 | + | return img_frame_navigate(&img, (int) a); | |
| 154 | + | else | |
| 155 | + | return 0; | |
| 156 | + | } | |
| 157 | + | ||
| 158 | + | int i_toggle_animation(arg_t a) { | |
| 159 | + | if (mode != MODE_IMAGE) | |
| 160 | + | return 0; | |
| 161 | + | ||
| 162 | + | if (img.multi.animate) { | |
| 163 | + | timo_adelay = 0; | |
| 164 | + | img.multi.animate = 0; | |
| 165 | + | return 0; | |
| 166 | + | } else { | |
| 167 | + | timo_adelay = img_frame_animate(&img, 1); | |
| 168 | + | return 1; | |
| 169 | + | } | |
| 153 | 170 | } | |
| 154 | 171 | ||
| 155 | 172 | int it_move(arg_t a) { | |
| @@ -239,6 +256,7 @@ int i_zoom(arg_t a) { | |||
| 239 | 256 | ||
| 240 | 257 | if (mode != MODE_IMAGE) | |
| 241 | 258 | return 0; | |
| 259 | + | ||
| 242 | 260 | if (scale > 0) | |
| 243 | 261 | return img_zoom_in(&img, &win); | |
| 244 | 262 | else if (scale < 0) | |
| @@ -48,6 +48,7 @@ int i_navigate(arg_t); | |||
| 48 | 48 | int it_first(arg_t); | |
| 49 | 49 | int it_last(arg_t); | |
| 50 | 50 | int i_navigate_frame(arg_t); | |
| 51 | + | int i_toggle_animation(arg_t); | |
| 51 | 52 | int it_move(arg_t); | |
| 52 | 53 | int i_pan_screen(arg_t); | |
| 53 | 54 | int i_pan_edge(arg_t); | |
| @@ -29,7 +29,7 @@ static const float zoom_levels[] = { | |||
| 29 | 29 | 100.0, 150.0, 200.0, 400.0, 800.0 | |
| 30 | 30 | }; | |
| 31 | 31 | ||
| 32 | − | /* default settings for gif images: */ | |
| 32 | + | /* default settings for multi-frame gif images: */ | |
| 33 | 33 | enum { | |
| 34 | 34 | GIF_DELAY = 100, /* delay time (in ms) */ | |
| 35 | 35 | GIF_AUTOPLAY = 1, /* autoplay when loaded [0/1] */ | |
| @@ -64,8 +64,9 @@ static const keymap_t keys[] = { | |||
| 64 | 64 | { False, XK_g, it_first, (arg_t) None }, | |
| 65 | 65 | { False, XK_G, it_last, (arg_t) None }, | |
| 66 | 66 | ||
| 67 | − | { False, XK_N, i_navigate_frame, (arg_t) +1 }, | |
| 68 | − | { False, XK_P, i_navigate_frame, (arg_t) -1 }, | |
| 67 | + | { True, XK_n, i_navigate_frame, (arg_t) +1 }, | |
| 68 | + | { True, XK_p, i_navigate_frame, (arg_t) -1 }, | |
| 69 | + | { True, XK_space, i_toggle_animation, (arg_t) None }, | |
| 69 | 70 | ||
| 70 | 71 | { False, XK_h, it_move, (arg_t) DIR_LEFT }, | |
| 71 | 72 | { False, XK_Left, it_move, (arg_t) DIR_LEFT }, | |
| @@ -596,22 +596,18 @@ int img_frame_animate(img_t *img, int restart) { | |||
| 596 | 596 | if (!img || !img->multi.cnt) | |
| 597 | 597 | return 0; | |
| 598 | 598 | ||
| 599 | − | if (!img->multi.animate && !restart) | |
| 600 | − | return 0; | |
| 601 | − | ||
| 602 | − | if (restart) { | |
| 603 | − | img_frame_goto(img, 0); | |
| 604 | − | img->multi.animate = 1; | |
| 605 | − | } else if (img->multi.sel + 1 >= img->multi.cnt) { | |
| 606 | − | if (!GIF_LOOP) { | |
| 599 | + | if (img->multi.sel + 1 >= img->multi.cnt) { | |
| 600 | + | if (restart || GIF_LOOP) { | |
| 601 | + | img_frame_goto(img, 0); | |
| 602 | + | } else { | |
| 607 | 603 | img->multi.animate = 0; | |
| 608 | 604 | return 0; | |
| 609 | − | } else { | |
| 610 | − | img_frame_goto(img, 0); | |
| 611 | 605 | } | |
| 612 | − | } else { | |
| 606 | + | } else if (!restart) { | |
| 613 | 607 | img_frame_goto(img, img->multi.sel + 1); | |
| 614 | 608 | } | |
| 615 | 609 | ||
| 610 | + | img->multi.animate = 1; | |
| 611 | + | ||
| 616 | 612 | return img->multi.frames[img->multi.sel].delay; | |
| 617 | 613 | } | |
| @@ -142,8 +142,12 @@ void load_image(int new) { | |||
| 142 | 142 | else | |
| 143 | 143 | filesize = 0; | |
| 144 | 144 | ||
| 145 | − | if (img.multi.cnt && img.multi.animate) | |
| 146 | − | timo_adelay = img.multi.frames[img.multi.sel].delay; | |
| 145 | + | if (img.multi.cnt) { | |
| 146 | + | if (img.multi.animate) | |
| 147 | + | timo_adelay = img.multi.frames[img.multi.sel].delay; | |
| 148 | + | else | |
| 149 | + | timo_adelay = 0; | |
| 150 | + | } | |
| 147 | 151 | } | |
| 148 | 152 | ||
| 149 | 153 | void update_title() { | |