summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2014-08-16 11:37:49 +0200
committerBert Münnich <ber.t@posteo.de>2014-08-16 21:48:52 +0200
commit61f61cae5fdf5aa51975bd587497b830684b7867 (patch)
treeda24dcfde194370113d811a1d3e779c11d781b10
parent3b8a79fb8bcde81966514d6a8af18f9db015b3df (diff)
downloadnsxiv-61f61cae5fdf5aa51975bd587497b830684b7867.tar.zst
Generalized thumbnail loading, allows easier reloading of thumbnails later on
-rw-r--r--Makefile2
-rw-r--r--main.c19
-rw-r--r--thumbs.c3
-rw-r--r--thumbs.h2
4 files changed, 16 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 991cc35..e45482f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION = git-20140801
+VERSION = git-20140816
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man
diff --git a/main.c b/main.c
index cb4460d..9deba15 100644
--- a/main.c
+++ b/main.c
@@ -363,11 +363,11 @@ void update_info(void)
return;
mark = files[sel].marked ? "* " : "";
if (mode == MODE_THUMB) {
- if (tns.cnt == filecnt) {
+ if (tns.loadnext >= filecnt) {
n = snprintf(rt, rlen, "%s%0*d/%d", mark, fw, sel + 1, filecnt);
ow_info = true;
} else {
- snprintf(lt, llen, "Loading... %0*d/%d", fw, tns.cnt, filecnt);
+ snprintf(lt, llen, "Loading... %0*d/%d", fw, tns.loadnext, filecnt);
rt[0] = '\0';
ow_info = false;
}
@@ -434,7 +434,7 @@ void reset_cursor(void)
}
}
} else {
- if (tns.cnt != filecnt)
+ if (tns.loadnext < filecnt)
cursor = CURSOR_WATCH;
else
cursor = CURSOR_ARROW;
@@ -655,19 +655,22 @@ void run(void)
set_timeout(redraw, 25, false);
while (true) {
- while (mode == MODE_THUMB && tns.cnt < filecnt &&
+ while (mode == MODE_THUMB && tns.loadnext < filecnt &&
XPending(win.env.dpy) == 0)
{
/* load thumbnails */
set_timeout(redraw, TO_REDRAW_THUMBS, false);
- if (tns_load(&tns, tns.cnt, &files[tns.cnt], false, false)) {
- tns.cnt++;
+ if (tns_load(&tns, tns.loadnext, &files[tns.loadnext], false, false)) {
+ if (tns.cnt == tns.loadnext)
+ tns.cnt++;
} else {
- remove_file(tns.cnt, false);
+ remove_file(tns.loadnext, false);
if (tns.sel > 0 && tns.sel >= tns.cnt)
tns.sel--;
}
- if (tns.cnt == filecnt)
+ while (tns.loadnext < filecnt && tns.thumbs[tns.loadnext].loaded)
+ tns.loadnext++;
+ if (tns.loadnext >= filecnt)
redraw();
else
check_timeouts(NULL);
diff --git a/thumbs.c b/thumbs.c
index f1617fc..c617a45 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -165,7 +165,7 @@ void tns_init(tns_t *tns, int cnt, win_t *win)
tns->thumbs = NULL;
}
tns->cap = cnt;
- tns->cnt = tns->first = tns->sel = 0;
+ tns->cnt = tns->loadnext = tns->first = tns->sel = 0;
tns->win = win;
tns->dirty = false;
@@ -325,6 +325,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
if (!cache_hit)
tns_cache_write(t, true);
+ t->loaded = true;
tns->dirty = true;
return true;
}
diff --git a/thumbs.h b/thumbs.h
index e11ac3c..4de80c3 100644
--- a/thumbs.h
+++ b/thumbs.h
@@ -32,12 +32,14 @@ typedef struct {
int h;
int x;
int y;
+ bool loaded;
} thumb_t;
typedef struct {
thumb_t *thumbs;
int cap;
int cnt;
+ int loadnext;
int first;
int sel;