Krolyxon
Commit 095217b

Branches

Refs →

nsxiv095217b

Linked thumbnails to files

Author
Bert
Date
2011-02-17 15:58 +0100
Parent
dc04bdc
Commit
095217b26f43b711c8ebc281110553ec788f7ebe

+13 −16

3 files changed

  1. M main.c +6 −10
  2. M thumbs.c +7 −5
  3. M thumbs.h +0 −1
M main.c View
@@ -55,8 +55,6 @@ const char **filenames;
5555 int filecnt, fileidx;
5656 size_t filesize;
5757
58−int tns_loaded;
59−
6058 #define TITLE_LEN 256
6159 char win_title[TITLE_LEN];
6260
@@ -131,10 +129,8 @@ int main(int argc, char **argv) {
131129 win_open(&win);
132130 img_init(&img, &win);
133131
134− if (options->thumbnails) {
135− tns_loaded = 0;
132+ if (options->thumbnails)
136133 tns_init(&tns, filecnt);
137− }
138134
139135 if (options->thumbnails == 2) {
140136 mode = MODE_THUMBS;
@@ -161,7 +157,7 @@ void update_title() {
161157 if (mode == MODE_THUMBS) {
162158 n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] %s",
163159 tns.cnt ? tns.sel + 1 : 0, tns.cnt,
164− tns.cnt ? tns.thumbs[tns.sel].filename : "");
160+ tns.cnt ? filenames[tns.sel] : "");
165161 } else {
166162 if (img.valid) {
167163 size = filesize;
@@ -490,17 +486,17 @@ void run() {
490486 timeout = 0;
491487
492488 while (1) {
493− if (mode == MODE_THUMBS && tns_loaded < filecnt) {
489+ if (mode == MODE_THUMBS && tns.cnt < filecnt) {
494490 win_set_cursor(&win, CURSOR_WATCH);
495491 gettimeofday(&t0, 0);
496492
497− while (!XPending(win.env.dpy) && tns_loaded < filecnt) {
498− tns_load(&tns, &win, filenames[tns_loaded++]);
493+ while (!XPending(win.env.dpy) && tns.cnt < filecnt) {
494+ tns_load(&tns, &win, filenames[tns.cnt]);
499495 gettimeofday(&t, 0);
500496 if (TV_TO_DOUBLE(t) - TV_TO_DOUBLE(t0) >= 0.25)
501497 break;
502498 }
503− if (tns_loaded == filecnt)
499+ if (tns.cnt == filecnt)
504500 win_set_cursor(&win, CURSOR_ARROW);
505501 if (!XPending(win.env.dpy)) {
506502 redraw();
M thumbs.c View
@@ -25,6 +25,7 @@
2525 #include "thumbs.h"
2626 #include "util.h"
2727
28+extern Imlib_Image *im_broken;
2829 const int thumb_dim = THUMB_SIZE + 10;
2930
3031 void tns_init(tns_t *tns, int cnt) {
@@ -57,19 +58,20 @@ void tns_load(tns_t *tns, win_t *win, const char *filename) {
5758 if (!tns || !win || !filename)
5859 return;
5960
60− if (!(im = imlib_load_image(filename)))
61− return;
62−
63− imlib_context_set_image(im);
61+ if ((im = imlib_load_image(filename)))
62+ imlib_context_set_image(im);
63+ else
64+ imlib_context_set_image(im_broken);
6465
6566 w = imlib_image_get_width();
6667 h = imlib_image_get_height();
6768 zw = (float) THUMB_SIZE / (float) w;
6869 zh = (float) THUMB_SIZE / (float) h;
6970 z = MIN(zw, zh);
71+ if (!im && z > 1.0)
72+ z = 1.0;
7073
7174 t = &tns->thumbs[tns->cnt++];
72− t->filename = filename;
7375 t->w = z * w;
7476 t->h = z * h;
7577
M thumbs.h View
@@ -23,7 +23,6 @@
2323
2424 typedef struct thumb_s {
2525 Pixmap pm;
26− const char *filename;
2726 int x;
2827 int y;
2928 int w;