summaryrefslogtreecommitdiffstats
path: root/event.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--event.c141
1 files changed, 69 insertions, 72 deletions
diff --git a/event.c b/event.c
index 2d8a728..798cb3c 100644
--- a/event.c
+++ b/event.c
@@ -51,8 +51,73 @@ Key key[] = {
51 51
52/* static functions */ 52/* static functions */
53 53
54static void movemouse(Client *c); 54static void
55static void resizemouse(Client *c); 55movemouse(Client *c)
56{
57 XEvent ev;
58 int x1, y1, ocx, ocy, di;
59 unsigned int dui;
60 Window dummy;
61
62 ocx = c->x;
63 ocy = c->y;
64 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
65 None, cursor[CurMove], CurrentTime) != GrabSuccess)
66 return;
67 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
68 for(;;) {
69 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
70 switch (ev.type) {
71 default: break;
72 case Expose:
73 handler[Expose](&ev);
74 break;
75 case MotionNotify:
76 XFlush(dpy);
77 c->x = ocx + (ev.xmotion.x - x1);
78 c->y = ocy + (ev.xmotion.y - y1);
79 resize(c, False);
80 break;
81 case ButtonRelease:
82 XUngrabPointer(dpy, CurrentTime);
83 return;
84 }
85 }
86}
87
88static void
89resizemouse(Client *c)
90{
91 XEvent ev;
92 int ocx, ocy;
93
94 ocx = c->x;
95 ocy = c->y;
96 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
97 None, cursor[CurResize], CurrentTime) != GrabSuccess)
98 return;
99 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
100 for(;;) {
101 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
102 switch(ev.type) {
103 default: break;
104 case Expose:
105 handler[Expose](&ev);
106 break;
107 case MotionNotify:
108 XFlush(dpy);
109 c->w = abs(ocx - ev.xmotion.x);
110 c->h = abs(ocy - ev.xmotion.y);
111 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
112 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
113 resize(c, True);
114 break;
115 case ButtonRelease:
116 XUngrabPointer(dpy, CurrentTime);
117 return;
118 }
119 }
120}
56 121
57static void 122static void
58buttonpress(XEvent *e) 123buttonpress(XEvent *e)
@@ -214,40 +279,6 @@ maprequest(XEvent *e)
214} 279}
215 280
216static void 281static void
217movemouse(Client *c)
218{
219 XEvent ev;
220 int x1, y1, ocx, ocy, di;
221 unsigned int dui;
222 Window dummy;
223
224 ocx = c->x;
225 ocy = c->y;
226 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
227 None, cursor[CurMove], CurrentTime) != GrabSuccess)
228 return;
229 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
230 for(;;) {
231 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
232 switch (ev.type) {
233 default: break;
234 case Expose:
235 handler[Expose](&ev);
236 break;
237 case MotionNotify:
238 XFlush(dpy);
239 c->x = ocx + (ev.xmotion.x - x1);
240 c->y = ocy + (ev.xmotion.y - y1);
241 resize(c, False);
242 break;
243 case ButtonRelease:
244 XUngrabPointer(dpy, CurrentTime);
245 return;
246 }
247 }
248}
249
250static void
251propertynotify(XEvent *e) 282propertynotify(XEvent *e)
252{ 283{
253 XPropertyEvent *ev = &e->xproperty; 284 XPropertyEvent *ev = &e->xproperty;
@@ -258,7 +289,7 @@ propertynotify(XEvent *e)
258 return; /* ignore */ 289 return; /* ignore */
259 290
260 if((c = getclient(ev->window))) { 291 if((c = getclient(ev->window))) {
261 if(ev->atom == wm_atom[WMProtocols]) { 292 if(ev->atom == wmatom[WMProtocols]) {
262 c->proto = getproto(c->win); 293 c->proto = getproto(c->win);
263 return; 294 return;
264 } 295 }
@@ -273,7 +304,7 @@ propertynotify(XEvent *e)
273 setsize(c); 304 setsize(c);
274 break; 305 break;
275 } 306 }
276 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) { 307 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
277 settitle(c); 308 settitle(c);
278 drawtitle(c); 309 drawtitle(c);
279 } 310 }
@@ -281,40 +312,6 @@ propertynotify(XEvent *e)
281} 312}
282 313
283static void 314static void
284resizemouse(Client *c)
285{
286 XEvent ev;
287 int ocx, ocy;
288
289 ocx = c->x;
290 ocy = c->y;
291 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
292 None, cursor[CurResize], CurrentTime) != GrabSuccess)
293 return;
294 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
295 for(;;) {
296 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
297 switch(ev.type) {
298 default: break;
299 case Expose:
300 handler[Expose](&ev);
301 break;
302 case MotionNotify:
303 XFlush(dpy);
304 c->w = abs(ocx - ev.xmotion.x);
305 c->h = abs(ocy - ev.xmotion.y);
306 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
307 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
308 resize(c, True);
309 break;
310 case ButtonRelease:
311 XUngrabPointer(dpy, CurrentTime);
312 return;
313 }
314 }
315}
316
317static void
318unmapnotify(XEvent *e) 315unmapnotify(XEvent *e)
319{ 316{
320 Client *c; 317 Client *c;