Krolyxon
Commit 61f61ca

Branches

Refs →

nsxiv61f61ca

Generalized thumbnail loading, allows easier reloading of thumbnails later on

Author
Bert Münnich
Date
2014-08-16 11:37 +0200
Committer
Bert Münnich · 2014-08-16 21:48 +0200
Parent
3b8a79f
Commit
61f61cae5fdf5aa51975bd587497b830684b7867

+16 −10

4 files changed

  1. M Makefile +1 −1
  2. M main.c +11 −8
  3. M thumbs.c +2 −1
  4. M thumbs.h +2 −0
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20140801
1+VERSION = git-20140816
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
M main.c View
@@ -363,11 +363,11 @@ void update_info(void)
363363 return;
364364 mark = files[sel].marked ? "* " : "";
365365 if (mode == MODE_THUMB) {
366− if (tns.cnt == filecnt) {
366+ if (tns.loadnext >= filecnt) {
367367 n = snprintf(rt, rlen, "%s%0*d/%d", mark, fw, sel + 1, filecnt);
368368 ow_info = true;
369369 } else {
370− snprintf(lt, llen, "Loading... %0*d/%d", fw, tns.cnt, filecnt);
370+ snprintf(lt, llen, "Loading... %0*d/%d", fw, tns.loadnext, filecnt);
371371 rt[0] = '\0';
372372 ow_info = false;
373373 }
@@ -434,7 +434,7 @@ void reset_cursor(void)
434434 }
435435 }
436436 } else {
437− if (tns.cnt != filecnt)
437+ if (tns.loadnext < filecnt)
438438 cursor = CURSOR_WATCH;
439439 else
440440 cursor = CURSOR_ARROW;
@@ -655,19 +655,22 @@ void run(void)
655655 set_timeout(redraw, 25, false);
656656
657657 while (true) {
658− while (mode == MODE_THUMB && tns.cnt < filecnt &&
658+ while (mode == MODE_THUMB && tns.loadnext < filecnt &&
659659 XPending(win.env.dpy) == 0)
660660 {
661661 /* load thumbnails */
662662 set_timeout(redraw, TO_REDRAW_THUMBS, false);
663− if (tns_load(&tns, tns.cnt, &files[tns.cnt], false, false)) {
664− tns.cnt++;
663+ if (tns_load(&tns, tns.loadnext, &files[tns.loadnext], false, false)) {
664+ if (tns.cnt == tns.loadnext)
665+ tns.cnt++;
665666 } else {
666− remove_file(tns.cnt, false);
667+ remove_file(tns.loadnext, false);
667668 if (tns.sel > 0 && tns.sel >= tns.cnt)
668669 tns.sel--;
669670 }
670− if (tns.cnt == filecnt)
671+ while (tns.loadnext < filecnt && tns.thumbs[tns.loadnext].loaded)
672+ tns.loadnext++;
673+ if (tns.loadnext >= filecnt)
671674 redraw();
672675 else
673676 check_timeouts(NULL);
M thumbs.c View
@@ -165,7 +165,7 @@ void tns_init(tns_t *tns, int cnt, win_t *win)
165165 tns->thumbs = NULL;
166166 }
167167 tns->cap = cnt;
168− tns->cnt = tns->first = tns->sel = 0;
168+ tns->cnt = tns->loadnext = tns->first = tns->sel = 0;
169169 tns->win = win;
170170 tns->dirty = false;
171171
@@ -325,6 +325,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
325325 if (!cache_hit)
326326 tns_cache_write(t, true);
327327
328+ t->loaded = true;
328329 tns->dirty = true;
329330 return true;
330331 }
M thumbs.h View
@@ -32,12 +32,14 @@ typedef struct {
3232 int h;
3333 int x;
3434 int y;
35+ bool loaded;
3536 } thumb_t;
3637
3738 typedef struct {
3839 thumb_t *thumbs;
3940 int cap;
4041 int cnt;
42+ int loadnext;
4143 int first;
4244 int sel;
4345