summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2017-05-17 20:07:32 +0200
committerBert Münnich <ber.t@posteo.de>2017-05-17 20:07:32 +0200
commit3724d3fc17dc6135a05608cab5bdf00c6978282d (patch)
tree048434245e8c09070f09b7b7851394c95536ba7c /main.c
parentedb117e3bdb4d6bef4a4749d94144df8472c0a4d (diff)
downloadnsxiv-3724d3fc17dc6135a05608cab5bdf00c6978282d.tar.zst
Revised autoreload interface
Make the header only contain the public interface and nothing from the implementation. All functions get a handle to their self object, like the img_ and tns_ and win_ functions. All necessary data (file path) is also passed as an argument, so that no extern redeclarations are needed. Make arl_setup_dir() private, it's not called outside the module. Make arl_handle() return true if the file has changed, so that the reloading of the file can be done by the caller.
Diffstat (limited to 'main.c')
-rw-r--r--main.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/main.c b/main.c
index 6214b94..70f7521 100644
--- a/main.c
+++ b/main.c
@@ -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>
@@ -57,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;
@@ -65,7 +67,6 @@ fileinfo_t *files;
int filecnt, fileidx;
int alternate;
int markcnt;
-autoreload_t autoreload;
int prefix;
bool extprefix;
@@ -100,7 +101,7 @@ timeout_t timeouts[] = {
void cleanup(void)
{
img_close(&img, false);
- arl_cleanup();
+ arl_cleanup(&arl);
tns_free(&tns);
win_close(&win);
}
@@ -320,7 +321,7 @@ void load_image(int new)
info.open = false;
open_info();
- arl_setup();
+ 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);
@@ -676,6 +677,8 @@ void on_buttonpress(XButtonEvent *bev)
prefix = 0;
}
+const struct timespec ten_ms = {0, 10000000};
+
void run(void)
{
int xfd;
@@ -689,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 || autoreload.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);
@@ -712,15 +715,21 @@ void run(void)
FD_SET(info.fd, &fds);
xfd = MAX(xfd, info.fd);
}
- if (autoreload.fd != -1) {
- FD_SET(autoreload.fd, &fds);
- xfd = MAX(xfd, autoreload.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 (autoreload.fd != -1 && FD_ISSET(autoreload.fd, &fds))
- arl_handle();
+ if (arl.fd != -1 && FD_ISSET(arl.fd, &fds)) {
+ if (arl_handle(&arl, files[fileidx].path)) {
+ /* when too fast, imlib2 can't load the image */
+ nanosleep(&ten_ms, NULL);
+ load_image(fileidx);
+ redraw();
+ }
+ }
}
continue;
}
@@ -864,7 +873,7 @@ int main(int argc, char **argv)
win_init(&win);
img_init(&img, &win);
- arl_init();
+ arl_init(&arl);
if ((homedir = getenv("XDG_CONFIG_HOME")) == NULL || homedir[0] == '\0') {
homedir = getenv("HOME");