2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
7 #include <X11/keysym.h>
15 void (*func)(Arg *arg);
21 #define CLEANMASK(mask) (mask & ~(NUMLOCKMASK | LockMask))
26 int x1, y1, ocx, ocy, di;
33 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
34 None, cursor[CurMove], CurrentTime) != GrabSuccess)
36 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
38 XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev);
46 c->x = ocx + (ev.xmotion.x - x1);
47 c->y = ocy + (ev.xmotion.y - y1);
48 resize(c, False, TopLeft);
51 XUngrabPointer(dpy, CurrentTime);
58 resizemouse(Client *c)
66 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
67 None, cursor[CurResize], CurrentTime) != GrabSuccess)
69 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
71 XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev);
79 c->w = abs(ocx - ev.xmotion.x);
80 c->h = abs(ocy - ev.xmotion.y);
81 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
82 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
83 if(ocx <= ev.xmotion.x)
84 sticky = (ocy <= ev.xmotion.y) ? TopLeft : BotLeft;
86 sticky = (ocy <= ev.xmotion.y) ? TopRight : BotRight;
87 resize(c, True, sticky);
90 XUngrabPointer(dpy, CurrentTime);
97 buttonpress(XEvent *e)
102 XButtonPressedEvent *ev = &e->xbutton;
104 if(barwin == ev->window) {
108 for(a.i = 0; a.i < TLast; a.i++) {
109 x += textw(tags[a.i]);
124 else if((c = getclient(ev->window))) {
130 if(!c->ismax && (arrange == dofloat || c->isfloat)) {
139 if(!c->ismax && (arrange == dofloat || c->isfloat)) {
149 configurerequest(XEvent *e)
152 XConfigureRequestEvent *ev = &e->xconfigurerequest;
155 unsigned long newmask;
157 if((c = getclient(ev->window))) {
160 if(ev->value_mask & CWX)
162 if(ev->value_mask & CWY)
164 if(ev->value_mask & CWWidth)
166 if(ev->value_mask & CWHeight)
169 if(ev->value_mask & CWBorderWidth)
170 c->border = ev->border_width;
173 resize(c, True, TopLeft);
179 newmask = ev->value_mask & (~(CWSibling | CWStackMode | CWBorderWidth));
181 XConfigureWindow(dpy, c->win, newmask, &wc);
183 synev.type = ConfigureNotify;
184 synev.xconfigure.display = dpy;
185 synev.xconfigure.event = c->win;
186 synev.xconfigure.window = c->win;
187 synev.xconfigure.x = c->x;
188 synev.xconfigure.y = c->y;
189 synev.xconfigure.width = c->w;
190 synev.xconfigure.height = c->h;
191 synev.xconfigure.border_width = c->border;
192 synev.xconfigure.above = None;
193 /* Send synthetic ConfigureNotify */
194 XSendEvent(dpy, c->win, True, NoEventMask, &synev);
200 wc.width = ev->width;
201 wc.height = ev->height;
202 wc.border_width = ev->border_width;
203 wc.sibling = ev->above;
204 wc.stack_mode = ev->detail;
205 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
211 destroynotify(XEvent *e)
214 XDestroyWindowEvent *ev = &e->xdestroywindow;
216 if((c = getclient(ev->window)))
221 enternotify(XEvent *e)
224 XCrossingEvent *ev = &e->xcrossing;
226 if(ev->detail == NotifyInferior)
229 if((c = getclient(ev->window)) || (c = getctitle(ev->window)))
231 else if(ev->window == root)
239 XExposeEvent *ev = &e->xexpose;
242 if(barwin == ev->window)
244 else if((c = getctitle(ev->window)))
252 static unsigned int len = sizeof(key) / sizeof(key[0]);
255 XKeyEvent *ev = &e->xkey;
257 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
258 for(i = 0; i < len; i++)
259 if(keysym == key[i].keysym &&
260 CLEANMASK(key[i].mod) == CLEANMASK(ev->state)) {
262 key[i].func(&key[i].arg);
268 leavenotify(XEvent *e)
270 XCrossingEvent *ev = &e->xcrossing;
272 if((ev->window == root) && !ev->same_screen)
277 maprequest(XEvent *e)
279 static XWindowAttributes wa;
280 XMapRequestEvent *ev = &e->xmaprequest;
282 if(!XGetWindowAttributes(dpy, ev->window, &wa))
285 if(wa.override_redirect) {
286 XSelectInput(dpy, ev->window,
287 (StructureNotifyMask | PropertyChangeMask));
291 if(!getclient(ev->window))
292 manage(ev->window, &wa);
296 propertynotify(XEvent *e)
300 XPropertyEvent *ev = &e->xproperty;
302 if(ev->state == PropertyDelete)
305 if((c = getclient(ev->window))) {
306 if(ev->atom == wmatom[WMProtocols]) {
307 c->proto = getproto(c->win);
312 case XA_WM_TRANSIENT_FOR:
313 XGetTransientForHint(dpy, c->win, &trans);
314 if(!c->isfloat && (c->isfloat = (trans != 0)))
317 case XA_WM_NORMAL_HINTS:
321 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
329 unmapnotify(XEvent *e)
332 XUnmapEvent *ev = &e->xunmap;
334 if((c = getclient(ev->window)))
340 void (*handler[LASTEvent]) (XEvent *) = {
341 [ButtonPress] = buttonpress,
342 [ConfigureRequest] = configurerequest,
343 [DestroyNotify] = destroynotify,
344 [EnterNotify] = enternotify,
345 [LeaveNotify] = leavenotify,
347 [KeyPress] = keypress,
348 [MapRequest] = maprequest,
349 [PropertyNotify] = propertynotify,
350 [UnmapNotify] = unmapnotify
356 static unsigned int len = sizeof(key) / sizeof(key[0]);
360 for(i = 0; i < len; i++) {
361 code = XKeysymToKeycode(dpy, key[i].keysym);
363 XUngrabKey(dpy, code, key[i].mod, root);
364 XGrabKey(dpy, code, key[i].mod, root, True,
365 GrabModeAsync, GrabModeAsync);
367 XUngrabKey(dpy, code, key[i].mod | LockMask, root);
368 XGrabKey(dpy, code, key[i].mod | LockMask, root, True,
369 GrabModeAsync, GrabModeAsync);
371 XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root);
372 XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root, True,
373 GrabModeAsync, GrabModeAsync);
374 /* capslock & numlock */
375 XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root);
376 XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root, True,
377 GrabModeAsync, GrabModeAsync);