Complete mouse support

This commit is contained in:
Bert 2011-01-26 18:38:54 +01:00
parent 0497a7f69d
commit f47092cda2
5 changed files with 101 additions and 31 deletions

View file

@ -41,8 +41,19 @@ Use the following keys to control sxiv:
[/] Go 10 images backward/forward [/] Go 10 images backward/forward
+,= Zoom in +,= Zoom in
- Zoom out - Zoom out
h,j,k,l Scroll left/down/up/right h,j,k,l Pan image left/down/up/right
<,> Rotate image (counter-)clockwise by 90 degrees <,> Rotate image (counter-)clockwise by 90 degrees
f Toggle fullscreen mode (requires an EWMH/NetWM compliant f Toggle fullscreen mode (requires an EWMH/NetWM compliant
window manager) window manager)
a Toggle anti-aliasing a Toggle anti-aliasing
Additionally, sxiv can be controlled via the following mouse commands:
Button1 Go to the next image
Button3 Go to the previous image
ScrollUp Pan image up
ScrollDown Pan image down
Shift+ScrollUp Pan image left
Shift+ScrollDown Pan image right
Ctrl+ScrollUp Zoom in
Ctrl+ScrollDown Zoom out

1
TODO
View file

@ -1,3 +1,2 @@
- mouse scrolling and zooming
- add some useful command line options - add some useful command line options
- view all images in directories (recursive mode) - view all images in directories (recursive mode)

83
main.c
View file

@ -30,14 +30,14 @@
#include "window.h" #include "window.h"
void on_keypress(XEvent*); void on_keypress(XEvent*);
void on_configurenotify(XEvent*);
void on_buttonpress(XEvent*); void on_buttonpress(XEvent*);
void on_configurenotify(XEvent*);
void update_title(); void update_title();
static void (*handler[LASTEvent])(XEvent*) = { static void (*handler[LASTEvent])(XEvent*) = {
[ButtonPress] = on_buttonpress,
[KeyPress] = on_keypress, [KeyPress] = on_keypress,
[ButtonPress] = on_buttonpress,
[ConfigureNotify] = on_configurenotify [ConfigureNotify] = on_configurenotify
}; };
@ -128,31 +128,6 @@ void cleanup() {
} }
} }
void on_buttonpress(XEvent *ev) {
int changed;
XButtonEvent *buttonevent;
changed = 0;
buttonevent = &ev->xbutton;
switch (buttonevent->button) {
case Button4:
changed = img_zoom_in(&img);
break;
case Button5:
changed = img_zoom_out(&img);
break;
default:
return;
}
if (changed) {
img_render(&img, &win);
update_title();
timeout = 0;
}
}
void on_keypress(XEvent *ev) { void on_keypress(XEvent *ev) {
char key; char key;
KeySym keysym; KeySym keysym;
@ -272,6 +247,60 @@ void on_keypress(XEvent *ev) {
} }
} }
void on_buttonpress(XEvent *ev) {
int changed;
unsigned int mask;
if (!ev)
return;
mask = CLEANMASK(ev->xbutton.state);
changed = 0;
switch (ev->xbutton.button) {
case Button1:
if (fileidx + 1 < filecnt) {
img_load(&img, filenames[++fileidx]);
changed = 1;
}
break;
case Button3:
if (fileidx > 0) {
img_load(&img, filenames[--fileidx]);
changed = 1;
}
break;
case Button4:
if (mask == ControlMask)
changed = img_zoom_in(&img);
else if (mask == ShiftMask)
changed = img_pan(&img, &win, PAN_LEFT);
else
changed = img_pan(&img, &win, PAN_UP);
break;
case Button5:
if (mask == ControlMask)
changed = img_zoom_out(&img);
else if (mask == ShiftMask)
changed = img_pan(&img, &win, PAN_RIGHT);
else
changed = img_pan(&img, &win, PAN_DOWN);
break;
case 6:
changed = img_pan(&img, &win, PAN_LEFT);
break;
case 7:
changed = img_pan(&img, &win, PAN_RIGHT);
break;
}
if (changed) {
img_render(&img, &win);
update_title();
timeout = 0;
}
}
void on_configurenotify(XEvent *ev) { void on_configurenotify(XEvent *ev) {
if (!ev) if (!ev)
return; return;

31
sxiv.1
View file

@ -80,6 +80,34 @@ Toggle fullscreen mode.
.TP .TP
.B a .B a
Toggle anti-aliasing. Toggle anti-aliasing.
.SH MOUSE COMMANDS
.SS Navigate image list
.TP
.B Button1
Go to the next image.
.TP
.B Button3
Go to the previous image.
.SS Zooming
.TP
.B Ctrl+ScrollUp
Zoom in.
.TP
.B Ctrl+ScrollDown
Zoom out.
.SS Panning
.TP
.B ScrollUp
Pan up.
.TP
.B ScrollDown
Pan down.
.TP
.B Shift+ScrollUp
Pan left.
.TP
.B Shift+ScrollDown
Pan right.
.SH AUTHORS .SH AUTHORS
.TP .TP
Bert Muennich <ber.t at gmx.com> Bert Muennich <ber.t at gmx.com>
@ -87,4 +115,5 @@ Bert Muennich <ber.t at gmx.com>
.TP .TP
http://github.com/muennich/sxiv http://github.com/muennich/sxiv
.SH SEE ALSO .SH SEE ALSO
.BR feh (1), qiv (1) .BR feh (1),
.BR qiv (1)

View file

@ -21,6 +21,8 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#define CLEANMASK(mask) ((mask) & ~LockMask)
typedef struct win_env_s { typedef struct win_env_s {
Display *dpy; Display *dpy;
int scr; int scr;