From c52c4fa69e2a6a58813fe35a5c4a1fe23661db03 Mon Sep 17 00:00:00 2001 From: Bert Date: Sat, 29 Jan 2011 22:37:40 +0100 Subject: Mouse-panning while pressing button2 --- window.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index ea86ad3..d5f5f4f 100644 --- a/window.c +++ b/window.c @@ -21,12 +21,16 @@ #include #include +#include #include "sxiv.h" #include "options.h" #include "window.h" -GC bgc; +static Cursor arrow; +static Cursor hand; + +static GC bgc; void win_open(win_t *win) { win_env_t *e; @@ -66,8 +70,11 @@ void win_open(win_t *win) { if (win->xwin == None) DIE("could not create window"); - XSelectInput(e->dpy, win->xwin, - StructureNotifyMask | KeyPressMask | ButtonPressMask); + XSelectInput(e->dpy, win->xwin, StructureNotifyMask | KeyPressMask | + ButtonPressMask | ButtonReleaseMask | Button2MotionMask); + + arrow = XCreateFontCursor(e->dpy, XC_left_ptr); + hand = XCreateFontCursor(e->dpy, XC_fleur); bgc = XCreateGC(e->dpy, win->xwin, 0, None); @@ -91,6 +98,11 @@ void win_close(win_t *win) { if (!win) return; + XFreeCursor(win->env.dpy, arrow); + XFreeCursor(win->env.dpy, hand); + + XFreeGC(win->env.dpy, bgc); + XDestroyWindow(win->env.dpy, win->xwin); XCloseDisplay(win->env.dpy); } @@ -174,3 +186,18 @@ void win_draw(win_t *win) { XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm); XClearWindow(win->env.dpy, win->xwin); } + +void win_set_cursor(win_t *win, win_cur_t cursor) { + if (!win) + return; + + switch (cursor) { + case CURSOR_HAND: + XDefineCursor(win->env.dpy, win->xwin, hand); + break; + case CURSOR_ARROW: + default: + XDefineCursor(win->env.dpy, win->xwin, arrow); + break; + } +} -- cgit v1.2.3-70-g09d2