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)
15 const char *browse[] = { "firefox", NULL };
16 const char *gimp[] = { "gimp", NULL };
17 const char *term[] = {
18 "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-cr", "white",
19 "-fn", "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", NULL
21 const char *xlock[] = { "xlock", NULL };
24 /* modifier key function arguments */
25 { ControlMask, XK_0, appendtag, { .i = Tscratch } },
26 { ControlMask, XK_1, appendtag, { .i = Tdev } },
27 { ControlMask, XK_2, appendtag, { .i = Twww } },
28 { ControlMask, XK_3, appendtag, { .i = Twork } },
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_j, focusnext, { 0 } },
34 { Mod1Mask, XK_k, focusprev, { 0 } },
35 { Mod1Mask, XK_m, maximize, { 0 } },
36 { Mod1Mask, XK_space, dotile, { 0 } },
37 { Mod1Mask, XK_Return, zoom, { 0 } },
38 { Mod1Mask|ShiftMask, XK_0, replacetag, { .i = Tscratch } },
39 { Mod1Mask|ShiftMask, XK_1, replacetag, { .i = Tdev } },
40 { Mod1Mask|ShiftMask, XK_2, replacetag, { .i = Twww } },
41 { Mod1Mask|ShiftMask, XK_3, replacetag, { .i = Twork } },
42 { Mod1Mask|ShiftMask, XK_c, killclient, { 0 } },
43 { Mod1Mask|ShiftMask, XK_g, spawn, { .argv = gimp } },
44 { Mod1Mask|ShiftMask, XK_l, spawn, { .argv = xlock } },
45 { Mod1Mask|ShiftMask, XK_q, quit, { 0 } },
46 { Mod1Mask|ShiftMask, XK_space, dofloat, { 0 } },
47 { Mod1Mask|ShiftMask, XK_w, spawn, { .argv = browse } },
48 { Mod1Mask|ShiftMask, XK_Return, spawn, { .argv = term } },
57 int x1, y1, ocx, ocy, di;
63 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
64 None, cursor[CurMove], CurrentTime) != GrabSuccess)
66 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
68 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
76 c->x = ocx + (ev.xmotion.x - x1);
77 c->y = ocy + (ev.xmotion.y - y1);
81 XUngrabPointer(dpy, CurrentTime);
88 resizemouse(Client *c)
95 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
96 None, cursor[CurResize], CurrentTime) != GrabSuccess)
98 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
100 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
104 handler[Expose](&ev);
108 c->w = abs(ocx - ev.xmotion.x);
109 c->h = abs(ocy - ev.xmotion.y);
110 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
111 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
115 XUngrabPointer(dpy, CurrentTime);
122 buttonpress(XEvent *e)
126 XButtonPressedEvent *ev = &e->xbutton;
129 if(barwin == ev->window) {
133 for(a.i = 0; a.i < TLast; a.i++) {
134 x += textw(tags[a.i]);
142 a.i = (tsel + 1 < TLast) ? tsel + 1 : 0;
146 a.i = (tsel - 1 >= 0) ? tsel - 1 : TLast - 1;
151 else if((c = getclient(ev->window))) {
152 if(arrange == dotile && !c->isfloat) {
153 if((ev->state & ControlMask) && (ev->button == Button1))
157 /* floating windows */
176 configurerequest(XEvent *e)
178 XConfigureRequestEvent *ev = &e->xconfigurerequest;
182 ev->value_mask &= ~CWSibling;
183 if((c = getclient(ev->window))) {
185 if(ev->value_mask & CWX)
187 if(ev->value_mask & CWY)
189 if(ev->value_mask & CWWidth)
191 if(ev->value_mask & CWHeight)
193 if(ev->value_mask & CWBorderWidth)
201 wc.width = ev->width;
202 wc.height = ev->height;
205 wc.stack_mode = Above;
206 ev->value_mask &= ~CWStackMode;
207 ev->value_mask |= CWBorderWidth;
208 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
213 destroynotify(XEvent *e)
216 XDestroyWindowEvent *ev = &e->xdestroywindow;
218 if((c = getclient(ev->window)))
223 enternotify(XEvent *e)
225 XCrossingEvent *ev = &e->xcrossing;
228 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
231 if((c = getclient(ev->window)))
233 else if(ev->window == root)
240 XExposeEvent *ev = &e->xexpose;
244 if(barwin == ev->window)
246 else if((c = getctitle(ev->window)))
254 XKeyEvent *ev = &e->xkey;
255 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
259 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
260 for(i = 0; i < len; i++)
261 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
263 key[i].func(&key[i].arg);
269 leavenotify(XEvent *e)
271 XCrossingEvent *ev = &e->xcrossing;
273 if((ev->window == root) && !ev->same_screen)
278 maprequest(XEvent *e)
280 XMapRequestEvent *ev = &e->xmaprequest;
281 static XWindowAttributes wa;
283 if(!XGetWindowAttributes(dpy, ev->window, &wa))
286 if(wa.override_redirect) {
287 XSelectInput(dpy, ev->window,
288 (StructureNotifyMask | PropertyChangeMask));
292 if(!getclient(ev->window))
293 manage(ev->window, &wa);
297 propertynotify(XEvent *e)
299 XPropertyEvent *ev = &e->xproperty;
303 if(ev->state == PropertyDelete)
306 if((c = getclient(ev->window))) {
307 if(ev->atom == wmatom[WMProtocols]) {
308 c->proto = getproto(c->win);
313 case XA_WM_TRANSIENT_FOR:
314 XGetTransientForHint(dpy, c->win, &trans);
315 if(!c->isfloat && (c->isfloat = (trans != 0)))
318 case XA_WM_NORMAL_HINTS:
322 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
330 unmapnotify(XEvent *e)
333 XUnmapEvent *ev = &e->xunmap;
335 if((c = getclient(ev->window)))
341 void (*handler[LASTEvent]) (XEvent *) = {
342 [ButtonPress] = buttonpress,
343 [ConfigureRequest] = configurerequest,
344 [DestroyNotify] = destroynotify,
345 [EnterNotify] = enternotify,
346 [LeaveNotify] = leavenotify,
348 [KeyPress] = keypress,
349 [MapRequest] = maprequest,
350 [PropertyNotify] = propertynotify,
351 [UnmapNotify] = unmapnotify
357 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
361 for(i = 0; i < len; i++) {
362 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);