aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-01-26 18:38:54 +0100
committerBert <ber.t@gmx.com>2011-01-26 18:38:54 +0100
commitf47092cda2b243519327e4a390f4b87220b4a39a (patch)
tree24295e155b42b06531cbbf9621abc938a2653ab6 /main.c
parent0497a7f69d356f9008e0c89f390e6c72a9dbfbcc (diff)
Complete mouse support
Diffstat (limited to 'main.c')
-rw-r--r--main.c83
1 files changed, 56 insertions, 27 deletions
diff --git a/main.c b/main.c
index ad2d4a4..7d1e682 100644
--- a/main.c
+++ b/main.c
@@ -30,14 +30,14 @@
#include "window.h"
void on_keypress(XEvent*);
-void on_configurenotify(XEvent*);
void on_buttonpress(XEvent*);
+void on_configurenotify(XEvent*);
void update_title();
static void (*handler[LASTEvent])(XEvent*) = {
- [ButtonPress] = on_buttonpress,
[KeyPress] = on_keypress,
+ [ButtonPress] = on_buttonpress,
[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) {
char key;
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) {
if (!ev)
return;