aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c32
-rw-r--r--thumbs.c39
-rw-r--r--thumbs.h9
3 files changed, 78 insertions, 2 deletions
diff --git a/main.c b/main.c
index bc6d9a3..79b562f 100644
--- a/main.c
+++ b/main.c
@@ -268,7 +268,7 @@ void redraw() {
}
void on_keypress(XKeyEvent *kev) {
- int x, y;
+ int sel, x, y;
unsigned int w, h;
char key;
KeySym ksym;
@@ -388,6 +388,36 @@ void on_keypress(XKeyEvent *kev) {
break;
}
} else {
+ /* thumbnail mode */
+ sel = tns.sel;
+
+ switch (ksym) {
+ /* open selected image */
+ case XK_Return:
+ fileidx = sel;
+ load_image();
+ mode = MODE_NORMAL;
+ changed = 1;
+ break;
+
+ /* move selection */
+ case XK_h:
+ case XK_Left:
+ tns_move_selection(&tns, &win, MOVE_LEFT);
+ break;
+ case XK_j:
+ case XK_Down:
+ tns_move_selection(&tns, &win, MOVE_DOWN);
+ break;
+ case XK_k:
+ case XK_Up:
+ tns_move_selection(&tns, &win, MOVE_UP);
+ break;
+ case XK_l:
+ case XK_Right:
+ tns_move_selection(&tns, &win, MOVE_RIGHT);
+ break;
+ }
}
/* common key mappings */
diff --git a/thumbs.c b/thumbs.c
index f1703e8..c369395 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -115,7 +115,6 @@ void tns_render(tns_t *tns, win_t *win) {
}
tns_highlight(tns, win, -1);
- win_draw(win);
}
void tns_highlight(tns_t *tns, win_t *win, int old) {
@@ -132,4 +131,42 @@ void tns_highlight(tns_t *tns, win_t *win, int old) {
t = &tns->thumbs[tns->sel];
win_draw_rect(win, t->x - 2, t->y - 2, t->w + 4, t->h + 4, True);
}
+
+ win_draw(win);
+}
+
+void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
+ int sel;
+
+ if (!tns || !win)
+ return;
+
+ sel = tns->sel;
+
+ switch (dir) {
+ case MOVE_LEFT:
+ if (sel % tns->cols > 0) {
+ --tns->sel;
+ tns_highlight(tns, win, sel);
+ }
+ break;
+ case MOVE_RIGHT:
+ if (sel % tns->cols < tns->cols - 1 && sel < tns->cnt - 1) {
+ ++tns->sel;
+ tns_highlight(tns, win, sel);
+ }
+ break;
+ case MOVE_UP:
+ if (sel / tns->cols > 0) {
+ tns->sel -= tns->cols;
+ tns_highlight(tns, win, sel);
+ }
+ break;
+ case MOVE_DOWN:
+ if (sel / tns->cols < tns->rows - 1 && sel + tns->cols < tns->cnt) {
+ tns->sel += tns->cols;
+ tns_highlight(tns, win, sel);
+ }
+ break;
+ }
}
diff --git a/thumbs.h b/thumbs.h
index a25a15f..1fd1209 100644
--- a/thumbs.h
+++ b/thumbs.h
@@ -21,6 +21,13 @@
#include "window.h"
+typedef enum movedir_e {
+ MOVE_LEFT = 0,
+ MOVE_RIGHT,
+ MOVE_UP,
+ MOVE_DOWN
+} movedir_t;
+
typedef struct thumb_s {
Pixmap pm;
int x;
@@ -48,4 +55,6 @@ void tns_load(tns_t*, win_t*, const char*);
void tns_render(tns_t*, win_t*);
void tns_highlight(tns_t*, win_t*, int);
+void tns_move_selection(tns_t*, win_t*, movedir_t);
+
#endif /* THUMBS_H */