Nicer key handling, does not fix problems

This commit is contained in:
Bert 2011-01-30 20:46:48 +01:00
parent 03bfe1015e
commit f7a66469e6
1 changed files with 27 additions and 42 deletions

69
main.c
View File

@ -136,79 +136,60 @@ void cleanup() {
void on_keypress(XEvent *ev) { void on_keypress(XEvent *ev) {
char key; char key;
KeySym keysym; KeySym ksym;
int changed; int changed;
if (!ev) if (!ev)
return; return;
XLookupString(&ev->xkey, &key, 1, &keysym, NULL); XLookupString(&ev->xkey, &key, 1, &ksym, NULL);
changed = 0; changed = 0;
switch (keysym) { switch (ksym) {
case XK_Escape: case XK_Escape:
cleanup(); cleanup();
exit(2); exit(2);
case XK_space: case XK_q:
key = 'n';
break;
case XK_BackSpace:
key = 'p';
break;
case XK_Left:
key = 'h';
break;
case XK_Down:
key = 'j';
break;
case XK_Up:
key = 'k';
break;
case XK_Right:
key = 'l';
break;
}
switch (key) {
case 'q':
cleanup(); cleanup();
exit(0); exit(0);
/* navigate image list */ /* navigate image list */
case 'n': case XK_n:
case XK_space:
if (fileidx + 1 < filecnt) { if (fileidx + 1 < filecnt) {
img_load(&img, filenames[++fileidx]); img_load(&img, filenames[++fileidx]);
changed = 1; changed = 1;
} }
break; break;
case 'p': case XK_p:
case XK_BackSpace:
if (fileidx > 0) { if (fileidx > 0) {
img_load(&img, filenames[--fileidx]); img_load(&img, filenames[--fileidx]);
changed = 1; changed = 1;
} }
break; break;
case '[': case XK_bracketleft:
if (fileidx != 0) { if (fileidx != 0) {
fileidx = MAX(0, fileidx - 10); fileidx = MAX(0, fileidx - 10);
img_load(&img, filenames[fileidx]); img_load(&img, filenames[fileidx]);
changed = 1; changed = 1;
} }
break; break;
case ']': case XK_bracketright:
if (fileidx != filecnt - 1) { if (fileidx != filecnt - 1) {
fileidx = MIN(fileidx + 10, filecnt - 1); fileidx = MIN(fileidx + 10, filecnt - 1);
img_load(&img, filenames[fileidx]); img_load(&img, filenames[fileidx]);
changed = 1; changed = 1;
} }
break; break;
case 'g': case XK_g:
if (fileidx != 0) { if (fileidx != 0) {
fileidx = 0; fileidx = 0;
img_load(&img, filenames[fileidx]); img_load(&img, filenames[fileidx]);
changed = 1; changed = 1;
} }
break; break;
case 'G': case XK_G:
if (fileidx != filecnt - 1) { if (fileidx != filecnt - 1) {
fileidx = filecnt - 1; fileidx = filecnt - 1;
img_load(&img, filenames[fileidx]); img_load(&img, filenames[fileidx]);
@ -217,43 +198,47 @@ void on_keypress(XEvent *ev) {
break; break;
/* zooming */ /* zooming */
case '+': case XK_plus:
case '=': case XK_equal:
changed = img_zoom_in(&img); changed = img_zoom_in(&img);
break; break;
case '-': case XK_minus:
changed = img_zoom_out(&img); changed = img_zoom_out(&img);
break; break;
/* panning */ /* panning */
case 'h': case XK_h:
case XK_Left:
changed = img_pan(&img, &win, PAN_LEFT); changed = img_pan(&img, &win, PAN_LEFT);
break; break;
case 'j': case XK_j:
case XK_Down:
changed = img_pan(&img, &win, PAN_DOWN); changed = img_pan(&img, &win, PAN_DOWN);
break; break;
case 'k': case XK_k:
case XK_Up:
changed = img_pan(&img, &win, PAN_UP); changed = img_pan(&img, &win, PAN_UP);
break; break;
case 'l': case XK_l:
case XK_Right:
changed = img_pan(&img, &win, PAN_RIGHT); changed = img_pan(&img, &win, PAN_RIGHT);
break; break;
/* rotation */ /* rotation */
case '<': case XK_less:
changed = img_rotate_left(&img, &win); changed = img_rotate_left(&img, &win);
break; break;
case '>': case XK_greater:
changed = img_rotate_right(&img, &win); changed = img_rotate_right(&img, &win);
break; break;
/* control window */ /* control window */
case 'f': case XK_f:
win_toggle_fullscreen(&win); win_toggle_fullscreen(&win);
break; break;
/* miscellaneous */ /* miscellaneous */
case 'a': case XK_a:
changed = img_toggle_antialias(&img); changed = img_toggle_antialias(&img);
break; break;
} }