dwm-meillo

annotate mouse.c @ 20:4560e0882c1d

made code more readable
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 22:49:09 +0200
parents b5510d0c6d43
children e8f627998d6f
rev   line source
garbeam@18 1 /*
garbeam@18 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
garbeam@18 3 * (C)opyright MMVI Kris Maglione <fbsdaemon@gmail.com>
garbeam@18 4 * See LICENSE file for license details.
garbeam@18 5 */
garbeam@18 6
garbeam@18 7 #include <stdlib.h>
garbeam@18 8 #include <string.h>
garbeam@18 9 #include <unistd.h>
garbeam@18 10
garbeam@18 11 #include "wm.h"
garbeam@18 12
garbeam@18 13 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
garbeam@18 14 #define MouseMask (ButtonMask | PointerMotionMask)
garbeam@18 15
garbeam@18 16 static void
garbeam@18 17 mmatch(Client *c, int x1, int y1, int x2, int y2)
garbeam@18 18 {
garbeam@20 19 c->w = abs(x1 - x2);
garbeam@20 20 c->h = abs(y1 - y2);
garbeam@20 21 if(c->incw)
garbeam@20 22 c->w -= (c->w - c->basew) % c->incw;
garbeam@20 23 if(c->inch)
garbeam@20 24 c->h -= (c->h - c->baseh) % c->inch;
garbeam@20 25 if(c->minw && c->w < c->minw)
garbeam@20 26 c->w = c->minw;
garbeam@20 27 if(c->minh && c->h < c->minh)
garbeam@20 28 c->h = c->minh;
garbeam@20 29 if(c->maxw && c->w > c->maxw)
garbeam@20 30 c->w = c->maxw;
garbeam@20 31 if(c->maxh && c->h > c->maxh)
garbeam@20 32 c->h = c->maxh;
garbeam@20 33 c->x = (x1 <= x2) ? x1 : x1 - c->w;
garbeam@20 34 c->y = (y1 <= y2) ? y1 : y1 - c->h;
garbeam@18 35 }
garbeam@18 36
garbeam@18 37 void
garbeam@18 38 mresize(Client *c)
garbeam@18 39 {
garbeam@18 40 XEvent ev;
garbeam@18 41 int old_cx, old_cy;
garbeam@18 42
garbeam@20 43 old_cx = c->x;
garbeam@20 44 old_cy = c->y;
garbeam@19 45 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
garbeam@18 46 None, cursor[CurResize], CurrentTime) != GrabSuccess)
garbeam@18 47 return;
garbeam@18 48 XGrabServer(dpy);
garbeam@20 49 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
garbeam@18 50 for(;;) {
garbeam@18 51 XMaskEvent(dpy, MouseMask, &ev);
garbeam@18 52 switch(ev.type) {
garbeam@18 53 default: break;
garbeam@18 54 case MotionNotify:
garbeam@18 55 XUngrabServer(dpy);
garbeam@18 56 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
garbeam@20 57 XResizeWindow(dpy, c->win, c->w, c->h);
garbeam@18 58 XGrabServer(dpy);
garbeam@18 59 break;
garbeam@18 60 case ButtonRelease:
garbeam@19 61 resize(c);
garbeam@19 62 XUngrabServer(dpy);
garbeam@18 63 XUngrabPointer(dpy, CurrentTime);
garbeam@18 64 return;
garbeam@18 65 }
garbeam@18 66 }
garbeam@18 67 }
garbeam@18 68
garbeam@18 69 void
garbeam@18 70 mmove(Client *c)
garbeam@18 71 {
garbeam@18 72 XEvent ev;
garbeam@18 73 int x1, y1, old_cx, old_cy, di;
garbeam@18 74 unsigned int dui;
garbeam@18 75 Window dummy;
garbeam@18 76
garbeam@20 77 old_cx = c->x;
garbeam@20 78 old_cy = c->y;
garbeam@19 79 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
garbeam@18 80 None, cursor[CurMove], CurrentTime) != GrabSuccess)
garbeam@18 81 return;
garbeam@18 82 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
garbeam@18 83 XGrabServer(dpy);
garbeam@18 84 for(;;) {
garbeam@18 85 XMaskEvent(dpy, MouseMask, &ev);
garbeam@18 86 switch (ev.type) {
garbeam@18 87 default: break;
garbeam@18 88 case MotionNotify:
garbeam@18 89 XUngrabServer(dpy);
garbeam@20 90 c->x = old_cx + (ev.xmotion.x - x1);
garbeam@20 91 c->y = old_cy + (ev.xmotion.y - y1);
garbeam@20 92 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
garbeam@18 93 XGrabServer(dpy);
garbeam@18 94 break;
garbeam@18 95 case ButtonRelease:
garbeam@19 96 resize(c);
garbeam@18 97 XUngrabServer(dpy);
garbeam@18 98 XUngrabPointer(dpy, CurrentTime);
garbeam@18 99 return;
garbeam@18 100 }
garbeam@18 101 }
garbeam@18 102 }