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)
14 /********** CUSTOMIZE **********/
16 const char *term[] = {
17 "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-cr", "white",
18 "-fn", "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", NULL
20 const char *browse[] = { "firefox", NULL };
21 const char *xlock[] = { "xlock", NULL };
24 /* modifier key function arguments */
25 { Mod1Mask, XK_Return, zoom, { 0 } },
26 { Mod1Mask, XK_k, focusprev, { 0 } },
27 { Mod1Mask, XK_j, focusnext, { 0 } },
28 { Mod1Mask, XK_m, maximize, { 0 } },
29 { Mod1Mask, XK_0, view, { .i = Tscratch } },
30 { Mod1Mask, XK_1, view, { .i = Tdev } },
31 { Mod1Mask, XK_2, view, { .i = Twww } },
32 { Mod1Mask, XK_3, view, { .i = Twork } },
33 { Mod1Mask, XK_space, dotile, { 0 } },
34 { Mod1Mask|ShiftMask, XK_space, dofloat, { 0 } },
35 { Mod1Mask|ShiftMask, XK_0, replacetag, { .i = Tscratch } },
36 { Mod1Mask|ShiftMask, XK_1, replacetag, { .i = Tdev } },
37 { Mod1Mask|ShiftMask, XK_2, replacetag, { .i = Twww } },
38 { Mod1Mask|ShiftMask, XK_3, replacetag, { .i = Twork } },
39 { Mod1Mask|ShiftMask, XK_c, killclient, { 0 } },
40 { Mod1Mask|ShiftMask, XK_q, quit, { 0 } },
41 { Mod1Mask|ShiftMask, XK_Return, spawn, { .argv = term } },
42 { Mod1Mask|ShiftMask, XK_w, spawn, { .argv = browse } },
43 { Mod1Mask|ShiftMask, XK_l, spawn, { .argv = xlock } },
44 { ControlMask, XK_0, appendtag, { .i = Tscratch } },
45 { ControlMask, XK_1, appendtag, { .i = Tdev } },
46 { ControlMask, XK_2, appendtag, { .i = Twww } },
47 { ControlMask, XK_3, appendtag, { .i = Twork } },
50 /********** CUSTOMIZE **********/
52 /* static functions */
58 int x1, y1, ocx, ocy, di;
64 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
65 None, cursor[CurMove], CurrentTime) != GrabSuccess)
67 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
69 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
77 c->x = ocx + (ev.xmotion.x - x1);
78 c->y = ocy + (ev.xmotion.y - y1);
82 XUngrabPointer(dpy, CurrentTime);
89 resizemouse(Client *c)
96 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
97 None, cursor[CurResize], CurrentTime) != GrabSuccess)
99 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
101 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
105 handler[Expose](&ev);
109 c->w = abs(ocx - ev.xmotion.x);
110 c->h = abs(ocy - ev.xmotion.y);
111 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
112 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
116 XUngrabPointer(dpy, CurrentTime);
123 buttonpress(XEvent *e)
127 XButtonPressedEvent *ev = &e->xbutton;
130 if(barwin == ev->window) {
134 for(a.i = 0; a.i < TLast; a.i++) {
135 x += textw(tags[a.i]);
143 a.i = (tsel + 1 < TLast) ? tsel + 1 : 0;
147 a.i = (tsel - 1 >= 0) ? tsel - 1 : TLast - 1;
152 else if((c = getclient(ev->window))) {
153 if(arrange == dotile && !c->isfloat) {
154 if((ev->state & ControlMask) && (ev->button == Button1))
158 /* floating windows */
177 configurerequest(XEvent *e)
179 XConfigureRequestEvent *ev = &e->xconfigurerequest;
183 ev->value_mask &= ~CWSibling;
184 if((c = getclient(ev->window))) {
186 if(ev->value_mask & CWX)
188 if(ev->value_mask & CWY)
190 if(ev->value_mask & CWWidth)
192 if(ev->value_mask & CWHeight)
194 if(ev->value_mask & CWBorderWidth)
202 wc.width = ev->width;
203 wc.height = ev->height;
206 wc.stack_mode = Above;
207 ev->value_mask &= ~CWStackMode;
208 ev->value_mask |= CWBorderWidth;
209 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
214 destroynotify(XEvent *e)
217 XDestroyWindowEvent *ev = &e->xdestroywindow;
219 if((c = getclient(ev->window)))
224 enternotify(XEvent *e)
226 XCrossingEvent *ev = &e->xcrossing;
229 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
232 if((c = getclient(ev->window)))
234 else if(ev->window == root)
241 XExposeEvent *ev = &e->xexpose;
245 if(barwin == ev->window)
247 else if((c = getctitle(ev->window)))
255 XKeyEvent *ev = &e->xkey;
256 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
260 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
261 for(i = 0; i < len; i++)
262 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
264 key[i].func(&key[i].arg);
270 leavenotify(XEvent *e)
272 XCrossingEvent *ev = &e->xcrossing;
274 if((ev->window == root) && !ev->same_screen)
279 maprequest(XEvent *e)
281 XMapRequestEvent *ev = &e->xmaprequest;
282 static XWindowAttributes wa;
284 if(!XGetWindowAttributes(dpy, ev->window, &wa))
287 if(wa.override_redirect) {
288 XSelectInput(dpy, ev->window,
289 (StructureNotifyMask | PropertyChangeMask));
293 if(!getclient(ev->window))
294 manage(ev->window, &wa);
298 propertynotify(XEvent *e)
300 XPropertyEvent *ev = &e->xproperty;
304 if(ev->state == PropertyDelete)
307 if((c = getclient(ev->window))) {
308 if(ev->atom == wmatom[WMProtocols]) {
309 c->proto = getproto(c->win);
314 case XA_WM_TRANSIENT_FOR:
315 XGetTransientForHint(dpy, c->win, &trans);
316 if(!c->isfloat && (c->isfloat = (trans != 0)))
319 case XA_WM_NORMAL_HINTS:
323 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
331 unmapnotify(XEvent *e)
334 XUnmapEvent *ev = &e->xunmap;
336 if((c = getclient(ev->window)))
340 /* extern functions */
342 void (*handler[LASTEvent]) (XEvent *) = {
343 [ButtonPress] = buttonpress,
344 [ConfigureRequest] = configurerequest,
345 [DestroyNotify] = destroynotify,
346 [EnterNotify] = enternotify,
347 [LeaveNotify] = leavenotify,
349 [KeyPress] = keypress,
350 [MapRequest] = maprequest,
351 [PropertyNotify] = propertynotify,
352 [UnmapNotify] = unmapnotify
358 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
362 for(i = 0; i < len; i++) {
363 code = XKeysymToKeycode(dpy, key[i].keysym);
364 XUngrabKey(dpy, code, key[i].mod, root);
365 XGrabKey(dpy, code, key[i].mod, root, True,
366 GrabModeAsync, GrabModeAsync);