dwm-meillo

view mouse.c @ 28:3dceb132082d

added max
author Anselm R. Garbe <garbeam@wmii.de>
date Wed, 12 Jul 2006 16:40:37 +0200
parents 4560e0882c1d
children 386649deb651
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 static void
17 mmatch(Client *c, int x1, int y1, int x2, int y2)
18 {
19 c->w = abs(x1 - x2);
20 c->h = abs(y1 - y2);
21 if(c->incw)
22 c->w -= (c->w - c->basew) % c->incw;
23 if(c->inch)
24 c->h -= (c->h - c->baseh) % c->inch;
25 if(c->minw && c->w < c->minw)
26 c->w = c->minw;
27 if(c->minh && c->h < c->minh)
28 c->h = c->minh;
29 if(c->maxw && c->w > c->maxw)
30 c->w = c->maxw;
31 if(c->maxh && c->h > c->maxh)
32 c->h = c->maxh;
33 c->x = (x1 <= x2) ? x1 : x1 - c->w;
34 c->y = (y1 <= y2) ? y1 : y1 - c->h;
35 }
37 void
38 mresize(Client *c)
39 {
40 XEvent ev;
41 int old_cx, old_cy;
43 old_cx = c->x;
44 old_cy = c->y;
45 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
46 None, cursor[CurResize], CurrentTime) != GrabSuccess)
47 return;
48 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
49 for(;;) {
50 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
51 switch(ev.type) {
52 default: break;
53 case Expose:
54 handler[Expose](&ev);
55 break;
56 case MotionNotify:
57 XFlush(dpy);
58 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
59 XResizeWindow(dpy, c->win, c->w, c->h);
60 break;
61 case ButtonRelease:
62 resize(c);
63 XUngrabPointer(dpy, CurrentTime);
64 return;
65 }
66 }
67 }
69 void
70 mmove(Client *c)
71 {
72 XEvent ev;
73 int x1, y1, old_cx, old_cy, di;
74 unsigned int dui;
75 Window dummy;
77 old_cx = c->x;
78 old_cy = c->y;
79 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
80 None, cursor[CurMove], CurrentTime) != GrabSuccess)
81 return;
82 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
83 for(;;) {
84 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
85 switch (ev.type) {
86 default: break;
87 case Expose:
88 handler[Expose](&ev);
89 break;
90 case MotionNotify:
91 XFlush(dpy);
92 c->x = old_cx + (ev.xmotion.x - x1);
93 c->y = old_cy + (ev.xmotion.y - y1);
94 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
95 break;
96 case ButtonRelease:
97 resize(c);
98 XUngrabPointer(dpy, CurrentTime);
99 return;
100 }
101 }
102 }