diff options
-rw-r--r-- | src/main.c | 11 | ||||
-rw-r--r-- | src/navigator.c | 13 | ||||
-rw-r--r-- | src/navigator.h | 2 |
3 files changed, 18 insertions, 8 deletions
@@ -17,6 +17,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include <stdio.h> #include <stddef.h> +#include <stdint.h> #include <SDL2/SDL.h> #include <SDL2/SDL_ttf.h> #include <FreeImage.h> @@ -310,6 +311,9 @@ int main(int argc, char** argv) unsigned int last_time; unsigned int current_time; + /* keep file change polling rate under control */ + static uint8_t poll_countdown = UINT8_MAX; + /* do we need to redraw the window? */ int need_redraw = 1; @@ -434,7 +438,7 @@ int main(int argc, char** argv) } /* if the user has changed image, start loading the new one */ - if(imv_navigator_poll_changed(&nav)) { + if(imv_navigator_poll_changed(&nav, poll_countdown--)) { const char *current_path = imv_navigator_selection(&nav); if(!current_path) { fprintf(stderr, "No input files left. Exiting.\n"); @@ -476,7 +480,7 @@ int main(int argc, char** argv) } /* handle slideshow */ - if (g_options.delay) { + if(g_options.delay) { unsigned int dt = current_time - last_time; delay_mseconds_passed += dt; @@ -560,6 +564,9 @@ int main(int argc, char** argv) /* redraw complete, unset the flag */ need_redraw = 0; + /* reset poll countdown timer */ + poll_countdown = UINT8_MAX; + /* tell SDL to show the newly drawn frame */ SDL_RenderPresent(renderer); } diff --git a/src/navigator.c b/src/navigator.c index c504cd8..fb2a3cd 100644 --- a/src/navigator.c +++ b/src/navigator.c @@ -210,19 +210,22 @@ int imv_navigator_find_path(struct imv_navigator *nav, const char *path) return -1; } -int imv_navigator_poll_changed(struct imv_navigator *nav) +int imv_navigator_poll_changed(struct imv_navigator *nav, const int nopoll) { if(nav->changed) { nav->changed = 0; return 1; - } else { + } + + if(!nopoll) { struct stat file_info; - if (stat(nav->paths[nav->cur_path], &file_info) == -1) + if(stat(nav->paths[nav->cur_path], &file_info) == -1) { return 0; - if (nav->mtimes[nav->cur_path] != file_info.st_mtim.tv_sec) { + } + if(nav->mtimes[nav->cur_path] != file_info.st_mtim.tv_sec) { nav->mtimes[nav->cur_path] = file_info.st_mtim.tv_sec; return 1; } - return 0; } + return 0; } diff --git a/src/navigator.h b/src/navigator.h index 4fd2fa7..749f656 100644 --- a/src/navigator.h +++ b/src/navigator.h @@ -62,6 +62,6 @@ int imv_navigator_find_path(struct imv_navigator *nav, const char *path); /* Returns 1 if either the currently selected path or underlying file has * changed since last called */ -int imv_navigator_poll_changed(struct imv_navigator *nav); +int imv_navigator_poll_changed(struct imv_navigator *nav, const int nopoll); #endif |