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 "urxvt", "-tr", "+sb", "-bg", "black", "-fg", "white", "-cr", "white",
30 "-fn", "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", NULL
32 const char *xlock[] = { "xlock", NULL };
36 /* modifier key function arguments */
37 { MODKEY, XK_0, view, { .i = Tfnord } },
38 { MODKEY, XK_1, view, { .i = Tdev } },
39 { MODKEY, XK_2, view, { .i = Tnet } },
40 { MODKEY, XK_3, view, { .i = Twork } },
41 { MODKEY, XK_4, view, { .i = Tmisc} },
42 { MODKEY, XK_j, focusnext, { 0 } },
43 { MODKEY, XK_k, focusprev, { 0 } },
44 { MODKEY, XK_m, togglemax, { 0 } },
45 { MODKEY, XK_space, togglemode, { 0 } },
46 { MODKEY, XK_Return, zoom, { 0 } },
47 { MODKEY|ControlMask, XK_0, appendtag, { .i = Tfnord } },
48 { MODKEY|ControlMask, XK_1, appendtag, { .i = Tdev } },
49 { MODKEY|ControlMask, XK_2, appendtag, { .i = Tnet } },
50 { MODKEY|ControlMask, XK_3, appendtag, { .i = Twork } },
51 { MODKEY|ControlMask, XK_4, appendtag, { .i = Tmisc } },
52 { MODKEY|ShiftMask, XK_0, replacetag, { .i = Tfnord } },
53 { MODKEY|ShiftMask, XK_1, replacetag, { .i = Tdev } },
54 { MODKEY|ShiftMask, XK_2, replacetag, { .i = Tnet } },
55 { MODKEY|ShiftMask, XK_3, replacetag, { .i = Twork } },
56 { MODKEY|ShiftMask, XK_4, replacetag, { .i = Tmisc } },
57 { MODKEY|ShiftMask, XK_c, killclient, { 0 } },
58 { MODKEY|ShiftMask, XK_q, quit, { 0 } },
59 { MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } },
61 { MODKEY|ShiftMask, XK_g, spawn, { .argv = gimp } },
62 { MODKEY|ShiftMask, XK_l, spawn, { .argv = xlock } },
63 { MODKEY|ShiftMask, XK_w, spawn, { .argv = browse } },
74 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)
150 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(!c->ismax && (arrange == dofloat || c->isfloat)) {
188 if(!c->ismax && (arrange == dofloat || c->isfloat)) {
198 configurerequest(XEvent *e)
201 XConfigureRequestEvent *ev = &e->xconfigurerequest;
204 ev->value_mask &= ~CWSibling;
205 if((c = getclient(ev->window))) {
207 if(ev->value_mask & CWX)
209 if(ev->value_mask & CWY)
211 if(ev->value_mask & CWWidth)
213 if(ev->value_mask & CWHeight)
215 if(ev->value_mask & CWBorderWidth)
218 resize(c, True, TopLeft);
223 wc.width = ev->width;
224 wc.height = ev->height;
227 wc.stack_mode = Above;
228 ev->value_mask &= ~CWStackMode;
229 ev->value_mask |= CWBorderWidth;
230 XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
235 destroynotify(XEvent *e)
238 XDestroyWindowEvent *ev = &e->xdestroywindow;
240 if((c = getclient(ev->window)))
245 enternotify(XEvent *e)
248 XCrossingEvent *ev = &e->xcrossing;
250 if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
253 if((c = getclient(ev->window)))
255 else if(ev->window == root)
263 XExposeEvent *ev = &e->xexpose;
266 if(barwin == ev->window)
268 else if((c = getctitle(ev->window)))
276 static unsigned int len = sizeof(key) / sizeof(key[0]);
279 XKeyEvent *ev = &e->xkey;
281 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
282 for(i = 0; i < len; i++)
283 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
285 key[i].func(&key[i].arg);
291 leavenotify(XEvent *e)
293 XCrossingEvent *ev = &e->xcrossing;
295 if((ev->window == root) && !ev->same_screen)
300 maprequest(XEvent *e)
302 static XWindowAttributes wa;
303 XMapRequestEvent *ev = &e->xmaprequest;
305 if(!XGetWindowAttributes(dpy, ev->window, &wa))
308 if(wa.override_redirect) {
309 XSelectInput(dpy, ev->window,
310 (StructureNotifyMask | PropertyChangeMask));
314 if(!getclient(ev->window))
315 manage(ev->window, &wa);
319 propertynotify(XEvent *e)
323 XPropertyEvent *ev = &e->xproperty;
325 if(ev->state == PropertyDelete)
328 if((c = getclient(ev->window))) {
329 if(ev->atom == wmatom[WMProtocols]) {
330 c->proto = getproto(c->win);
335 case XA_WM_TRANSIENT_FOR:
336 XGetTransientForHint(dpy, c->win, &trans);
337 if(!c->isfloat && (c->isfloat = (trans != 0)))
340 case XA_WM_NORMAL_HINTS:
344 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
352 unmapnotify(XEvent *e)
355 XUnmapEvent *ev = &e->xunmap;
357 if((c = getclient(ev->window)))
363 void (*handler[LASTEvent]) (XEvent *) = {
364 [ButtonPress] = buttonpress,
365 [ConfigureRequest] = configurerequest,
366 [DestroyNotify] = destroynotify,
367 [EnterNotify] = enternotify,
368 [LeaveNotify] = leavenotify,
370 [KeyPress] = keypress,
371 [MapRequest] = maprequest,
372 [PropertyNotify] = propertynotify,
373 [UnmapNotify] = unmapnotify
379 static unsigned int len = sizeof(key) / sizeof(key[0]);
383 for(i = 0; i < len; i++) {
384 code = XKeysymToKeycode(dpy, key[i].keysym);
385 XUngrabKey(dpy, code, key[i].mod, root);
386 XGrabKey(dpy, code, key[i].mod, root, True,
387 GrabModeAsync, GrabModeAsync);