aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-01-29 22:37:40 +0100
committerBert <ber.t@gmx.com>2011-01-29 22:37:40 +0100
commitc52c4fa69e2a6a58813fe35a5c4a1fe23661db03 (patch)
tree6ddefe9122c481495caceec023a79786e5412b84 /main.c
parent4ab4be31a7fed20c2d1bde4b76c1d22bfd4312aa (diff)
downloadnsxiv-c52c4fa69e2a6a58813fe35a5c4a1fe23661db03.tar.zst
Mouse-panning while pressing button2
Diffstat (limited to 'main.c')
-rw-r--r--main.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/main.c b/main.c
index aa21426..df4ef9e 100644
--- a/main.c
+++ b/main.c
@@ -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;