Update title when moving selection

This commit is contained in:
Bert 2011-02-19 09:47:53 +01:00
parent c6726ed331
commit a367d35ba0
4 changed files with 22 additions and 13 deletions

View file

@ -1,6 +1,6 @@
all: sxiv all: sxiv
VERSION=git-20110218 VERSION=git-20110219
CC?=gcc CC?=gcc
PREFIX?=/usr/local PREFIX?=/usr/local

12
main.c
View file

@ -386,7 +386,7 @@ void on_keypress(XKeyEvent *kev) {
else else
tns.sel = 0; tns.sel = 0;
mode = MODE_THUMBS; mode = MODE_THUMBS;
changed = 1; changed = tns.dirty = 1;
} }
break; break;
@ -416,19 +416,19 @@ void on_keypress(XKeyEvent *kev) {
/* move selection */ /* move selection */
case XK_h: case XK_h:
case XK_Left: case XK_Left:
tns_move_selection(&tns, &win, MOVE_LEFT); changed = tns_move_selection(&tns, &win, MOVE_LEFT);
break; break;
case XK_j: case XK_j:
case XK_Down: case XK_Down:
tns_move_selection(&tns, &win, MOVE_DOWN); changed = tns_move_selection(&tns, &win, MOVE_DOWN);
break; break;
case XK_k: case XK_k:
case XK_Up: case XK_Up:
tns_move_selection(&tns, &win, MOVE_UP); changed = tns_move_selection(&tns, &win, MOVE_UP);
break; break;
case XK_l: case XK_l:
case XK_Right: case XK_Right:
tns_move_selection(&tns, &win, MOVE_RIGHT); changed = tns_move_selection(&tns, &win, MOVE_RIGHT);
break; break;
} }
} }
@ -594,6 +594,8 @@ void run() {
timeout = 75000; timeout = 75000;
if (mode == MODE_NORMAL) if (mode == MODE_NORMAL)
img.checkpan = 1; img.checkpan = 1;
else
tns.dirty = 1;
} }
break; break;
case ClientMessage: case ClientMessage:

View file

@ -35,6 +35,7 @@ void tns_init(tns_t *tns, int cnt) {
tns->cnt = tns->first = tns->sel = 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;
} }
void tns_free(tns_t *tns, win_t *win) { void tns_free(tns_t *tns, win_t *win) {
@ -81,12 +82,14 @@ void tns_load(tns_t *tns, win_t *win, const char *filename) {
imlib_render_image_part_on_drawable_at_size(0, 0, w, h, imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
0, 0, t->w, t->h); 0, 0, t->w, t->h);
imlib_free_image(); imlib_free_image();
tns->dirty = 1;
} }
void tns_render(tns_t *tns, win_t *win) { void tns_render(tns_t *tns, win_t *win) {
int i, cnt, x, y; int i, cnt, x, y;
if (!tns || !win) if (!tns || !tns->dirty || !win)
return; return;
tns->cols = MAX(1, win->w / thumb_dim); tns->cols = MAX(1, win->w / thumb_dim);
@ -117,6 +120,8 @@ void tns_render(tns_t *tns, win_t *win) {
} }
} }
tns->dirty = 0;
tns_highlight(tns, win, -1); tns_highlight(tns, win, -1);
} }
@ -138,13 +143,13 @@ void tns_highlight(tns_t *tns, win_t *win, int old) {
win_draw(win); win_draw(win);
} }
void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) { int tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
int sel, old; int sel, old;
if (!tns || !win) if (!tns || !win)
return; return 0;
sel = tns->sel; sel = old = tns->sel;
switch (dir) { switch (dir) {
case MOVE_LEFT: case MOVE_LEFT:
@ -165,11 +170,12 @@ void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
break; break;
} }
if (sel != tns->sel && tns->thumbs[sel].x != 0) { if (sel != old && tns->thumbs[sel].x != 0) {
old = tns->sel;
tns->sel = sel; tns->sel = sel;
tns_highlight(tns, win, old); tns_highlight(tns, win, old);
} }
return sel != old;
} }
int tns_translate(tns_t *tns, int x, int y) { int tns_translate(tns_t *tns, int x, int y) {

View file

@ -45,6 +45,7 @@ typedef struct tns_s {
int rows; int rows;
int first; int first;
int sel; int sel;
unsigned char dirty;
} tns_t; } tns_t;
void tns_init(tns_t*, int); void tns_init(tns_t*, int);
@ -55,7 +56,7 @@ void tns_load(tns_t*, win_t*, const char*);
void tns_render(tns_t*, win_t*); void tns_render(tns_t*, win_t*);
void tns_highlight(tns_t*, win_t*, int); void tns_highlight(tns_t*, win_t*, int);
void tns_move_selection(tns_t*, win_t*, movedir_t); int tns_move_selection(tns_t*, win_t*, movedir_t);
int tns_translate(tns_t*, int, int); int tns_translate(tns_t*, int, int);