aboutsummaryrefslogtreecommitdiff
path: root/src/imv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/imv.c')
-rw-r--r--src/imv.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/imv.c b/src/imv.c
index ff60d6e..5484c89 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -599,8 +599,18 @@ int imv_run(struct imv *imv)
/* check stdin for any more paths */
check_stdin_for_paths(imv);
} else {
- /* sleep a little bit so we don't waste CPU time */
- SDL_Delay(10);
+ /* sleep until we have something to do */
+ unsigned int timeout = 1000; /* sleep up to a second */
+
+ /* if we need to display the next frame of an animation soon we should
+ * limit our sleep until the next frame is due */
+ const double next_frame_in = imv_loader_time_left(imv->loader);
+ if(next_frame_in > 0.0) {
+ timeout = (unsigned int)(next_frame_in * 1000.0);
+ }
+
+ /* go to sleep until an input event, etc. or the timeout expires */
+ SDL_WaitEventTimeout(NULL, timeout);
}
}