Use Button1 to open thumbnail

This commit is contained in:
Bert 2011-02-17 17:28:13 +01:00
parent f08c24bbb3
commit 6adbb3831d
3 changed files with 74 additions and 41 deletions

21
main.c
View File

@ -268,11 +268,11 @@ void redraw() {
}
void on_keypress(XKeyEvent *kev) {
int sel, x, y;
int x, y;
unsigned int w, h;
char key;
KeySym ksym;
int changed;
int changed, sel;
if (!kev)
return;
@ -439,7 +439,7 @@ void on_keypress(XKeyEvent *kev) {
}
void on_buttonpress(XButtonEvent *bev) {
int changed;
int changed, sel;
unsigned int mask;
if (!bev)
@ -448,6 +448,7 @@ void on_buttonpress(XButtonEvent *bev) {
mask = CLEANMASK(bev->state);
changed = 0;
if (mode == MODE_NORMAL) {
switch (bev->button) {
case Button1:
if (fileidx + 1 < filecnt) {
@ -489,6 +490,20 @@ void on_buttonpress(XButtonEvent *bev) {
changed = img_pan(&img, &win, PAN_RIGHT);
break;
}
} else {
/* thumbnail mode */
switch (bev->button) {
case Button1:
if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) {
fileidx = sel;
load_image();
mode = MODE_NORMAL;
changed = 1;
break;
}
break;
}
}
if (changed)
redraw();

View File

@ -170,3 +170,19 @@ void tns_move_selection(tns_t *tns, win_t *win, movedir_t dir) {
break;
}
}
int tns_translate(tns_t *tns, int x, int y) {
int n;
thumb_t *t;
if (!tns || x < 5 || y < 5)
return -1;
if ((n = y / thumb_dim * tns-> cols + x / thumb_dim) < tns->cnt) {
t = &tns->thumbs[n];
if (x > t->x && x < t->x + t->w && y > t->y && y < t->y + t->h)
return n;
}
return -1;
}

View File

@ -57,4 +57,6 @@ void tns_highlight(tns_t*, win_t*, int);
void tns_move_selection(tns_t*, win_t*, movedir_t);
int tns_translate(tns_t*, int, int);
#endif /* THUMBS_H */