aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
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");