Krolyxon
Commit a367d35

Branches

Refs →

nsxiva367d35

Update title when moving selection

Author
Bert
Date
2011-02-19 09:47 +0100
Parent
c6726ed
Commit
a367d35ba0f9edf8a01f7d98d9f58df9df292c15

+22 −13

4 files changed

  1. M Makefile +1 −1
  2. M main.c +7 −5
  3. M thumbs.c +12 −6
  4. M thumbs.h +2 −1
M Makefile View
@@ -1,6 +1,6 @@
11 all: sxiv
22
3−VERSION=git-20110218
3+VERSION=git-20110219
44
55 CC?=gcc
66 PREFIX?=/usr/local
M main.c View
@@ -386,7 +386,7 @@ void on_keypress(XKeyEvent *kev) {
386386 else
387387 tns.sel = 0;
388388 mode = MODE_THUMBS;
389− changed = 1;
389+ changed = tns.dirty = 1;
390390 }
391391 break;
392392
@@ -416,19 +416,19 @@ void on_keypress(XKeyEvent *kev) {
416416 /* move selection */
417417 case XK_h:
418418 case XK_Left:
419− tns_move_selection(&tns, &win, MOVE_LEFT);
419+ changed = tns_move_selection(&tns, &win, MOVE_LEFT);
420420 break;
421421 case XK_j:
422422 case XK_Down:
423− tns_move_selection(&tns, &win, MOVE_DOWN);
423+ changed = tns_move_selection(&tns, &win, MOVE_DOWN);
424424 break;
425425 case XK_k:
426426 case XK_Up:
427− tns_move_selection(&tns, &win, MOVE_UP);
427+ changed = tns_move_selection(&tns, &win, MOVE_UP);
428428 break;
429429 case XK_l:
430430 case XK_Right:
431− tns_move_selection(&tns, &win, MOVE_RIGHT);
431+ changed = tns_move_selection(&tns, &win, MOVE_RIGHT);
432432 break;
433433 }
434434 }
@@ -594,6 +594,8 @@ void run() {
594594 timeout = 75000;
595595 if (mode == MODE_NORMAL)
596596 img.checkpan = 1;
597+ else
598+ tns.dirty = 1;
597599 }
598600 break;
599601 case ClientMessage:
M thumbs.c View
@@ -35,6 +35,7 @@ void tns_init(tns_t *tns, int cnt) {
3535 tns->cnt = tns->first = tns->sel = 0;
3636 tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t));
3737 memset(tns->thumbs, 0, cnt * sizeof(thumb_t));
38+ tns->dirty = 0;
3839 }
3940
4041 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) {
8182 imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
8283 0, 0, t->w, t->h);
8384 imlib_free_image();
85+
86+ tns->dirty = 1;
8487 }
8588
8689 void tns_render(tns_t *tns, win_t *win) {
8790 int i, cnt, x, y;
8891
89− if (!tns || !win)
92+ if (!tns || !tns->dirty || !win)
9093 return;
9194
9295 tns->cols = MAX(1, win->w / thumb_dim);
@@ -117,6 +120,8 @@ void tns_render(tns_t *tns, win_t *win) {
117120 }
118121 }
119122
123+ tns->dirty = 0;
124+
120125 tns_highlight(tns, win, -1);
121126 }
122127
@@ -138,13 +143,13 @@ void tns_highlight(tns_t *tns, win_t *win, int old) {
138143 win_draw(win);
139144 }
140145
141−void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
146+int tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
142147 int sel, old;
143148
144149 if (!tns || !win)
145− return;
150+ return 0;
146151
147− sel = tns->sel;
152+ sel = old = tns->sel;
148153
149154 switch (dir) {
150155 case MOVE_LEFT:
@@ -165,11 +170,12 @@ void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
165170 break;
166171 }
167172
168− if (sel != tns->sel && tns->thumbs[sel].x != 0) {
169− old = tns->sel;
173+ if (sel != old && tns->thumbs[sel].x != 0) {
170174 tns->sel = sel;
171175 tns_highlight(tns, win, old);
172176 }
177+
178+ return sel != old;
173179 }
174180
175181 int tns_translate(tns_t *tns, int x, int y) {
M thumbs.h View
@@ -45,6 +45,7 @@ typedef struct tns_s {
4545 int rows;
4646 int first;
4747 int sel;
48+ unsigned char dirty;
4849 } tns_t;
4950
5051 void tns_init(tns_t*, int);
@@ -55,7 +56,7 @@ void tns_load(tns_t*, win_t*, const char*);
5556 void tns_render(tns_t*, win_t*);
5657 void tns_highlight(tns_t*, win_t*, int);
5758
58−void tns_move_selection(tns_t*, win_t*, movedir_t);
59+int tns_move_selection(tns_t*, win_t*, movedir_t);
5960
6061 int tns_translate(tns_t*, int, int);
6162