2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
8 #include <X11/keysym.h>
11 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
12 #define MouseMask (ButtonMask | PointerMotionMask)
19 void (*func)(Arg *arg);
24 const char *browse[] = { "firefox", NULL };
25 const char *gimp[] = { "gimp", NULL };
27 const char *term[] = { "xterm", NULL };
29 "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-cr", "white",
30 "-fn", "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", NULL
32 coonst char *xlock[] = { "xlock", NULL };
36 /* modifier key function arguments */
37 { ControlMask, XK_0, appendtag, { .i = Tscratch } },
38 { ControlMask, XK_1, appendtag, { .i = Tdev } },
39 { ControlMask, XK_2, appendtag, { .i = Twww } },
40 { ControlMask, XK_3, appendtag, { .i = Twork } },
41 { MODKEY, XK_0, view, { .i = Tscratch } },
42 { MODKEY, XK_1, view, { .i = Tdev } },
43 { MODKEY, XK_2, view, { .i = Twww } },
44 { MODKEY, XK_3, view, { .i = Twork } },
45 { MODKEY, XK_j, focusnext, { 0 } },
46 { MODKEY, XK_k, focusprev, { 0 } },
47 { MODKEY, XK_m, maximize, { 0 } },
48 { MODKEY, XK_space, dotile, { 0 } },
49 { MODKEY, XK_Return, zoom, { 0 } },
50 { ControlMask|ShiftMask,XK_0, heretag, { .i = Tscratch } },
51 { ControlMask|ShiftMask,XK_1, heretag, { .i = Tdev } },
52 { ControlMask|ShiftMask,XK_2, heretag, { .i = Twww } },
53 { ControlMask|ShiftMask,XK_3, heretag, { .i = Twork } },
54 { MODKEY|ShiftMask, XK_0, replacetag, { .i = Tscratch } },
55 { MODKEY|ShiftMask, XK_1, replacetag, { .i = Tdev } },
56 { MODKEY|ShiftMask, XK_2, replacetag, { .i = Twww } },
57 { MODKEY|ShiftMask, XK_3, replacetag, { .i = Twork } },
58 { MODKEY|ShiftMask, XK_c, killclient, { 0 } },
60 { MODKEY|ShiftMask, XK_g, spawn, { .argv = gimp } },
61 { MODKEY|ShiftMask, XK_l, spawn, { .argv = xlock } },
63 { MODKEY|ShiftMask, XK_q, quit, { 0 } },
64 { MODKEY|ShiftMask, XK_space, dofloat, { 0 } },
65 /*{ MODKEY|ShiftMask, XK_w, spawn, { .argv = browse } },*/
66 { MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } },
75 int x1, y1, ocx, ocy, di;
81 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
82 None, cursor[CurMove], CurrentTime) != GrabSuccess)
84 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
86 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
94 c->x = ocx + (ev.xmotion.x - x1);
95 c->y = ocy + (ev.xmotion.y - y1);
96 resize(c, False, TopLeft);
99 XUngrabPointer(dpy, CurrentTime);
106 resizemouse(Client *c)
114 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
115 None, cursor[CurResize], CurrentTime) != GrabSuccess)
117 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
119 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
123 handler[Expose](&ev);
127 c->w = abs(ocx - ev.xmotion.x);
128 c->h = abs(ocy - ev.xmotion.y);
129 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
130 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
131 if(ocx <= ev.xmotion.x)
132 sticky = (ocy <= ev.xmotion.y) ? TopLeft : BotLeft;
134 sticky = (ocy <= ev.xmotion.y) ? TopRight : BotRight;
135 resize(c, True, sticky);
138 XUngrabPointer(dpy, CurrentTime);
145 buttonpress(XEvent *e)
149 XButtonPressedEvent *ev = &e->xbutton;
152 if(barwin == ev->window) {
156 for(a.i = 0; a.i < TLast; a.i++) {
157 x += textw(tags[a.i]);
165 a.i = (tsel + 1 < TLast) ? tsel + 1 : 0;
169 a.i = (tsel - 1 >= 0) ? tsel - 1 : TLast - 1;
174 else if((c = getclient(ev->window))) {
179 if(arrange == dotile && !c->isfloat) {
180 if((ev->state & ControlMask) && (ev->button == Button1))
192 if(arrange == dofloat || c->isfloat) {
202 configurerequest(XEvent *e)
204 XConfigureRequestEvent *ev = &e->xconfigurerequest;
208 ev->value_mask &= ~CWSibling;
209 if((c = getclient(ev->window))) {
211 if(ev->value_mask & CWX)
213 if(ev->value_mask & CWY)
215 if(ev->value_mask & CWWidth)
217 if(ev->value_mask & CWHeight)
219 if(ev->value_mask & CWBorderWidth)
222 resize(c, True, TopLeft);
227 wc.width = ev->width;
228 wc.height = ev->height;
231 wc.stack_mode = Above;
232 ev->value_mask &= ~CWStackMode;
233 ev->value_mask |= CWBorderWidth;
234 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
239 destroynotify(XEvent *e)
242 XDestroyWindowEvent *ev = &e->xdestroywindow;
244 if((c = getclient(ev->window)))
249 enternotify(XEvent *e)
251 XCrossingEvent *ev = &e->xcrossing;
254 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
257 if((c = getclient(ev->window)))
259 else if(ev->window == root)
266 XExposeEvent *ev = &e->xexpose;
270 if(barwin == ev->window)
272 else if((c = getctitle(ev->window)))
280 XKeyEvent *ev = &e->xkey;
281 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
285 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
286 for(i = 0; i < len; i++)
287 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
289 key[i].func(&key[i].arg);
295 leavenotify(XEvent *e)
297 XCrossingEvent *ev = &e->xcrossing;
299 if((ev->window == root) && !ev->same_screen)
304 maprequest(XEvent *e)
306 XMapRequestEvent *ev = &e->xmaprequest;
307 static XWindowAttributes wa;
309 if(!XGetWindowAttributes(dpy, ev->window, &wa))
312 if(wa.override_redirect) {
313 XSelectInput(dpy, ev->window,
314 (StructureNotifyMask | PropertyChangeMask));
318 if(!getclient(ev->window))
319 manage(ev->window, &wa);
323 propertynotify(XEvent *e)
325 XPropertyEvent *ev = &e->xproperty;
329 if(ev->state == PropertyDelete)
332 if((c = getclient(ev->window))) {
333 if(ev->atom == wmatom[WMProtocols]) {
334 c->proto = getproto(c->win);
339 case XA_WM_TRANSIENT_FOR:
340 XGetTransientForHint(dpy, c->win, &trans);
341 if(!c->isfloat && (c->isfloat = (trans != 0)))
344 case XA_WM_NORMAL_HINTS:
348 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
356 unmapnotify(XEvent *e)
359 XUnmapEvent *ev = &e->xunmap;
361 if((c = getclient(ev->window)))
367 void (*handler[LASTEvent]) (XEvent *) = {
368 [ButtonPress] = buttonpress,
369 [ConfigureRequest] = configurerequest,
370 [DestroyNotify] = destroynotify,
371 [EnterNotify] = enternotify,
372 [LeaveNotify] = leavenotify,
374 [KeyPress] = keypress,
375 [MapRequest] = maprequest,
376 [PropertyNotify] = propertynotify,
377 [UnmapNotify] = unmapnotify
383 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
387 for(i = 0; i < len; i++) {
388 code = XKeysymToKeycode(dpy, key[i].keysym);
389 XUngrabKey(dpy, code, key[i].mod, root);
390 XGrabKey(dpy, code, key[i].mod, root, True,
391 GrabModeAsync, GrabModeAsync);