Added <,> mappings to rotate image

This commit is contained in:
Bert 2011-01-26 14:42:10 +01:00
parent d2f9fb89e5
commit 64a5366508
6 changed files with 52 additions and 2 deletions

View File

@ -1,6 +1,6 @@
all: sxiv
VERSION=0.2
VERSION=git-20110126
CC?=gcc
PREFIX?=/usr/local

View File

@ -42,5 +42,6 @@ Use the following keys to control sxiv:
+,= Zoom in
- Zoom out
h,j,k,l Scroll left/down/up/right
<,> Rotate image (counter-)clockwise by 90 degrees
f Toggle fullscreen mode (requires an EWMH/NetWM compliant
window manager)

33
image.c
View File

@ -104,7 +104,7 @@ void img_render(img_t *img, win_t *win) {
if (!img || !win || !imlib_context_get_image())
return;
if ((!img->re || !img->zoomed) && SCALE_MODE != SCALE_ZOOM) {
if (!img->zoomed && SCALE_MODE != SCALE_ZOOM) {
/* set zoom level to fit image into window */
zw = (float) win->w / (float) img->w;
zh = (float) win->h / (float) img->h;
@ -241,3 +241,34 @@ int img_pan(img_t *img, win_t *win, pandir_t dir) {
return ox != img->x || oy != img->y;
}
int img_rotate(img_t *img, win_t *win, int d) {
int ox, oy, tmp;
if (!img || !win)
return 0;
ox = d == 1 ? img->x : win->w - img->x - img->w * img->zoom;
oy = d == 3 ? img->y : win->h - img->y - img->h * img->zoom;
imlib_image_orientate(d);
img->x = oy + (win->w - win->h) / 2;
img->y = ox + (win->h - win->w) / 2;
tmp = img->w;
img->w = img->h;
img->h = tmp;
img->checkpan = 1;
return 1;
}
int img_rotate_left(img_t *img, win_t *win) {
return img_rotate(img, win, 3);
}
int img_rotate_right(img_t *img, win_t *win) {
return img_rotate(img, win, 1);
}

View File

@ -56,4 +56,7 @@ int img_zoom_out(img_t*);
int img_pan(img_t*, win_t*, pandir_t);
int img_rotate_left(img_t*, win_t*);
int img_rotate_right(img_t*, win_t*);
#endif /* IMAGE_H */

8
main.c
View File

@ -219,6 +219,14 @@ void on_keypress(XEvent *ev) {
changed = img_pan(&img, &win, PAN_RIGHT);
break;
/* rotation */
case '<':
changed = img_rotate_left(&img, &win);
break;
case '>':
changed = img_rotate_right(&img, &win);
break;
/* Control window */
case 'f':
win_toggle_fullscreen(&win);

7
sxiv.1
View File

@ -65,6 +65,13 @@ Pan up.
.TP
.B l
Pan right.
.SS Rotation
.TP
.B <
Rotate image counter-clockwise by 90 degrees.
.TP
.B >
Rotate image clockwise by 90 degrees.
.SS Control window
.TP
.B f