all repos — dwm @ 3f942f9e798d4222116ae4c083d2482ddb1e972b

fork of suckless dynamic window manager

mouse.c (view raw)

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