From 64a5366508142ad938e4a6f9f8bdb5f375b1336c Mon Sep 17 00:00:00 2001 From: Bert Date: Wed, 26 Jan 2011 14:42:10 +0100 Subject: Added <,> mappings to rotate image --- Makefile | 2 +- README.md | 1 + image.c | 33 ++++++++++++++++++++++++++++++++- image.h | 3 +++ main.c | 8 ++++++++ sxiv.1 | 7 +++++++ 6 files changed, 52 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6428781..d144865 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: sxiv -VERSION=0.2 +VERSION=git-20110126 CC?=gcc PREFIX?=/usr/local diff --git a/README.md b/README.md index ed71eca..4e66437 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/image.c b/image.c index 5187d51..beff925 100644 --- a/image.c +++ b/image.c @@ -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); +} diff --git a/image.h b/image.h index 4e4d816..55b825c 100644 --- a/image.h +++ b/image.h @@ -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 */ diff --git a/main.c b/main.c index 9b7ed6b..039394c 100644 --- a/main.c +++ b/main.c @@ -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); diff --git a/sxiv.1 b/sxiv.1 index d567680..b9a3b95 100644 --- a/sxiv.1 +++ b/sxiv.1 @@ -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 -- cgit v1.2.3-54-g00ecf