H/J/K/L mappings to pan to edges

This commit is contained in:
Bert 2011-05-16 15:54:09 +02:00
parent 1763e9f253
commit 485e6c863a
4 changed files with 44 additions and 1 deletions

View file

@ -1,6 +1,6 @@
all: sxiv all: sxiv
VERSION=git-20110510 VERSION=git-20110516
CC?=gcc CC?=gcc
DESTDIR?= DESTDIR?=

29
image.c
View file

@ -293,6 +293,35 @@ int img_pan(img_t *img, win_t *win, pandir_t dir) {
return 0; return 0;
} }
int img_pan_edge(img_t *img, win_t *win, pandir_t dir) {
int ox, oy;
if (!img || !img->im || !win)
return 0;
ox = img->x;
oy = img->y;
switch (dir) {
case PAN_LEFT:
img->x = 0;
break;
case PAN_RIGHT:
img->x = win->w - img->w * img->zoom;
break;
case PAN_UP:
img->y = 0;
break;
case PAN_DOWN:
img->y = win->h - img->h * img->zoom;
break;
}
img_check_pan(img, win);
return ox != img->x || oy != img->y;
}
void img_rotate(img_t *img, win_t *win, int d) { void img_rotate(img_t *img, win_t *win, int d) {
int ox, oy, tmp; int ox, oy, tmp;

View file

@ -69,6 +69,7 @@ int img_zoom_out(img_t*, win_t*);
int img_move(img_t*, win_t*, int, int); int img_move(img_t*, win_t*, int, int);
int img_pan(img_t*, win_t*, pandir_t); int img_pan(img_t*, win_t*, pandir_t);
int img_pan_edge(img_t*, win_t*, pandir_t);
void img_rotate_left(img_t*, win_t*); void img_rotate_left(img_t*, win_t*);
void img_rotate_right(img_t*, win_t*); void img_rotate_right(img_t*, win_t*);

13
main.c
View file

@ -455,6 +455,19 @@ void on_keypress(XKeyEvent *kev) {
changed = img_pan(&img, &win, PAN_RIGHT); changed = img_pan(&img, &win, PAN_RIGHT);
break; break;
case XK_H:
changed = img_pan_edge(&img, &win, PAN_LEFT);
break;
case XK_J:
changed = img_pan_edge(&img, &win, PAN_DOWN);
break;
case XK_K:
changed = img_pan_edge(&img, &win, PAN_UP);
break;
case XK_L:
changed = img_pan_edge(&img, &win, PAN_RIGHT);
break;
/* rotation */ /* rotation */
case XK_less: case XK_less:
img_rotate_left(&img, &win); img_rotate_left(&img, &win);