Krolyxon
Commit 64a5366

Branches

Refs →

nsxiv64a5366

Added <,> mappings to rotate image

Author
Bert
Date
2011-01-26 14:42 +0100
Parent
d2f9fb8
Commit
64a5366508142ad938e4a6f9f8bdb5f375b1336c

+52 −2

6 files changed

  1. M Makefile +1 −1
  2. M README.md +1 −0
  3. M image.c +32 −1
  4. M image.h +3 −0
  5. M main.c +8 −0
  6. M sxiv.1 +7 −0
M Makefile View
@@ -1,6 +1,6 @@
11 all: sxiv
22
3−VERSION=0.2
3+VERSION=git-20110126
44
55 CC?=gcc
66 PREFIX?=/usr/local
M README.md View
@@ -42,5 +42,6 @@ Use the following keys to control sxiv:
4242 +,= Zoom in
4343 - Zoom out
4444 h,j,k,l Scroll left/down/up/right
45+ <,> Rotate image (counter-)clockwise by 90 degrees
4546 f Toggle fullscreen mode (requires an EWMH/NetWM compliant
4647 window manager)
M image.c View
@@ -104,7 +104,7 @@ void img_render(img_t *img, win_t *win) {
104104 if (!img || !win || !imlib_context_get_image())
105105 return;
106106
107− if ((!img->re || !img->zoomed) && SCALE_MODE != SCALE_ZOOM) {
107+ if (!img->zoomed && SCALE_MODE != SCALE_ZOOM) {
108108 /* set zoom level to fit image into window */
109109 zw = (float) win->w / (float) img->w;
110110 zh = (float) win->h / (float) img->h;
@@ -241,3 +241,34 @@ int img_pan(img_t *img, win_t *win, pandir_t dir) {
241241
242242 return ox != img->x || oy != img->y;
243243 }
244+
245+int img_rotate(img_t *img, win_t *win, int d) {
246+ int ox, oy, tmp;
247+
248+ if (!img || !win)
249+ return 0;
250+
251+ ox = d == 1 ? img->x : win->w - img->x - img->w * img->zoom;
252+ oy = d == 3 ? img->y : win->h - img->y - img->h * img->zoom;
253+
254+ imlib_image_orientate(d);
255+
256+ img->x = oy + (win->w - win->h) / 2;
257+ img->y = ox + (win->h - win->w) / 2;
258+
259+ tmp = img->w;
260+ img->w = img->h;
261+ img->h = tmp;
262+
263+ img->checkpan = 1;
264+
265+ return 1;
266+}
267+
268+int img_rotate_left(img_t *img, win_t *win) {
269+ return img_rotate(img, win, 3);
270+}
271+
272+int img_rotate_right(img_t *img, win_t *win) {
273+ return img_rotate(img, win, 1);
274+}
M image.h View
@@ -56,4 +56,7 @@ int img_zoom_out(img_t*);
5656
5757 int img_pan(img_t*, win_t*, pandir_t);
5858
59+int img_rotate_left(img_t*, win_t*);
60+int img_rotate_right(img_t*, win_t*);
61+
5962 #endif /* IMAGE_H */
M main.c View
@@ -219,6 +219,14 @@ void on_keypress(XEvent *ev) {
219219 changed = img_pan(&img, &win, PAN_RIGHT);
220220 break;
221221
222+ /* rotation */
223+ case '<':
224+ changed = img_rotate_left(&img, &win);
225+ break;
226+ case '>':
227+ changed = img_rotate_right(&img, &win);
228+ break;
229+
222230 /* Control window */
223231 case 'f':
224232 win_toggle_fullscreen(&win);
M sxiv.1 View
@@ -65,6 +65,13 @@ Pan up.
6565 .TP
6666 .B l
6767 Pan right.
68+.SS Rotation
69+.TP
70+.B <
71+Rotate image counter-clockwise by 90 degrees.
72+.TP
73+.B >
74+Rotate image clockwise by 90 degrees.
6875 .SS Control window
6976 .TP
7077 .B f