Krolyxon
Commit bb577d2

Branches

Refs →

nsxivbb577d2

Added command to toggle gif animations

Author
Bert
Date
2011-08-19 18:46 +0200
Parent
8b3ae50
Commit
bb577d274dbd9981a726092a504466bc9b5c9bdb

+38 −18

5 files changed

  1. M commands.c +20 −2
  2. M commands.h +1 −0
  3. M config.h +4 −3
  4. M image.c +7 −11
  5. M main.c +6 −2
M commands.c View
@@ -41,7 +41,7 @@ extern int filecnt, fileidx;
4141
4242 extern int timo_cursor;
4343 extern int timo_redraw;
44−extern int timo_delay;
44+extern int timo_adelay;
4545
4646 int it_quit(arg_t a) {
4747 cleanup();
@@ -149,7 +149,24 @@ int it_last(arg_t a) {
149149 }
150150
151151 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+ }
153170 }
154171
155172 int it_move(arg_t a) {
@@ -239,6 +256,7 @@ int i_zoom(arg_t a) {
239256
240257 if (mode != MODE_IMAGE)
241258 return 0;
259+
242260 if (scale > 0)
243261 return img_zoom_in(&img, &win);
244262 else if (scale < 0)
M commands.h View
@@ -48,6 +48,7 @@ int i_navigate(arg_t);
4848 int it_first(arg_t);
4949 int it_last(arg_t);
5050 int i_navigate_frame(arg_t);
51+int i_toggle_animation(arg_t);
5152 int it_move(arg_t);
5253 int i_pan_screen(arg_t);
5354 int i_pan_edge(arg_t);
M config.h View
@@ -29,7 +29,7 @@ static const float zoom_levels[] = {
2929 100.0, 150.0, 200.0, 400.0, 800.0
3030 };
3131
32−/* default settings for gif images: */
32+/* default settings for multi-frame gif images: */
3333 enum {
3434 GIF_DELAY = 100, /* delay time (in ms) */
3535 GIF_AUTOPLAY = 1, /* autoplay when loaded [0/1] */
@@ -64,8 +64,9 @@ static const keymap_t keys[] = {
6464 { False, XK_g, it_first, (arg_t) None },
6565 { False, XK_G, it_last, (arg_t) None },
6666
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 },
6970
7071 { False, XK_h, it_move, (arg_t) DIR_LEFT },
7172 { False, XK_Left, it_move, (arg_t) DIR_LEFT },
M image.c View
@@ -596,22 +596,18 @@ int img_frame_animate(img_t *img, int restart) {
596596 if (!img || !img->multi.cnt)
597597 return 0;
598598
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 {
607603 img->multi.animate = 0;
608604 return 0;
609− } else {
610− img_frame_goto(img, 0);
611605 }
612− } else {
606+ } else if (!restart) {
613607 img_frame_goto(img, img->multi.sel + 1);
614608 }
615609
610+ img->multi.animate = 1;
611+
616612 return img->multi.frames[img->multi.sel].delay;
617613 }
M main.c View
@@ -142,8 +142,12 @@ void load_image(int new) {
142142 else
143143 filesize = 0;
144144
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+ }
147151 }
148152
149153 void update_title() {