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 static unsigned int valid_mask = 255 & ~(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;
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)
200 XCrossingEvent *ev = &e->xcrossing;
202 if(ev->detail == NotifyInferior)
205 if((c = getclient(ev->window)))
207 else if(ev->window == root)
215 XExposeEvent *ev = &e->xexpose;
218 if(barwin == ev->window)
220 else if((c = getctitle(ev->window)))
228 static unsigned int len = sizeof(key) / sizeof(key[0]);
231 XKeyEvent *ev = &e->xkey;
232 ev->state &= valid_mask;
234 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
235 for(i = 0; i < len; i++)
236 if((keysym == key[i].keysym) && ((key[i].mod & valid_mask) == ev->state)) {
238 key[i].func(&key[i].arg);
244 leavenotify(XEvent *e)
246 XCrossingEvent *ev = &e->xcrossing;
248 if((ev->window == root) && !ev->same_screen)
253 maprequest(XEvent *e)
255 static XWindowAttributes wa;
256 XMapRequestEvent *ev = &e->xmaprequest;
258 if(!XGetWindowAttributes(dpy, ev->window, &wa))
261 if(wa.override_redirect) {
262 XSelectInput(dpy, ev->window,
263 (StructureNotifyMask | PropertyChangeMask));
267 if(!getclient(ev->window))
268 manage(ev->window, &wa);
272 propertynotify(XEvent *e)
276 XPropertyEvent *ev = &e->xproperty;
278 if(ev->state == PropertyDelete)
281 if((c = getclient(ev->window))) {
282 if(ev->atom == wmatom[WMProtocols]) {
283 c->proto = getproto(c->win);
288 case XA_WM_TRANSIENT_FOR:
289 XGetTransientForHint(dpy, c->win, &trans);
290 if(!c->isfloat && (c->isfloat = (trans != 0)))
293 case XA_WM_NORMAL_HINTS:
297 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
305 unmapnotify(XEvent *e)
308 XUnmapEvent *ev = &e->xunmap;
310 if((c = getclient(ev->window)))
316 void (*handler[LASTEvent]) (XEvent *) = {
317 [ButtonPress] = buttonpress,
318 [ConfigureRequest] = configurerequest,
319 [DestroyNotify] = destroynotify,
320 [EnterNotify] = enternotify,
321 [LeaveNotify] = leavenotify,
323 [KeyPress] = keypress,
324 [MapRequest] = maprequest,
325 [PropertyNotify] = propertynotify,
326 [UnmapNotify] = unmapnotify
332 static unsigned int len = sizeof(key) / sizeof(key[0]);
336 for(i = 0; i < len; i++) {
337 code = XKeysymToKeycode(dpy, key[i].keysym);
338 XUngrabKey(dpy, code, key[i].mod, root);
339 XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root);
340 XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root);
341 XGrabKey(dpy, code, key[i].mod, root, True,
342 GrabModeAsync, GrabModeAsync);
343 XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root, True,
344 GrabModeAsync, GrabModeAsync);
345 XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root, True,
346 GrabModeAsync, GrabModeAsync);