2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
11 #include <X11/keysym.h>
12 #include <X11/Xatom.h>
16 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
17 #define MouseMask (ButtonMask | PointerMotionMask)
20 static void buttonpress(XEvent *e);
21 static void configurerequest(XEvent *e);
22 static void destroynotify(XEvent *e);
23 static void enternotify(XEvent *e);
24 static void leavenotify(XEvent *e);
25 static void expose(XEvent *e);
26 static void maprequest(XEvent *e);
27 static void propertynotify(XEvent *e);
28 static void unmapnotify(XEvent *e);
30 void (*handler[LASTEvent]) (XEvent *) = {
31 [ButtonPress] = buttonpress,
32 [ConfigureRequest] = configurerequest,
33 [DestroyNotify] = destroynotify,
34 [EnterNotify] = enternotify,
35 [LeaveNotify] = leavenotify,
37 [KeyPress] = keypress,
38 [MapRequest] = maprequest,
39 [PropertyNotify] = propertynotify,
40 [UnmapNotify] = unmapnotify
51 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
52 None, cursor[CurResize], CurrentTime) != GrabSuccess)
54 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
56 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
64 c->w = abs(ocx - ev.xmotion.x);
65 c->h = abs(ocy - ev.xmotion.y);
66 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
67 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
71 XUngrabPointer(dpy, CurrentTime);
81 int x1, y1, ocx, ocy, di;
87 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
88 None, cursor[CurMove], CurrentTime) != GrabSuccess)
90 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
92 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
100 c->x = ocx + (ev.xmotion.x - x1);
101 c->y = ocy + (ev.xmotion.y - y1);
105 XUngrabPointer(dpy, CurrentTime);
112 buttonpress(XEvent *e)
116 XButtonPressedEvent *ev = &e->xbutton;
119 if(barwin == ev->window) {
120 x = (arrange == floating) ? textw("~") : 0;
121 for(a.i = 0; a.i < TLast; a.i++) {
122 x += textw(tags[a.i]);
129 else if((c = getclient(ev->window))) {
130 if(arrange == tiling && !c->floating)
150 configurerequest(XEvent *e)
152 XConfigureRequestEvent *ev = &e->xconfigurerequest;
156 ev->value_mask &= ~CWSibling;
157 if((c = getclient(ev->window))) {
159 if(ev->value_mask & CWX)
161 if(ev->value_mask & CWY)
163 if(ev->value_mask & CWWidth)
165 if(ev->value_mask & CWHeight)
167 if(ev->value_mask & CWBorderWidth)
175 wc.width = ev->width;
176 wc.height = ev->height;
179 wc.stack_mode = Above;
180 ev->value_mask &= ~CWStackMode;
181 ev->value_mask |= CWBorderWidth;
182 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
187 destroynotify(XEvent *e)
190 XDestroyWindowEvent *ev = &e->xdestroywindow;
192 if((c = getclient(ev->window)))
197 enternotify(XEvent *e)
199 XCrossingEvent *ev = &e->xcrossing;
202 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
205 if((c = getclient(ev->window)))
207 else if(ev->window == root)
212 leavenotify(XEvent *e)
214 XCrossingEvent *ev = &e->xcrossing;
216 if((ev->window == root) && !ev->same_screen)
223 XExposeEvent *ev = &e->xexpose;
227 if(barwin == ev->window)
229 else if((c = gettitle(ev->window)))
235 maprequest(XEvent *e)
237 XMapRequestEvent *ev = &e->xmaprequest;
238 static XWindowAttributes wa;
240 if(!XGetWindowAttributes(dpy, ev->window, &wa))
243 if(wa.override_redirect) {
244 XSelectInput(dpy, ev->window,
245 (StructureNotifyMask | PropertyChangeMask));
249 if(!getclient(ev->window))
250 manage(ev->window, &wa);
254 propertynotify(XEvent *e)
256 XPropertyEvent *ev = &e->xproperty;
260 if(ev->state == PropertyDelete)
263 if((c = getclient(ev->window))) {
264 if(ev->atom == wm_atom[WMProtocols]) {
265 c->proto = win_proto(c->win);
270 case XA_WM_TRANSIENT_FOR:
271 XGetTransientForHint(dpy, c->win, &trans);
272 if(!c->floating && (c->floating = (trans != 0)))
275 case XA_WM_NORMAL_HINTS:
279 if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
287 unmapnotify(XEvent *e)
290 XUnmapEvent *ev = &e->xunmap;
292 if((c = getclient(ev->window)))