nsxivf2b8a75
Always support thumbs; start thumb-mode with single -t
+66 −64
4 files changed
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | all: sxiv | |
| 2 | 2 | ||
| 3 | − | VERSION=git-20110220 | |
| 3 | + | VERSION=git-20110221 | |
| 4 | 4 | ||
| 5 | 5 | CC?=gcc | |
| 6 | 6 | PREFIX?=/usr/local | |
| @@ -129,15 +129,14 @@ int main(int argc, char **argv) { | |||
| 129 | 129 | win_open(&win); | |
| 130 | 130 | img_init(&img, &win); | |
| 131 | 131 | ||
| 132 | − | if (options->thumbnails) | |
| 133 | − | tns_init(&tns, filecnt); | |
| 134 | − | ||
| 135 | − | if (options->thumbnails == 2) { | |
| 132 | + | if (options->thumbnails) { | |
| 136 | 133 | mode = MODE_THUMBS; | |
| 134 | + | tns_init(&tns, filecnt); | |
| 137 | 135 | win_clear(&win); | |
| 138 | 136 | win_draw(&win); | |
| 139 | 137 | } else { | |
| 140 | 138 | mode = MODE_NORMAL; | |
| 139 | + | tns.thumbs = NULL; | |
| 141 | 140 | load_image(); | |
| 142 | 141 | img_render(&img, &win); | |
| 143 | 142 | } | |
| @@ -163,11 +162,11 @@ void update_title() { | |||
| 163 | 162 | size = filesize; | |
| 164 | 163 | size_readable(&size, &unit); | |
| 165 | 164 | 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]); | |
| 168 | 167 | } else { | |
| 169 | 168 | n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] broken: %s", | |
| 170 | − | fileidx + 1, filecnt, filenames[fileidx]); | |
| 169 | + | fileidx + 1, filecnt, filenames[fileidx]); | |
| 171 | 170 | } | |
| 172 | 171 | } | |
| 173 | 172 | ||
| @@ -309,6 +308,18 @@ void on_keypress(XKeyEvent *kev) { | |||
| 309 | 308 | changed = load_image(); | |
| 310 | 309 | } | |
| 311 | 310 | 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; | |
| 312 | 323 | ||
| 313 | 324 | /* zooming */ | |
| 314 | 325 | case XK_plus: | |
| @@ -368,10 +379,11 @@ void on_keypress(XKeyEvent *kev) { | |||
| 368 | 379 | ||
| 369 | 380 | /* switch to thumnail mode */ | |
| 370 | 381 | 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; | |
| 375 | 387 | break; | |
| 376 | 388 | ||
| 377 | 389 | /* miscellaneous */ | |
| @@ -388,6 +400,7 @@ void on_keypress(XKeyEvent *kev) { | |||
| 388 | 400 | switch (ksym) { | |
| 389 | 401 | /* open selected image */ | |
| 390 | 402 | case XK_Return: | |
| 403 | + | fileidx = tns.sel; | |
| 391 | 404 | load_image(); | |
| 392 | 405 | mode = MODE_NORMAL; | |
| 393 | 406 | win_set_cursor(&win, CURSOR_ARROW); | |
| @@ -411,6 +424,17 @@ void on_keypress(XKeyEvent *kev) { | |||
| 411 | 424 | case XK_Right: | |
| 412 | 425 | changed = tns_move_selection(&tns, &win, TNS_RIGHT); | |
| 413 | 426 | 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 | + | } | |
| 414 | 438 | } | |
| 415 | 439 | } | |
| 416 | 440 | ||
| @@ -423,27 +447,6 @@ void on_keypress(XKeyEvent *kev) { | |||
| 423 | 447 | cleanup(); | |
| 424 | 448 | exit(0); | |
| 425 | 449 | ||
| 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 | − | ||
| 447 | 450 | case XK_f: | |
| 448 | 451 | win_toggle_fullscreen(&win); | |
| 449 | 452 | /* render on next configurenotify */ | |
| @@ -511,14 +514,15 @@ void on_buttonpress(XButtonEvent *bev) { | |||
| 511 | 514 | switch (bev->button) { | |
| 512 | 515 | case Button1: | |
| 513 | 516 | if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) { | |
| 514 | − | if (sel == fileidx) { | |
| 517 | + | if (sel == tns.sel) { | |
| 518 | + | fileidx = tns.sel; | |
| 515 | 519 | load_image(); | |
| 516 | 520 | mode = MODE_NORMAL; | |
| 517 | 521 | win_set_cursor(&win, CURSOR_ARROW); | |
| 518 | 522 | } else { | |
| 519 | − | tns_highlight(&tns, &win, fileidx, False); | |
| 523 | + | tns_highlight(&tns, &win, tns.sel, False); | |
| 520 | 524 | tns_highlight(&tns, &win, sel, True); | |
| 521 | − | fileidx = sel; | |
| 525 | + | tns.sel = sel; | |
| 522 | 526 | } | |
| 523 | 527 | changed = 1; | |
| 524 | 528 | break; | |
| @@ -585,6 +589,7 @@ void run() { | |||
| 585 | 589 | FD_SET(xfd, &fds); | |
| 586 | 590 | ||
| 587 | 591 | if (!XPending(win.env.dpy) && !select(xfd + 1, &fds, 0, 0, &t)) | |
| 592 | + | /* timeout fired */ | |
| 588 | 593 | redraw(); | |
| 589 | 594 | } | |
| 590 | 595 | ||
| @@ -87,8 +87,7 @@ void parse_options(int argc, char **argv) { | |||
| 87 | 87 | _options.scalemode = SCALE_FIT; | |
| 88 | 88 | break; | |
| 89 | 89 | case 't': | |
| 90 | − | if (_options.thumbnails < 2) | |
| 91 | − | ++_options.thumbnails; | |
| 90 | + | _options.thumbnails = 1; | |
| 92 | 91 | break; | |
| 93 | 92 | case 'v': | |
| 94 | 93 | print_version(); | |
| @@ -25,16 +25,14 @@ | |||
| 25 | 25 | #include "thumbs.h" | |
| 26 | 26 | #include "util.h" | |
| 27 | 27 | ||
| 28 | − | extern int fileidx; | |
| 29 | 28 | extern Imlib_Image *im_broken; | |
| 30 | − | ||
| 31 | 29 | const int thumb_dim = THUMB_SIZE + 10; | |
| 32 | 30 | ||
| 33 | 31 | void tns_init(tns_t *tns, int cnt) { | |
| 34 | 32 | if (!tns) | |
| 35 | 33 | return; | |
| 36 | 34 | ||
| 37 | − | tns->cnt = tns->first = 0; | |
| 35 | + | tns->cnt = tns->first = tns->sel = 0; | |
| 38 | 36 | tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t)); | |
| 39 | 37 | memset(tns->thumbs, 0, cnt * sizeof(thumb_t)); | |
| 40 | 38 | tns->dirty = 0; | |
| @@ -43,7 +41,7 @@ void tns_init(tns_t *tns, int cnt) { | |||
| 43 | 41 | void tns_free(tns_t *tns, win_t *win) { | |
| 44 | 42 | int i; | |
| 45 | 43 | ||
| 46 | − | if (!tns) | |
| 44 | + | if (!tns || !tns->thumbs) | |
| 47 | 45 | return; | |
| 48 | 46 | ||
| 49 | 47 | for (i = 0; i < tns->cnt; ++i) | |
| @@ -94,21 +92,21 @@ void tns_check_view(tns_t *tns, Bool scrolled) { | |||
| 94 | 92 | return; | |
| 95 | 93 | ||
| 96 | 94 | tns->first -= tns->first % tns->cols; | |
| 97 | − | r = fileidx % tns->cols; | |
| 95 | + | r = tns->sel % tns->cols; | |
| 98 | 96 | ||
| 99 | 97 | if (scrolled) { | |
| 100 | 98 | /* 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; | |
| 105 | 103 | } else { | |
| 106 | 104 | /* 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); | |
| 109 | 107 | 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; | |
| 112 | 110 | tns->dirty = 1; | |
| 113 | 111 | } | |
| 114 | 112 | } | |
| @@ -156,7 +154,7 @@ void tns_render(tns_t *tns, win_t *win) { | |||
| 156 | 154 | } | |
| 157 | 155 | ||
| 158 | 156 | tns->dirty = 0; | |
| 159 | − | tns_highlight(tns, win, fileidx, True); | |
| 157 | + | tns_highlight(tns, win, tns->sel, True); | |
| 160 | 158 | } | |
| 161 | 159 | ||
| 162 | 160 | 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) { | |||
| 179 | 177 | if (!tns || !win) | |
| 180 | 178 | return 0; | |
| 181 | 179 | ||
| 182 | − | old = fileidx; | |
| 180 | + | old = tns->sel; | |
| 183 | 181 | ||
| 184 | 182 | switch (dir) { | |
| 185 | 183 | case TNS_LEFT: | |
| 186 | − | if (fileidx > 0) | |
| 187 | − | --fileidx; | |
| 184 | + | if (tns->sel > 0) | |
| 185 | + | --tns->sel; | |
| 188 | 186 | break; | |
| 189 | 187 | case TNS_RIGHT: | |
| 190 | − | if (fileidx < tns->cnt - 1) | |
| 191 | − | ++fileidx; | |
| 188 | + | if (tns->sel < tns->cnt - 1) | |
| 189 | + | ++tns->sel; | |
| 192 | 190 | break; | |
| 193 | 191 | case TNS_UP: | |
| 194 | − | if (fileidx >= tns->cols) | |
| 195 | − | fileidx -= tns->cols; | |
| 192 | + | if (tns->sel >= tns->cols) | |
| 193 | + | tns->sel -= tns->cols; | |
| 196 | 194 | break; | |
| 197 | 195 | 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; | |
| 200 | 198 | break; | |
| 201 | 199 | } | |
| 202 | 200 | ||
| 203 | − | if (fileidx != old) { | |
| 201 | + | if (tns->sel != old) { | |
| 204 | 202 | tns_highlight(tns, win, old, False); | |
| 205 | 203 | tns_check_view(tns, False); | |
| 206 | 204 | if (!tns->dirty) | |
| 207 | − | tns_highlight(tns, win, fileidx, True); | |
| 205 | + | tns_highlight(tns, win, tns->sel, True); | |
| 208 | 206 | } | |
| 209 | 207 | ||
| 210 | − | return fileidx != old; | |
| 208 | + | return tns->sel != old; | |
| 211 | 209 | } | |
| 212 | 210 | ||
| 213 | 211 | int tns_scroll(tns_t *tns, tnsdir_t dir) { | |