diff options
author | Bert <ber.t@gmx.com> | 2011-01-29 22:37:40 +0100 |
---|---|---|
committer | Bert <ber.t@gmx.com> | 2011-01-29 22:37:40 +0100 |
commit | c52c4fa69e2a6a58813fe35a5c4a1fe23661db03 (patch) | |
tree | 6ddefe9122c481495caceec023a79786e5412b84 /main.c | |
parent | 4ab4be31a7fed20c2d1bde4b76c1d22bfd4312aa (diff) |
Mouse-panning while pressing button2
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -31,6 +31,8 @@ void on_keypress(XEvent*); void on_buttonpress(XEvent*); +void on_buttonrelease(XEvent*); +void on_motionnotify(XEvent*); void on_configurenotify(XEvent*); void update_title(); @@ -38,6 +40,8 @@ void update_title(); static void (*handler[LASTEvent])(XEvent*) = { [KeyPress] = on_keypress, [ButtonPress] = on_buttonpress, + [ButtonRelease] = on_buttonrelease, + [MotionNotify] = on_motionnotify, [ConfigureNotify] = on_configurenotify }; @@ -49,6 +53,9 @@ int filecnt, fileidx; unsigned char timeout; +int mox; +int moy; + #define TITLE_LEN 256 char win_title[TITLE_LEN]; @@ -276,6 +283,11 @@ void on_buttonpress(XEvent *ev) { changed = 1; } break; + case Button2: + mox = ev->xbutton.x; + moy = ev->xbutton.y; + win_set_cursor(&win, CURSOR_HAND); + break; case Button3: if (fileidx > 0) { img_load(&img, filenames[--fileidx]); @@ -313,6 +325,31 @@ void on_buttonpress(XEvent *ev) { } } +void on_buttonrelease(XEvent *ev) { + if (!ev) + return; + + if (ev->xbutton.button == Button2) + win_set_cursor(&win, CURSOR_ARROW); +} + +void on_motionnotify(XEvent *ev) { + XMotionEvent *m; + + if (!ev) + return; + + m = &ev->xmotion; + + if (m->x >= 0 && m->x <= win.w && m->y >= 0 && m->y <= win.h) { + if (img_move(&img, &win, m->x - mox, m->y - moy)) + timeout = 1; + + mox = m->x; + moy = m->y; + } +} + void on_configurenotify(XEvent *ev) { if (!ev) return; |