Browse Source

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

master
Bert 14 years ago
parent
commit
f2b8a75f6c
4 changed files with 66 additions and 64 deletions
  1. +1
    -1
      Makefile
  2. +40
    -35
      main.c
  3. +1
    -2
      options.c
  4. +24
    -26
      thumbs.c

+ 1
- 1
Makefile View File

@@ -1,6 +1,6 @@
all: sxiv all: sxiv


VERSION=git-20110220
VERSION=git-20110221


CC?=gcc CC?=gcc
PREFIX?=/usr/local PREFIX?=/usr/local


+ 40
- 35
main.c View File

@@ -129,15 +129,14 @@ int main(int argc, char **argv) {
win_open(&win); win_open(&win);
img_init(&img, &win); img_init(&img, &win);


if (options->thumbnails)
tns_init(&tns, filecnt);

if (options->thumbnails == 2) {
if (options->thumbnails) {
mode = MODE_THUMBS; mode = MODE_THUMBS;
tns_init(&tns, filecnt);
win_clear(&win); win_clear(&win);
win_draw(&win); win_draw(&win);
} else { } else {
mode = MODE_NORMAL; mode = MODE_NORMAL;
tns.thumbs = NULL;
load_image(); load_image();
img_render(&img, &win); img_render(&img, &win);
} }
@@ -163,11 +162,11 @@ void update_title() {
size = filesize; size = filesize;
size_readable(&size, &unit); size_readable(&size, &unit);
n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] <%d%%> (%.2f%s) %s", n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] <%d%%> (%.2f%s) %s",
fileidx + 1, filecnt, (int) (img.zoom * 100.0), size, unit,
filenames[fileidx]);
fileidx + 1, filecnt, (int) (img.zoom * 100.0), size, unit,
filenames[fileidx]);
} else { } else {
n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] broken: %s", n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] broken: %s",
fileidx + 1, filecnt, filenames[fileidx]);
fileidx + 1, filecnt, filenames[fileidx]);
} }
} }


@@ -309,6 +308,18 @@ void on_keypress(XKeyEvent *kev) {
changed = load_image(); changed = load_image();
} }
break; break;
case XK_g:
if (fileidx != 0) {
fileidx = 0;
changed = load_image();
}
break;
case XK_G:
if (fileidx != filecnt - 1) {
fileidx = filecnt - 1;
changed = load_image();
}
break;


/* zooming */ /* zooming */
case XK_plus: case XK_plus:
@@ -368,10 +379,11 @@ void on_keypress(XKeyEvent *kev) {


/* switch to thumnail mode */ /* switch to thumnail mode */
case XK_Return: case XK_Return:
if (options->thumbnails) {
mode = MODE_THUMBS;
changed = tns.dirty = 1;
}
if (!tns.thumbs)
tns_init(&tns, filecnt);
mode = MODE_THUMBS;
tns.sel = fileidx;
changed = tns.dirty = 1;
break; break;


/* miscellaneous */ /* miscellaneous */
@@ -388,6 +400,7 @@ void on_keypress(XKeyEvent *kev) {
switch (ksym) { switch (ksym) {
/* open selected image */ /* open selected image */
case XK_Return: case XK_Return:
fileidx = tns.sel;
load_image(); load_image();
mode = MODE_NORMAL; mode = MODE_NORMAL;
win_set_cursor(&win, CURSOR_ARROW); win_set_cursor(&win, CURSOR_ARROW);
@@ -411,6 +424,17 @@ void on_keypress(XKeyEvent *kev) {
case XK_Right: case XK_Right:
changed = tns_move_selection(&tns, &win, TNS_RIGHT); changed = tns_move_selection(&tns, &win, TNS_RIGHT);
break; break;
case XK_g:
if (tns.sel != 0) {
tns.sel = 0;
changed = tns.dirty = 1;
}
break;
case XK_G:
if (tns.sel != tns.cnt - 1) {
tns.sel = tns.cnt - 1;
changed = tns.dirty = 1;
}
} }
} }


@@ -423,27 +447,6 @@ void on_keypress(XKeyEvent *kev) {
cleanup(); cleanup();
exit(0); exit(0);


case XK_g:
if (fileidx != 0) {
fileidx = 0;
changed = 1;
if (mode == MODE_NORMAL)
load_image();
else
tns.dirty = 1;
}
break;
case XK_G:
if (fileidx != filecnt - 1) {
fileidx = filecnt - 1;
changed = 1;
if (mode == MODE_NORMAL)
load_image();
else
tns.dirty = 1;
}
break;

case XK_f: case XK_f:
win_toggle_fullscreen(&win); win_toggle_fullscreen(&win);
/* render on next configurenotify */ /* render on next configurenotify */
@@ -511,14 +514,15 @@ void on_buttonpress(XButtonEvent *bev) {
switch (bev->button) { switch (bev->button) {
case Button1: case Button1:
if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) { if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) {
if (sel == fileidx) {
if (sel == tns.sel) {
fileidx = tns.sel;
load_image(); load_image();
mode = MODE_NORMAL; mode = MODE_NORMAL;
win_set_cursor(&win, CURSOR_ARROW); win_set_cursor(&win, CURSOR_ARROW);
} else { } else {
tns_highlight(&tns, &win, fileidx, False);
tns_highlight(&tns, &win, tns.sel, False);
tns_highlight(&tns, &win, sel, True); tns_highlight(&tns, &win, sel, True);
fileidx = sel;
tns.sel = sel;
} }
changed = 1; changed = 1;
break; break;
@@ -585,6 +589,7 @@ void run() {
FD_SET(xfd, &fds); FD_SET(xfd, &fds);


if (!XPending(win.env.dpy) && !select(xfd + 1, &fds, 0, 0, &t)) if (!XPending(win.env.dpy) && !select(xfd + 1, &fds, 0, 0, &t))
/* timeout fired */
redraw(); redraw();
} }




+ 1
- 2
options.c View File

@@ -87,8 +87,7 @@ void parse_options(int argc, char **argv) {
_options.scalemode = SCALE_FIT; _options.scalemode = SCALE_FIT;
break; break;
case 't': case 't':
if (_options.thumbnails < 2)
++_options.thumbnails;
_options.thumbnails = 1;
break; break;
case 'v': case 'v':
print_version(); print_version();


+ 24
- 26
thumbs.c View File

@@ -25,16 +25,14 @@
#include "thumbs.h" #include "thumbs.h"
#include "util.h" #include "util.h"


extern int fileidx;
extern Imlib_Image *im_broken; extern Imlib_Image *im_broken;

const int thumb_dim = THUMB_SIZE + 10; const int thumb_dim = THUMB_SIZE + 10;


void tns_init(tns_t *tns, int cnt) { void tns_init(tns_t *tns, int cnt) {
if (!tns) if (!tns)
return; return;


tns->cnt = tns->first = 0;
tns->cnt = tns->first = tns->sel = 0;
tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t)); tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t));
memset(tns->thumbs, 0, cnt * sizeof(thumb_t)); memset(tns->thumbs, 0, cnt * sizeof(thumb_t));
tns->dirty = 0; tns->dirty = 0;
@@ -43,7 +41,7 @@ void tns_init(tns_t *tns, int cnt) {
void tns_free(tns_t *tns, win_t *win) { void tns_free(tns_t *tns, win_t *win) {
int i; int i;


if (!tns)
if (!tns || !tns->thumbs)
return; return;


for (i = 0; i < tns->cnt; ++i) for (i = 0; i < tns->cnt; ++i)
@@ -94,21 +92,21 @@ void tns_check_view(tns_t *tns, Bool scrolled) {
return; return;


tns->first -= tns->first % tns->cols; tns->first -= tns->first % tns->cols;
r = fileidx % tns->cols;
r = tns->sel % tns->cols;


if (scrolled) { if (scrolled) {
/* move selection into visible area */ /* move selection into visible area */
if (fileidx >= tns->first + tns->cols * tns->rows)
fileidx = tns->first + r + tns->cols * (tns->rows - 1);
else if (fileidx < tns->first)
fileidx = tns->first + r;
if (tns->sel >= tns->first + tns->cols * tns->rows)
tns->sel = tns->first + r + tns->cols * (tns->rows - 1);
else if (tns->sel < tns->first)
tns->sel = tns->first + r;
} else { } else {
/* scroll to selection */ /* scroll to selection */
if (tns->first + tns->cols * tns->rows <= fileidx) {
tns->first = fileidx - r - tns->cols * (tns->rows - 1);
if (tns->first + tns->cols * tns->rows <= tns->sel) {
tns->first = tns->sel - r - tns->cols * (tns->rows - 1);
tns->dirty = 1; tns->dirty = 1;
} else if (tns->first > fileidx) {
tns->first = fileidx - r;
} else if (tns->first > tns->sel) {
tns->first = tns->sel - r;
tns->dirty = 1; tns->dirty = 1;
} }
} }
@@ -156,7 +154,7 @@ void tns_render(tns_t *tns, win_t *win) {
} }


tns->dirty = 0; tns->dirty = 0;
tns_highlight(tns, win, fileidx, True);
tns_highlight(tns, win, tns->sel, True);
} }


void tns_highlight(tns_t *tns, win_t *win, int n, Bool hl) { 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) {
if (!tns || !win) if (!tns || !win)
return 0; return 0;


old = fileidx;
old = tns->sel;


switch (dir) { switch (dir) {
case TNS_LEFT: case TNS_LEFT:
if (fileidx > 0)
--fileidx;
if (tns->sel > 0)
--tns->sel;
break; break;
case TNS_RIGHT: case TNS_RIGHT:
if (fileidx < tns->cnt - 1)
++fileidx;
if (tns->sel < tns->cnt - 1)
++tns->sel;
break; break;
case TNS_UP: case TNS_UP:
if (fileidx >= tns->cols)
fileidx -= tns->cols;
if (tns->sel >= tns->cols)
tns->sel -= tns->cols;
break; break;
case TNS_DOWN: case TNS_DOWN:
if (fileidx + tns->cols < tns->cnt)
fileidx += tns->cols;
if (tns->sel + tns->cols < tns->cnt)
tns->sel += tns->cols;
break; break;
} }


if (fileidx != old) {
if (tns->sel != old) {
tns_highlight(tns, win, old, False); tns_highlight(tns, win, old, False);
tns_check_view(tns, False); tns_check_view(tns, False);
if (!tns->dirty) if (!tns->dirty)
tns_highlight(tns, win, fileidx, True);
tns_highlight(tns, win, tns->sel, True);
} }


return fileidx != old;
return tns->sel != old;
} }


int tns_scroll(tns_t *tns, tnsdir_t dir) { int tns_scroll(tns_t *tns, tnsdir_t dir) {


Loading…
Cancel
Save