diff options
author | Bert Münnich <ber.t@posteo.de> | 2017-05-17 20:22:23 +0200 |
---|---|---|
committer | Bert Münnich <ber.t@posteo.de> | 2017-05-17 20:22:23 +0200 |
commit | caec32d2578db9973e0ed3d87fbb9974e0b03f04 (patch) | |
tree | 9c8107929e11d0726fc17f07966ac85eccece677 /main.c | |
parent | 1fb3ec576ca4de2056a914b8bc3fd5ba8e99429e (diff) | |
parent | a20173a42df64515c0a5d1c5fba0c056a633a441 (diff) | |
download | nsxiv-caec32d2578db9973e0ed3d87fbb9974e0b03f04.tar.zst |
Merge branch 'autoreload'
Pull request #278.
Fixes issue #29 and issue #199.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -28,6 +28,7 @@ #include <sys/stat.h> #include <sys/time.h> #include <sys/wait.h> +#include <time.h> #include <X11/keysym.h> #include <X11/XF86keysym.h> @@ -38,6 +39,7 @@ #include "thumbs.h" #include "util.h" #include "window.h" +#include "autoreload.h" #define _MAPPINGS_CONFIG #include "config.h" @@ -56,6 +58,7 @@ void slideshow(void); void clear_resize(void); appmode_t mode; +arl_t arl; img_t img; tns_t tns; win_t win; @@ -98,6 +101,7 @@ timeout_t timeouts[] = { void cleanup(void) { img_close(&img, false); + arl_cleanup(&arl); tns_free(&tns); win_close(&win); } @@ -317,6 +321,7 @@ void load_image(int new) info.open = false; open_info(); + arl_setup(&arl, files[fileidx].path); if (img.multi.cnt > 0 && img.multi.animate) set_timeout(animate, img.multi.frames[img.multi.sel].delay, true); @@ -672,6 +677,8 @@ void on_buttonpress(XButtonEvent *bev) prefix = 0; } +const struct timespec ten_ms = {0, 10000000}; + void run(void) { int xfd; @@ -685,8 +692,8 @@ void run(void) init_thumb = mode == MODE_THUMB && tns.initnext < filecnt; load_thumb = mode == MODE_THUMB && tns.loadnext < tns.end; - if ((init_thumb || load_thumb || to_set || info.fd != -1) && - XPending(win.env.dpy) == 0) + if ((init_thumb || load_thumb || to_set || info.fd != -1 || + arl.fd != -1) && XPending(win.env.dpy) == 0) { if (load_thumb) { set_timeout(redraw, TO_REDRAW_THUMBS, false); @@ -708,9 +715,21 @@ void run(void) FD_SET(info.fd, &fds); xfd = MAX(xfd, info.fd); } + if (arl.fd != -1) { + FD_SET(arl.fd, &fds); + xfd = MAX(xfd, arl.fd); + } select(xfd + 1, &fds, 0, 0, to_set ? &timeout : NULL); if (info.fd != -1 && FD_ISSET(info.fd, &fds)) read_info(); + if (arl.fd != -1 && FD_ISSET(arl.fd, &fds)) { + if (arl_handle(&arl)) { + /* when too fast, imlib2 can't load the image */ + nanosleep(&ten_ms, NULL); + load_image(fileidx); + redraw(); + } + } } continue; } @@ -854,6 +873,7 @@ int main(int argc, char **argv) win_init(&win); img_init(&img, &win); + arl_init(&arl); if ((homedir = getenv("XDG_CONFIG_HOME")) == NULL || homedir[0] == '\0') { homedir = getenv("HOME"); |