| @@ -30,14 +30,14 @@ |
| 30 | 30 | | #include "window.h" |
| 31 | 31 | | |
| 32 | 32 | | void on_keypress(XEvent*); |
| 33 | | − | void on_configurenotify(XEvent*); |
| 34 | 33 | | void on_buttonpress(XEvent*); |
| 34 | + | void on_configurenotify(XEvent*); |
| 35 | 35 | | |
| 36 | 36 | | void update_title(); |
| 37 | 37 | | |
| 38 | 38 | | static void (*handler[LASTEvent])(XEvent*) = { |
| 39 | | − | [ButtonPress] = on_buttonpress, |
| 40 | 39 | | [KeyPress] = on_keypress, |
| 40 | + | [ButtonPress] = on_buttonpress, |
| 41 | 41 | | [ConfigureNotify] = on_configurenotify |
| 42 | 42 | | }; |
| 43 | 43 | | |
| @@ -128,31 +128,6 @@ void cleanup() { |
| 128 | 128 | | } |
| 129 | 129 | | } |
| 130 | 130 | | |
| 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 | | − | |
| 156 | 131 | | void on_keypress(XEvent *ev) { |
| 157 | 132 | | char key; |
| 158 | 133 | | KeySym keysym; |
| @@ -272,6 +247,60 @@ void on_keypress(XEvent *ev) { |
| 272 | 247 | | } |
| 273 | 248 | | } |
| 274 | 249 | | |
| 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 | + | |
| 275 | 304 | | void on_configurenotify(XEvent *ev) { |
| 276 | 305 | | if (!ev) |
| 277 | 306 | | return; |