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@18
|
19 c->r[RFloat].width = abs(x1 - x2);
|
garbeam@18
|
20 c->r[RFloat].height = abs(y1 - y2);
|
garbeam@18
|
21 c->r[RFloat].width -=
|
garbeam@18
|
22 (c->r[RFloat].width - c->size.base_width) % c->size.width_inc;
|
garbeam@18
|
23 c->r[RFloat].height -=
|
garbeam@18
|
24 (c->r[RFloat].height - c->size.base_height) % c->size.height_inc;
|
garbeam@18
|
25 if(c->size.min_width && c->r[RFloat].width < c->size.min_width)
|
garbeam@18
|
26 c->r[RFloat].width = c->size.min_width;
|
garbeam@18
|
27 if(c->size.min_height && c->r[RFloat].height < c->size.min_height)
|
garbeam@18
|
28 c->r[RFloat].height = c->size.min_height;
|
garbeam@18
|
29 if(c->size.max_width && c->r[RFloat].width > c->size.max_width)
|
garbeam@18
|
30 c->r[RFloat].width = c->size.max_width;
|
garbeam@18
|
31 if(c->size.max_height && c->r[RFloat].height > c->size.max_height)
|
garbeam@18
|
32 c->r[RFloat].height = c->size.max_height;
|
garbeam@18
|
33 c->r[RFloat].x = (x1 <= x2) ? x1 : x1 - c->r[RFloat].width;
|
garbeam@18
|
34 c->r[RFloat].y = (y1 <= y2) ? y1 : y1 - c->r[RFloat].height;
|
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@18
|
43 old_cx = c->r[RFloat].x;
|
garbeam@18
|
44 old_cy = c->r[RFloat].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@18
|
49 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
|
garbeam@18
|
50 c->r[RFloat].width, c->r[RFloat].height);
|
garbeam@18
|
51 for(;;) {
|
garbeam@18
|
52 XMaskEvent(dpy, MouseMask, &ev);
|
garbeam@18
|
53 switch(ev.type) {
|
garbeam@18
|
54 default: break;
|
garbeam@18
|
55 case MotionNotify:
|
garbeam@18
|
56 XUngrabServer(dpy);
|
garbeam@18
|
57 mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y);
|
garbeam@19
|
58 XResizeWindow(dpy, c->win, c->r[RFloat].width, c->r[RFloat].height);
|
garbeam@18
|
59 XGrabServer(dpy);
|
garbeam@18
|
60 break;
|
garbeam@18
|
61 case ButtonRelease:
|
garbeam@19
|
62 resize(c);
|
garbeam@19
|
63 XUngrabServer(dpy);
|
garbeam@18
|
64 XUngrabPointer(dpy, CurrentTime);
|
garbeam@18
|
65 return;
|
garbeam@18
|
66 }
|
garbeam@18
|
67 }
|
garbeam@18
|
68 }
|
garbeam@18
|
69
|
garbeam@18
|
70 void
|
garbeam@18
|
71 mmove(Client *c)
|
garbeam@18
|
72 {
|
garbeam@18
|
73 XEvent ev;
|
garbeam@18
|
74 int x1, y1, old_cx, old_cy, di;
|
garbeam@18
|
75 unsigned int dui;
|
garbeam@18
|
76 Window dummy;
|
garbeam@18
|
77
|
garbeam@18
|
78 old_cx = c->r[RFloat].x;
|
garbeam@18
|
79 old_cy = c->r[RFloat].y;
|
garbeam@19
|
80 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
|
garbeam@18
|
81 None, cursor[CurMove], CurrentTime) != GrabSuccess)
|
garbeam@18
|
82 return;
|
garbeam@18
|
83 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
|
garbeam@18
|
84 XGrabServer(dpy);
|
garbeam@18
|
85 for(;;) {
|
garbeam@18
|
86 XMaskEvent(dpy, MouseMask, &ev);
|
garbeam@18
|
87 switch (ev.type) {
|
garbeam@18
|
88 default: break;
|
garbeam@18
|
89 case MotionNotify:
|
garbeam@18
|
90 XUngrabServer(dpy);
|
garbeam@18
|
91 c->r[RFloat].x = old_cx + (ev.xmotion.x - x1);
|
garbeam@18
|
92 c->r[RFloat].y = old_cy + (ev.xmotion.y - y1);
|
garbeam@19
|
93 XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y,
|
garbeam@19
|
94 c->r[RFloat].width, c->r[RFloat].height);
|
garbeam@18
|
95 XGrabServer(dpy);
|
garbeam@18
|
96 break;
|
garbeam@18
|
97 case ButtonRelease:
|
garbeam@19
|
98 resize(c);
|
garbeam@18
|
99 XUngrabServer(dpy);
|
garbeam@18
|
100 XUngrabPointer(dpy, CurrentTime);
|
garbeam@18
|
101 return;
|
garbeam@18
|
102 }
|
garbeam@18
|
103 }
|
garbeam@18
|
104 }
|