Krolyxon
Commit f47092c

Branches

Refs →

nsxivf47092c

Complete mouse support

Author
Bert
Date
2011-01-26 18:38 +0100
Parent
0497a7f
Commit
f47092cda2b243519327e4a390f4b87220b4a39a

+101 −31

5 files changed

  1. M README.md +12 −1
  2. M TODO +0 −1
  3. M main.c +56 −27
  4. M sxiv.1 +31 −2
  5. M window.h +2 −0
M README.md View
@@ -41,8 +41,19 @@ Use the following keys to control sxiv:
4141 [/] Go 10 images backward/forward
4242 +,= Zoom in
4343 - Zoom out
44− h,j,k,l Scroll left/down/up/right
44+ h,j,k,l Pan image left/down/up/right
4545 <,> Rotate image (counter-)clockwise by 90 degrees
4646 f Toggle fullscreen mode (requires an EWMH/NetWM compliant
4747 window manager)
4848 a Toggle anti-aliasing
49+
50+Additionally, sxiv can be controlled via the following mouse commands:
51+
52+ Button1 Go to the next image
53+ Button3 Go to the previous image
54+ ScrollUp Pan image up
55+ ScrollDown Pan image down
56+ Shift+ScrollUp Pan image left
57+ Shift+ScrollDown Pan image right
58+ Ctrl+ScrollUp Zoom in
59+ Ctrl+ScrollDown Zoom out
M TODO View
@@ -1,3 +1,2 @@
1−- mouse scrolling and zooming
21 - add some useful command line options
32 - view all images in directories (recursive mode)
M main.c View
@@ -30,14 +30,14 @@
3030 #include "window.h"
3131
3232 void on_keypress(XEvent*);
33−void on_configurenotify(XEvent*);
3433 void on_buttonpress(XEvent*);
34+void on_configurenotify(XEvent*);
3535
3636 void update_title();
3737
3838 static void (*handler[LASTEvent])(XEvent*) = {
39− [ButtonPress] = on_buttonpress,
4039 [KeyPress] = on_keypress,
40+ [ButtonPress] = on_buttonpress,
4141 [ConfigureNotify] = on_configurenotify
4242 };
4343
@@ -128,31 +128,6 @@ void cleanup() {
128128 }
129129 }
130130
131−void on_buttonpress(XEvent *ev) {
132− int changed;
133− XButtonEvent *buttonevent;
134−
135− changed = 0;
136− buttonevent = &ev->xbutton;
137−
138− switch (buttonevent->button) {
139− case Button4:
140− changed = img_zoom_in(&img);
141− break;
142− case Button5:
143− changed = img_zoom_out(&img);
144− break;
145− default:
146− return;
147− }
148−
149− if (changed) {
150− img_render(&img, &win);
151− update_title();
152− timeout = 0;
153− }
154−}
155−
156131 void on_keypress(XEvent *ev) {
157132 char key;
158133 KeySym keysym;
@@ -272,6 +247,60 @@ void on_keypress(XEvent *ev) {
272247 }
273248 }
274249
250+void on_buttonpress(XEvent *ev) {
251+ int changed;
252+ unsigned int mask;
253+
254+ if (!ev)
255+ return;
256+
257+ mask = CLEANMASK(ev->xbutton.state);
258+ changed = 0;
259+
260+ switch (ev->xbutton.button) {
261+ case Button1:
262+ if (fileidx + 1 < filecnt) {
263+ img_load(&img, filenames[++fileidx]);
264+ changed = 1;
265+ }
266+ break;
267+ case Button3:
268+ if (fileidx > 0) {
269+ img_load(&img, filenames[--fileidx]);
270+ changed = 1;
271+ }
272+ break;
273+ case Button4:
274+ if (mask == ControlMask)
275+ changed = img_zoom_in(&img);
276+ else if (mask == ShiftMask)
277+ changed = img_pan(&img, &win, PAN_LEFT);
278+ else
279+ changed = img_pan(&img, &win, PAN_UP);
280+ break;
281+ case Button5:
282+ if (mask == ControlMask)
283+ changed = img_zoom_out(&img);
284+ else if (mask == ShiftMask)
285+ changed = img_pan(&img, &win, PAN_RIGHT);
286+ else
287+ changed = img_pan(&img, &win, PAN_DOWN);
288+ break;
289+ case 6:
290+ changed = img_pan(&img, &win, PAN_LEFT);
291+ break;
292+ case 7:
293+ changed = img_pan(&img, &win, PAN_RIGHT);
294+ break;
295+ }
296+
297+ if (changed) {
298+ img_render(&img, &win);
299+ update_title();
300+ timeout = 0;
301+ }
302+}
303+
275304 void on_configurenotify(XEvent *ev) {
276305 if (!ev)
277306 return;
M sxiv.1 View
@@ -26,7 +26,7 @@ Quit sxiv.
2626 .TP
2727 .B Escape
2828 Quit sxiv and return an exit value of 2.
29−.SS Navigate image list
29+.SS Navigate image list
3030 .TP
3131 .BR Space ", " n
3232 Go to the next image.
@@ -80,6 +80,34 @@ Toggle fullscreen mode.
8080 .TP
8181 .B a
8282 Toggle anti-aliasing.
83+.SH MOUSE COMMANDS
84+.SS Navigate image list
85+.TP
86+.B Button1
87+Go to the next image.
88+.TP
89+.B Button3
90+Go to the previous image.
91+.SS Zooming
92+.TP
93+.B Ctrl+ScrollUp
94+Zoom in.
95+.TP
96+.B Ctrl+ScrollDown
97+Zoom out.
98+.SS Panning
99+.TP
100+.B ScrollUp
101+Pan up.
102+.TP
103+.B ScrollDown
104+Pan down.
105+.TP
106+.B Shift+ScrollUp
107+Pan left.
108+.TP
109+.B Shift+ScrollDown
110+Pan right.
83111 .SH AUTHORS
84112 .TP
85113 Bert Muennich <ber.t at gmx.com>
@@ -87,4 +115,5 @@ Bert Muennich <ber.t at gmx.com>
87115 .TP
88116 http://github.com/muennich/sxiv
89117 .SH SEE ALSO
90−.BR feh (1), qiv (1)
118+.BR feh (1),
119+.BR qiv (1)
M window.h View
@@ -21,6 +21,8 @@
2121
2222 #include <X11/Xlib.h>
2323
24+#define CLEANMASK(mask) ((mask) & ~LockMask)
25+
2426 typedef struct win_env_s {
2527 Display *dpy;
2628 int scr;