diff options
| author | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2012-07-09 22:42:28 +0300 |
|---|---|---|
| committer | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2012-07-20 18:52:17 +0300 |
| commit | f25780829287e582cf8984ed66b4d5157d2d1c2f (patch) | |
| tree | 5cb2553c8faeca4ad40ef4a3e52a7be87fba911a | |
| parent | be34f1d9fce482880b84a125b349f11bd1a0dfb8 (diff) | |
rework mousemotion function - use of if/else instead of switch/case
| -rw-r--r-- | monsterwm.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/monsterwm.c b/monsterwm.c index 909f0e0..d240c3c 100644 --- a/monsterwm.c +++ b/monsterwm.c @@ -552,11 +552,12 @@ void maprequest(XEvent *e) { void mousemotion(const Arg *arg) { Desktop *d = &desktops[currdeskidx]; XWindowAttributes wa; + XEvent ev; if (!d->curr || !XGetWindowAttributes(dis, d->curr->win, &wa)) return; - if (XGrabPointer(dis, root, False, BUTTONMASK|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) return; + if (arg->i == RESIZE) XWarpPointer(dis, None, d->curr->win, 0, 0, 0, 0, wa.width, wa.height); int rx, ry, c, xw, yh; unsigned int m; Window w; XQueryPointer(dis, root, &w, &w, &rx, &ry, &c, &c, &m); @@ -564,22 +565,17 @@ void mousemotion(const Arg *arg) { if (d->curr->isfull) setfullscreen(d->curr, False); if (!d->curr->isfloat && !d->curr->istrans) { d->curr->isfloat = True; tile(d); focus(d->curr, d); } - XEvent ev; do { XMaskEvent(dis, BUTTONMASK|PointerMotionMask|SubstructureRedirectMask, &ev); - switch (ev.type) { - case ConfigureRequest: case MapRequest: - events[ev.type](&ev); - break; - case MotionNotify: - xw = (arg->i == MOVE ? wa.x:wa.width) + ev.xmotion.x - rx; - yh = (arg->i == MOVE ? wa.y:wa.height) + ev.xmotion.y - ry; - if (arg->i == RESIZE) XResizeWindow(dis, d->curr->win, - xw > MINWSZ ? xw:wa.width, yh > MINWSZ ? yh:wa.height); - else if (arg->i == MOVE) XMoveWindow(dis, d->curr->win, xw, yh); - break; - } - } while(ev.type != ButtonRelease); + if (ev.type == MotionNotify) { + xw = (arg->i == MOVE ? wa.x:wa.width) + ev.xmotion.x - rx; + yh = (arg->i == MOVE ? wa.y:wa.height) + ev.xmotion.y - ry; + if (arg->i == RESIZE) XResizeWindow(dis, d->curr->win, + xw > MINWSZ ? xw:wa.width, yh > MINWSZ ? yh:wa.height); + else if (arg->i == MOVE) XMoveWindow(dis, d->curr->win, xw, yh); + } else if (ev.type == ConfigureRequest || ev.type == MapRequest) events[ev.type](&ev); + } while (ev.type != ButtonRelease); + XUngrabPointer(dis, CurrentTime); } |
