2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
8 #include <X11/keysym.h>
16 void (*func)(Arg *arg);
22 #define CLEANMASK(mask) (mask & ~(NUMLOCKMASK | LockMask))
27 int x1, y1, ocx, ocy, di;
34 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
35 None, cursor[CurMove], CurrentTime) != GrabSuccess)
37 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
39 XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev);
47 c->x = ocx + (ev.xmotion.x - x1);
48 c->y = ocy + (ev.xmotion.y - y1);
49 resize(c, False, TopLeft);
52 XUngrabPointer(dpy, CurrentTime);
59 resizemouse(Client *c)
67 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
68 None, cursor[CurResize], CurrentTime) != GrabSuccess)
70 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
72 XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev);
80 c->w = abs(ocx - ev.xmotion.x);
81 c->h = abs(ocy - ev.xmotion.y);
82 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
83 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
84 if(ocx <= ev.xmotion.x)
85 sticky = (ocy <= ev.xmotion.y) ? TopLeft : BotLeft;
87 sticky = (ocy <= ev.xmotion.y) ? TopRight : BotRight;
88 resize(c, True, sticky);
91 XUngrabPointer(dpy, CurrentTime);
98 buttonpress(XEvent *e)
103 XButtonPressedEvent *ev = &e->xbutton;
105 if(barwin == ev->window) {
109 for(a.i = 0; a.i < TLast; a.i++) {
110 x += textw(tags[a.i]);
125 else if((c = getclient(ev->window))) {
131 if(!c->ismax && (arrange == dofloat || c->isfloat)) {
140 if(!c->ismax && (arrange == dofloat || c->isfloat)) {
150 configurerequest(XEvent *e)
153 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)
170 resize(c, True, TopLeft);
175 wc.width = ev->width;
176 wc.height = ev->height;
178 XConfigureWindow(dpy, ev->window,
179 CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
184 destroynotify(XEvent *e)
187 XDestroyWindowEvent *ev = &e->xdestroywindow;
189 if((c = getclient(ev->window)))
194 enternotify(XEvent *e)
197 XCrossingEvent *ev = &e->xcrossing;
199 if(ev->detail == NotifyInferior)
202 if((c = getclient(ev->window)) || (c = getctitle(ev->window)))
204 else if(ev->window == root)
212 XExposeEvent *ev = &e->xexpose;
215 if(barwin == ev->window)
217 else if((c = getctitle(ev->window)))
225 static unsigned int len = sizeof(key) / sizeof(key[0]);
228 XKeyEvent *ev = &e->xkey;
230 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
231 for(i = 0; i < len; i++)
232 if(keysym == key[i].keysym &&
233 CLEANMASK(key[i].mod) == CLEANMASK(ev->state)) {
235 key[i].func(&key[i].arg);
241 leavenotify(XEvent *e)
243 XCrossingEvent *ev = &e->xcrossing;
245 if((ev->window == root) && !ev->same_screen)
250 maprequest(XEvent *e)
252 static XWindowAttributes wa;
253 XMapRequestEvent *ev = &e->xmaprequest;
255 if(!XGetWindowAttributes(dpy, ev->window, &wa))
258 if(wa.override_redirect) {
259 XSelectInput(dpy, ev->window,
260 (StructureNotifyMask | PropertyChangeMask));
264 if(!getclient(ev->window))
265 manage(ev->window, &wa);
269 propertynotify(XEvent *e)
273 XPropertyEvent *ev = &e->xproperty;
275 if(ev->state == PropertyDelete)
278 if((c = getclient(ev->window))) {
279 if(ev->atom == wmatom[WMProtocols]) {
280 c->proto = getproto(c->win);
285 case XA_WM_TRANSIENT_FOR:
286 XGetTransientForHint(dpy, c->win, &trans);
287 if(!c->isfloat && (c->isfloat = (trans != 0)))
290 case XA_WM_NORMAL_HINTS:
294 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
302 unmapnotify(XEvent *e)
305 XUnmapEvent *ev = &e->xunmap;
307 if((c = getclient(ev->window)))
313 void (*handler[LASTEvent]) (XEvent *) = {
314 [ButtonPress] = buttonpress,
315 [ConfigureRequest] = configurerequest,
316 [DestroyNotify] = destroynotify,
317 [EnterNotify] = enternotify,
318 [LeaveNotify] = leavenotify,
320 [KeyPress] = keypress,
321 [MapRequest] = maprequest,
322 [PropertyNotify] = propertynotify,
323 [UnmapNotify] = unmapnotify
329 static unsigned int len = sizeof(key) / sizeof(key[0]);
333 for(i = 0; i < len; i++) {
334 code = XKeysymToKeycode(dpy, key[i].keysym);
336 XUngrabKey(dpy, code, key[i].mod, root);
337 XGrabKey(dpy, code, key[i].mod, root, True,
338 GrabModeAsync, GrabModeAsync);
340 XUngrabKey(dpy, code, key[i].mod | LockMask, root);
341 XGrabKey(dpy, code, key[i].mod | LockMask, root, True,
342 GrabModeAsync, GrabModeAsync);
344 XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root);
345 XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root, True,
346 GrabModeAsync, GrabModeAsync);
347 /* capslock & numlock */
348 XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root);
349 XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root, True,
350 GrabModeAsync, GrabModeAsync);