Krolyxon
Commit f2b8a75

Branches

Refs →

nsxivf2b8a75

Always support thumbs; start thumb-mode with single -t

Author
Bert
Date
2011-02-21 14:59 +0100
Parent
72e8baf
Commit
f2b8a75f6cb3a9cbbaddd2e16f9ba9105b650142

+66 −64

4 files changed

  1. M Makefile +1 −1
  2. M main.c +40 −35
  3. M options.c +1 −2
  4. M thumbs.c +24 −26
M Makefile View
@@ -1,6 +1,6 @@
11 all: sxiv
22
3−VERSION=git-20110220
3+VERSION=git-20110221
44
55 CC?=gcc
66 PREFIX?=/usr/local
M main.c View
@@ -129,15 +129,14 @@ int main(int argc, char **argv) {
129129 win_open(&win);
130130 img_init(&img, &win);
131131
132− if (options->thumbnails)
133− tns_init(&tns, filecnt);
134−
135− if (options->thumbnails == 2) {
132+ if (options->thumbnails) {
136133 mode = MODE_THUMBS;
134+ tns_init(&tns, filecnt);
137135 win_clear(&win);
138136 win_draw(&win);
139137 } else {
140138 mode = MODE_NORMAL;
139+ tns.thumbs = NULL;
141140 load_image();
142141 img_render(&img, &win);
143142 }
@@ -163,11 +162,11 @@ void update_title() {
163162 size = filesize;
164163 size_readable(&size, &unit);
165164 n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] <%d%%> (%.2f%s) %s",
166− fileidx + 1, filecnt, (int) (img.zoom * 100.0), size, unit,
167− filenames[fileidx]);
165+ fileidx + 1, filecnt, (int) (img.zoom * 100.0), size, unit,
166+ filenames[fileidx]);
168167 } else {
169168 n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] broken: %s",
170− fileidx + 1, filecnt, filenames[fileidx]);
169+ fileidx + 1, filecnt, filenames[fileidx]);
171170 }
172171 }
173172
@@ -309,6 +308,18 @@ void on_keypress(XKeyEvent *kev) {
309308 changed = load_image();
310309 }
311310 break;
311+ case XK_g:
312+ if (fileidx != 0) {
313+ fileidx = 0;
314+ changed = load_image();
315+ }
316+ break;
317+ case XK_G:
318+ if (fileidx != filecnt - 1) {
319+ fileidx = filecnt - 1;
320+ changed = load_image();
321+ }
322+ break;
312323
313324 /* zooming */
314325 case XK_plus:
@@ -368,10 +379,11 @@ void on_keypress(XKeyEvent *kev) {
368379
369380 /* switch to thumnail mode */
370381 case XK_Return:
371− if (options->thumbnails) {
372− mode = MODE_THUMBS;
373− changed = tns.dirty = 1;
374− }
382+ if (!tns.thumbs)
383+ tns_init(&tns, filecnt);
384+ mode = MODE_THUMBS;
385+ tns.sel = fileidx;
386+ changed = tns.dirty = 1;
375387 break;
376388
377389 /* miscellaneous */
@@ -388,6 +400,7 @@ void on_keypress(XKeyEvent *kev) {
388400 switch (ksym) {
389401 /* open selected image */
390402 case XK_Return:
403+ fileidx = tns.sel;
391404 load_image();
392405 mode = MODE_NORMAL;
393406 win_set_cursor(&win, CURSOR_ARROW);
@@ -411,6 +424,17 @@ void on_keypress(XKeyEvent *kev) {
411424 case XK_Right:
412425 changed = tns_move_selection(&tns, &win, TNS_RIGHT);
413426 break;
427+ case XK_g:
428+ if (tns.sel != 0) {
429+ tns.sel = 0;
430+ changed = tns.dirty = 1;
431+ }
432+ break;
433+ case XK_G:
434+ if (tns.sel != tns.cnt - 1) {
435+ tns.sel = tns.cnt - 1;
436+ changed = tns.dirty = 1;
437+ }
414438 }
415439 }
416440
@@ -423,27 +447,6 @@ void on_keypress(XKeyEvent *kev) {
423447 cleanup();
424448 exit(0);
425449
426− case XK_g:
427− if (fileidx != 0) {
428− fileidx = 0;
429− changed = 1;
430− if (mode == MODE_NORMAL)
431− load_image();
432− else
433− tns.dirty = 1;
434− }
435− break;
436− case XK_G:
437− if (fileidx != filecnt - 1) {
438− fileidx = filecnt - 1;
439− changed = 1;
440− if (mode == MODE_NORMAL)
441− load_image();
442− else
443− tns.dirty = 1;
444− }
445− break;
446−
447450 case XK_f:
448451 win_toggle_fullscreen(&win);
449452 /* render on next configurenotify */
@@ -511,14 +514,15 @@ void on_buttonpress(XButtonEvent *bev) {
511514 switch (bev->button) {
512515 case Button1:
513516 if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) {
514− if (sel == fileidx) {
517+ if (sel == tns.sel) {
518+ fileidx = tns.sel;
515519 load_image();
516520 mode = MODE_NORMAL;
517521 win_set_cursor(&win, CURSOR_ARROW);
518522 } else {
519− tns_highlight(&tns, &win, fileidx, False);
523+ tns_highlight(&tns, &win, tns.sel, False);
520524 tns_highlight(&tns, &win, sel, True);
521− fileidx = sel;
525+ tns.sel = sel;
522526 }
523527 changed = 1;
524528 break;
@@ -585,6 +589,7 @@ void run() {
585589 FD_SET(xfd, &fds);
586590
587591 if (!XPending(win.env.dpy) && !select(xfd + 1, &fds, 0, 0, &t))
592+ /* timeout fired */
588593 redraw();
589594 }
590595
M options.c View
@@ -87,8 +87,7 @@ void parse_options(int argc, char **argv) {
8787 _options.scalemode = SCALE_FIT;
8888 break;
8989 case 't':
90− if (_options.thumbnails < 2)
91− ++_options.thumbnails;
90+ _options.thumbnails = 1;
9291 break;
9392 case 'v':
9493 print_version();
M thumbs.c View
@@ -25,16 +25,14 @@
2525 #include "thumbs.h"
2626 #include "util.h"
2727
28−extern int fileidx;
2928 extern Imlib_Image *im_broken;
30−
3129 const int thumb_dim = THUMB_SIZE + 10;
3230
3331 void tns_init(tns_t *tns, int cnt) {
3432 if (!tns)
3533 return;
3634
37− tns->cnt = tns->first = 0;
35+ tns->cnt = tns->first = tns->sel = 0;
3836 tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t));
3937 memset(tns->thumbs, 0, cnt * sizeof(thumb_t));
4038 tns->dirty = 0;
@@ -43,7 +41,7 @@ void tns_init(tns_t *tns, int cnt) {
4341 void tns_free(tns_t *tns, win_t *win) {
4442 int i;
4543
46− if (!tns)
44+ if (!tns || !tns->thumbs)
4745 return;
4846
4947 for (i = 0; i < tns->cnt; ++i)
@@ -94,21 +92,21 @@ void tns_check_view(tns_t *tns, Bool scrolled) {
9492 return;
9593
9694 tns->first -= tns->first % tns->cols;
97− r = fileidx % tns->cols;
95+ r = tns->sel % tns->cols;
9896
9997 if (scrolled) {
10098 /* move selection into visible area */
101− if (fileidx >= tns->first + tns->cols * tns->rows)
102− fileidx = tns->first + r + tns->cols * (tns->rows - 1);
103− else if (fileidx < tns->first)
104− fileidx = tns->first + r;
99+ if (tns->sel >= tns->first + tns->cols * tns->rows)
100+ tns->sel = tns->first + r + tns->cols * (tns->rows - 1);
101+ else if (tns->sel < tns->first)
102+ tns->sel = tns->first + r;
105103 } else {
106104 /* scroll to selection */
107− if (tns->first + tns->cols * tns->rows <= fileidx) {
108− tns->first = fileidx - r - tns->cols * (tns->rows - 1);
105+ if (tns->first + tns->cols * tns->rows <= tns->sel) {
106+ tns->first = tns->sel - r - tns->cols * (tns->rows - 1);
109107 tns->dirty = 1;
110− } else if (tns->first > fileidx) {
111− tns->first = fileidx - r;
108+ } else if (tns->first > tns->sel) {
109+ tns->first = tns->sel - r;
112110 tns->dirty = 1;
113111 }
114112 }
@@ -156,7 +154,7 @@ void tns_render(tns_t *tns, win_t *win) {
156154 }
157155
158156 tns->dirty = 0;
159− tns_highlight(tns, win, fileidx, True);
157+ tns_highlight(tns, win, tns->sel, True);
160158 }
161159
162160 void tns_highlight(tns_t *tns, win_t *win, int n, Bool hl) {
@@ -179,35 +177,35 @@ int tns_move_selection(tns_t *tns, win_t *win, tnsdir_t dir) {
179177 if (!tns || !win)
180178 return 0;
181179
182− old = fileidx;
180+ old = tns->sel;
183181
184182 switch (dir) {
185183 case TNS_LEFT:
186− if (fileidx > 0)
187− --fileidx;
184+ if (tns->sel > 0)
185+ --tns->sel;
188186 break;
189187 case TNS_RIGHT:
190− if (fileidx < tns->cnt - 1)
191− ++fileidx;
188+ if (tns->sel < tns->cnt - 1)
189+ ++tns->sel;
192190 break;
193191 case TNS_UP:
194− if (fileidx >= tns->cols)
195− fileidx -= tns->cols;
192+ if (tns->sel >= tns->cols)
193+ tns->sel -= tns->cols;
196194 break;
197195 case TNS_DOWN:
198− if (fileidx + tns->cols < tns->cnt)
199− fileidx += tns->cols;
196+ if (tns->sel + tns->cols < tns->cnt)
197+ tns->sel += tns->cols;
200198 break;
201199 }
202200
203− if (fileidx != old) {
201+ if (tns->sel != old) {
204202 tns_highlight(tns, win, old, False);
205203 tns_check_view(tns, False);
206204 if (!tns->dirty)
207− tns_highlight(tns, win, fileidx, True);
205+ tns_highlight(tns, win, tns->sel, True);
208206 }
209207
210− return fileidx != old;
208+ return tns->sel != old;
211209 }
212210
213211 int tns_scroll(tns_t *tns, tnsdir_t dir) {