From a6100373c1be2796966fa7e15d7b41f2f8a112f7 Mon Sep 17 00:00:00 2001 From: Bert Date: Fri, 3 Jun 2011 23:39:22 +0200 Subject: [PATCH] New mappings: ctrl-[hjkl], pan image one window width/height --- Makefile | 2 +- README.md | 2 ++ image.c | 10 +++++----- image.h | 2 +- main.c | 31 +++++++++++++++++++------------ sxiv.1 | 20 ++++++++++++++++---- 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index edbb949..6a4b9fc 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: sxiv -VERSION=git-20110529 +VERSION=git-20110603 CC?=gcc DESTDIR?= diff --git a/README.md b/README.md index 3dabbd6..ebe570f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/image.c b/image.c index 25e85b3..8233df5 100644 --- a/image.c +++ b/image.c @@ -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; diff --git a/image.h b/image.h index 2f9ffce..711f15c 100644 --- a/image.h +++ b/image.h @@ -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*); diff --git a/main.c b/main.c index 9a43fe7..d030226 100644 --- a/main.c +++ b/main.c @@ -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 { diff --git a/sxiv.1 b/sxiv.1 index c5dce3b..b3e763c 100644 --- a/sxiv.1 +++ b/sxiv.1 @@ -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 <