Krolyxon
Commit 9a35f40

Branches

Refs →

nsxiv9a35f40

main.c: add zooming on mousewheel events

Author
Dave Reisner
Date
2011-01-22 22:04 -0500
Committer
Dave Reisner · 2011-01-23 09:46 -0500
Parent
13eb5ac
Commit
9a35f40224a08bfcc27b4ba79301e22a58cf4495

+27 −0

1 file changed

  1. M main.c +27 −0
M main.c View
@@ -31,10 +31,12 @@
3131
3232 void on_keypress(XEvent*);
3333 void on_configurenotify(XEvent*);
34+void on_buttonpress(XEvent*);
3435
3536 void update_title();
3637
3738 static void (*handler[LASTEvent])(XEvent*) = {
39+ [ButtonPress] = on_buttonpress,
3840 [KeyPress] = on_keypress,
3941 [ConfigureNotify] = on_configurenotify
4042 };
@@ -126,6 +128,31 @@ void cleanup() {
126128 }
127129 }
128130
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+
129156 void on_keypress(XEvent *ev) {
130157 char key;
131158 KeySym keysym;