Mercurial > dwm-meillo
annotate mouse.c @ 30:2e0fb4130bfb
new stuff, fixed several issues
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Wed, 12 Jul 2006 17:50:31 +0200 |
parents | e8f627998d6f |
children | 386649deb651 |
rev | line source |
---|---|
18 | 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 */ | |
6 | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <unistd.h> | |
10 | |
11 #include "wm.h" | |
12 | |
13 #define ButtonMask (ButtonPressMask | ButtonReleaseMask) | |
14 #define MouseMask (ButtonMask | PointerMotionMask) | |
15 | |
16 static void | |
17 mmatch(Client *c, int x1, int y1, int x2, int y2) | |
18 { | |
20 | 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; | |
18 | 35 } |
36 | |
37 void | |
38 mresize(Client *c) | |
39 { | |
40 XEvent ev; | |
41 int old_cx, old_cy; | |
42 | |
20 | 43 old_cx = c->x; |
44 old_cy = c->y; | |
19
b5510d0c6d43
added basic mouse support (actually we don't need more)
Anselm R. Garbe <garbeam@wmii.de>
parents:
18
diff
changeset
|
45 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, |
18 | 46 None, cursor[CurResize], CurrentTime) != GrabSuccess) |
47 return; | |
20 | 48 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); |
18 | 49 for(;;) { |
26
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
50 XMaskEvent(dpy, MouseMask | ExposureMask, &ev); |
18 | 51 switch(ev.type) { |
52 default: break; | |
26
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
53 case Expose: |
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
54 handler[Expose](&ev); |
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
55 break; |
18 | 56 case MotionNotify: |
26
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
57 XFlush(dpy); |
18 | 58 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y); |
20 | 59 XResizeWindow(dpy, c->win, c->w, c->h); |
18 | 60 break; |
61 case ButtonRelease: | |
19
b5510d0c6d43
added basic mouse support (actually we don't need more)
Anselm R. Garbe <garbeam@wmii.de>
parents:
18
diff
changeset
|
62 resize(c); |
18 | 63 XUngrabPointer(dpy, CurrentTime); |
64 return; | |
65 } | |
66 } | |
67 } | |
68 | |
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; | |
76 | |
20 | 77 old_cx = c->x; |
78 old_cy = c->y; | |
19
b5510d0c6d43
added basic mouse support (actually we don't need more)
Anselm R. Garbe <garbeam@wmii.de>
parents:
18
diff
changeset
|
79 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, |
18 | 80 None, cursor[CurMove], CurrentTime) != GrabSuccess) |
81 return; | |
82 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); | |
83 for(;;) { | |
26
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
84 XMaskEvent(dpy, MouseMask | ExposureMask, &ev); |
18 | 85 switch (ev.type) { |
86 default: break; | |
26
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
87 case Expose: |
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
88 handler[Expose](&ev); |
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
89 break; |
18 | 90 case MotionNotify: |
26
e8f627998d6f
simplified several portions of code through replacing rect structs with x,y,h,w counterparts (much more readable)
Anselm R. Garbe <garbeam@wmii.de>
parents:
20
diff
changeset
|
91 XFlush(dpy); |
20 | 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); | |
18 | 95 break; |
96 case ButtonRelease: | |
19
b5510d0c6d43
added basic mouse support (actually we don't need more)
Anselm R. Garbe <garbeam@wmii.de>
parents:
18
diff
changeset
|
97 resize(c); |
18 | 98 XUngrabPointer(dpy, CurrentTime); |
99 return; | |
100 } | |
101 } | |
102 } |