dwm-meillo

view mouse.c @ 31:386649deb651

before leaning things up
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 01:04:38 +0200
parents e8f627998d6f
children fc9ccd34b8ab
line source
1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * (C)opyright MMVI Kris Maglione <fbsdaemon@gmail.com>
4 * See LICENSE file for license details.
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
11 #include "wm.h"
13 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
14 #define MouseMask (ButtonMask | PointerMotionMask)
16 void
17 mresize(Client *c)
18 {
19 XEvent ev;
20 int old_cx, old_cy;
22 old_cx = c->x;
23 old_cy = c->y;
24 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
25 None, cursor[CurResize], CurrentTime) != GrabSuccess)
26 return;
27 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
28 for(;;) {
29 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
30 switch(ev.type) {
31 default: break;
32 case Expose:
33 handler[Expose](&ev);
34 break;
35 case MotionNotify:
36 XFlush(dpy);
37 c->w = abs(old_cx - ev.xmotion.x);
38 c->h = abs(old_cy - ev.xmotion.y);
39 c->x = (old_cx <= ev.xmotion.x) ? old_cx : old_cx - c->w;
40 c->y = (old_cy <= ev.xmotion.y) ? old_cy : old_cy - c->h;
41 resize(c);
42 break;
43 case ButtonRelease:
44 XUngrabPointer(dpy, CurrentTime);
45 return;
46 }
47 }
48 }
50 void
51 mmove(Client *c)
52 {
53 XEvent ev;
54 int x1, y1, old_cx, old_cy, di;
55 unsigned int dui;
56 Window dummy;
58 old_cx = c->x;
59 old_cy = c->y;
60 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
61 None, cursor[CurMove], CurrentTime) != GrabSuccess)
62 return;
63 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
64 for(;;) {
65 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
66 switch (ev.type) {
67 default: break;
68 case Expose:
69 handler[Expose](&ev);
70 break;
71 case MotionNotify:
72 XFlush(dpy);
73 c->x = old_cx + (ev.xmotion.x - x1);
74 c->y = old_cy + (ev.xmotion.y - y1);
75 resize(c);
76 break;
77 case ButtonRelease:
78 XUngrabPointer(dpy, CurrentTime);
79 return;
80 }
81 }
82 }