New mappings: ctrl-[hjkl], pan image one window width/height

This commit is contained in:
Bert 2011-06-03 23:39:22 +02:00
parent ea23115af4
commit a6100373c1
6 changed files with 44 additions and 23 deletions

View File

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

View File

@ -69,6 +69,8 @@ thumbnail mode are denoted via brackets:
h,j,k,l Pan image [move selection] left/down/up/right
(also with arrow keys)
H,J,K,L Pan to left/bottom/top/right image edge
Ctrl-h,j,k,l Pan image one window width/height left/down/up/right
(also with Ctrl-arrow keys)
<,> Rotate image (counter-)clockwise by 90 degrees

10
image.c
View File

@ -275,19 +275,19 @@ int img_move(img_t *img, win_t *win, int dx, int dy) {
return ox != img->x || oy != img->y;
}
int img_pan(img_t *img, win_t *win, pandir_t dir) {
int img_pan(img_t *img, win_t *win, pandir_t dir, int page) {
if (!img || !img->im || !win)
return 0;
switch (dir) {
case PAN_LEFT:
return img_move(img, win, win->w / 5, 0);
return img_move(img, win, win->w / (page ? 1 : 5), 0);
case PAN_RIGHT:
return img_move(img, win, win->w / 5 * -1, 0);
return img_move(img, win, win->w / (page ? 1 : 5) * -1, 0);
case PAN_UP:
return img_move(img, win, 0, win->h / 5);
return img_move(img, win, 0, win->h / (page ? 1 : 5));
case PAN_DOWN:
return img_move(img, win, 0, win->h / 5 * -1);
return img_move(img, win, 0, win->h / (page ? 1 : 5) * -1);
}
return 0;

View File

@ -68,7 +68,7 @@ int img_zoom_in(img_t*, win_t*);
int img_zoom_out(img_t*, win_t*);
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);
int img_pan_edge(img_t*, win_t*, pandir_t);
void img_rotate_left(img_t*, win_t*);

31
main.c
View File

@ -357,17 +357,18 @@ void on_keypress(XKeyEvent *kev) {
unsigned int w, h;
char key;
KeySym ksym;
int changed;
int changed, ctrl;
if (!kev)
return;
XLookupString(kev, &key, 1, &ksym, NULL);
changed = 0;
ctrl = CLEANMASK(kev->state) & ControlMask;
#if EXT_COMMANDS
/* external commands from commands.h */
if (CLEANMASK(kev->state) & ControlMask) {
if (ctrl) {
for (x = 0; x < LEN(commands); ++x) {
if (commands[x].ksym == ksym) {
win_set_cursor(&win, CURSOR_WATCH);
@ -446,19 +447,25 @@ void on_keypress(XKeyEvent *kev) {
/* panning */
case XK_h:
case XK_Left:
changed = img_pan(&img, &win, PAN_LEFT);
changed = img_pan(&img, &win, PAN_LEFT, ctrl);
break;
case XK_j:
case XK_Down:
changed = img_pan(&img, &win, PAN_DOWN);
changed = img_pan(&img, &win, PAN_DOWN, ctrl);
break;
case XK_k:
case XK_Up:
changed = img_pan(&img, &win, PAN_UP);
changed = img_pan(&img, &win, PAN_UP, ctrl);
break;
case XK_l:
case XK_Right:
changed = img_pan(&img, &win, PAN_RIGHT);
changed = img_pan(&img, &win, PAN_RIGHT, ctrl);
break;
case XK_Prior:
changed = img_pan(&img, &win, PAN_UP, 1);
break;
case XK_Next:
changed = img_pan(&img, &win, PAN_DOWN, 1);
break;
case XK_H:
@ -632,23 +639,23 @@ void on_buttonpress(XButtonEvent *bev) {
if (mask == ControlMask)
changed = img_zoom_in(&img, &win);
else if (mask == ShiftMask)
changed = img_pan(&img, &win, PAN_LEFT);
changed = img_pan(&img, &win, PAN_LEFT, 0);
else
changed = img_pan(&img, &win, PAN_UP);
changed = img_pan(&img, &win, PAN_UP, 0);
break;
case Button5:
if (mask == ControlMask)
changed = img_zoom_out(&img, &win);
else if (mask == ShiftMask)
changed = img_pan(&img, &win, PAN_RIGHT);
changed = img_pan(&img, &win, PAN_RIGHT, 0);
else
changed = img_pan(&img, &win, PAN_DOWN);
changed = img_pan(&img, &win, PAN_DOWN, 0);
break;
case 6:
changed = img_pan(&img, &win, PAN_LEFT);
changed = img_pan(&img, &win, PAN_LEFT, 0);
break;
case 7:
changed = img_pan(&img, &win, PAN_RIGHT);
changed = img_pan(&img, &win, PAN_RIGHT, 0);
break;
}
} else {

20
sxiv.1
View File

@ -138,17 +138,29 @@ Pan image [move selection] up.
.BR l ", " Right
Pan image [move selection] right.
.TP
.BR H
.B H
Pan to left image edge.
.TP
.BR J
.B J
Pan to bottom image edge.
.TP
.BR K
.B K
Pan to top image edge.
.TP
.BR L
.B L
Pan to right image edge.
.TP
.BR Ctrl-h ", " Ctrl-Left
Pan image one window width left.
.TP
.BR Ctrl-j ", " Ctrl-Down ", " PageDn
Pan image one window height down.
.TP
.BR Ctrl-k ", " Ctrl-Up ", " PageUp
Pan image one window height up.
.TP
.BR Ctrl-l ", " Ctrl-Right
Pan image one window width right.
.SS Rotation
.TP
.B <