garbeam@73: /* garbeam@73: * (C)opyright MMVI Anselm R. Garbe garbeam@73: * See LICENSE file for license details. garbeam@73: */ garbeam@73: garbeam@73: #include garbeam@73: #include garbeam@73: #include garbeam@73: #include garbeam@73: #include garbeam@73: #include garbeam@73: #include garbeam@73: garbeam@73: #include "dwm.h" garbeam@73: garbeam@73: static void ckill(Arg *arg); garbeam@73: static void nextc(Arg *arg); garbeam@73: static void prevc(Arg *arg); garbeam@73: static void max(Arg *arg); garbeam@73: static void ttrunc(Arg *arg); garbeam@73: static void tappend(Arg *arg); garbeam@73: static void zoom(Arg *arg); garbeam@73: garbeam@73: /********** CUSTOMIZE **********/ garbeam@73: garbeam@73: const char *term[] = { garbeam@73: "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn", garbeam@73: "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL garbeam@73: }; garbeam@73: const char *browse[] = { "firefox", NULL }; garbeam@73: const char *xlock[] = { "xlock", NULL }; garbeam@73: garbeam@73: Key key[] = { garbeam@73: /* modifier key function arguments */ garbeam@73: { Mod1Mask, XK_Return, zoom, { 0 } }, garbeam@73: { Mod1Mask, XK_k, prevc, { 0 } }, garbeam@73: { Mod1Mask, XK_j, nextc, { 0 } }, garbeam@73: { Mod1Mask, XK_m, max, { 0 } }, garbeam@73: { Mod1Mask, XK_0, view, { .i = Tscratch } }, garbeam@73: { Mod1Mask, XK_1, view, { .i = Tdev } }, garbeam@73: { Mod1Mask, XK_2, view, { .i = Twww } }, garbeam@73: { Mod1Mask, XK_3, view, { .i = Twork } }, garbeam@73: { Mod1Mask, XK_space, tiling, { 0 } }, garbeam@73: { Mod1Mask|ShiftMask, XK_space, floating, { 0 } }, garbeam@73: { Mod1Mask|ShiftMask, XK_0, ttrunc, { .i = Tscratch } }, garbeam@73: { Mod1Mask|ShiftMask, XK_1, ttrunc, { .i = Tdev } }, garbeam@73: { Mod1Mask|ShiftMask, XK_2, ttrunc, { .i = Twww } }, garbeam@73: { Mod1Mask|ShiftMask, XK_3, ttrunc, { .i = Twork } }, garbeam@73: { Mod1Mask|ShiftMask, XK_c, ckill, { 0 } }, garbeam@73: { Mod1Mask|ShiftMask, XK_q, quit, { 0 } }, garbeam@73: { Mod1Mask|ShiftMask, XK_Return, spawn, { .argv = term } }, garbeam@73: { Mod1Mask|ShiftMask, XK_w, spawn, { .argv = browse } }, garbeam@73: { Mod1Mask|ShiftMask, XK_l, spawn, { .argv = xlock } }, garbeam@73: { ControlMask, XK_0, tappend, { .i = Tscratch } }, garbeam@73: { ControlMask, XK_1, tappend, { .i = Tdev } }, garbeam@73: { ControlMask, XK_2, tappend, { .i = Twww } }, garbeam@73: { ControlMask, XK_3, tappend, { .i = Twork } }, garbeam@73: }; garbeam@73: garbeam@73: /********** CUSTOMIZE **********/ garbeam@73: garbeam@73: void garbeam@73: grabkeys() garbeam@73: { garbeam@73: static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; garbeam@73: unsigned int i; garbeam@73: KeyCode code; garbeam@73: garbeam@73: for(i = 0; i < len; i++) { garbeam@73: code = XKeysymToKeycode(dpy, key[i].keysym); garbeam@73: XUngrabKey(dpy, code, key[i].mod, root); garbeam@73: XGrabKey(dpy, code, key[i].mod, root, True, garbeam@73: GrabModeAsync, GrabModeAsync); garbeam@73: } garbeam@73: } garbeam@73: garbeam@73: void garbeam@73: keypress(XEvent *e) garbeam@73: { garbeam@73: XKeyEvent *ev = &e->xkey; garbeam@73: static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; garbeam@73: unsigned int i; garbeam@73: KeySym keysym; garbeam@73: garbeam@73: keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); garbeam@73: for(i = 0; i < len; i++) garbeam@73: if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { garbeam@73: if(key[i].func) garbeam@73: key[i].func(&key[i].arg); garbeam@73: return; garbeam@73: } garbeam@73: } garbeam@73: garbeam@73: static void garbeam@73: zoom(Arg *arg) garbeam@73: { garbeam@73: Client **l, *c; garbeam@73: garbeam@73: if(!sel) garbeam@73: return; garbeam@73: garbeam@73: if(sel == next(clients) && sel->next) { garbeam@73: if((c = next(sel->next))) garbeam@73: sel = c; garbeam@73: } garbeam@73: garbeam@73: for(l = &clients; *l && *l != sel; l = &(*l)->next); garbeam@73: *l = sel->next; garbeam@73: garbeam@73: sel->next = clients; /* pop */ garbeam@73: clients = sel; garbeam@73: arrange(NULL); garbeam@73: focus(sel); garbeam@73: } garbeam@73: garbeam@73: static void garbeam@73: max(Arg *arg) garbeam@73: { garbeam@73: if(!sel) garbeam@73: return; garbeam@73: sel->x = sx; garbeam@73: sel->y = sy + bh; garbeam@73: sel->w = sw - 2 * sel->border; garbeam@73: sel->h = sh - 2 * sel->border - bh; garbeam@73: craise(sel); garbeam@73: resize(sel, False); garbeam@73: } garbeam@73: garbeam@73: static void garbeam@73: tappend(Arg *arg) garbeam@73: { garbeam@73: if(!sel) garbeam@73: return; garbeam@73: garbeam@73: sel->tags[arg->i] = tags[arg->i]; garbeam@73: arrange(NULL); garbeam@73: } garbeam@73: garbeam@73: static void garbeam@73: ttrunc(Arg *arg) garbeam@73: { garbeam@73: int i; garbeam@73: if(!sel) garbeam@73: return; garbeam@73: garbeam@73: for(i = 0; i < TLast; i++) garbeam@73: sel->tags[i] = NULL; garbeam@73: tappend(arg); garbeam@73: } garbeam@73: garbeam@73: static void garbeam@73: prevc(Arg *arg) garbeam@73: { garbeam@73: Client *c; garbeam@73: garbeam@73: if(!sel) garbeam@73: return; garbeam@73: garbeam@73: if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) { garbeam@73: craise(c); garbeam@73: focus(c); garbeam@73: } garbeam@73: } garbeam@73: garbeam@73: static void garbeam@73: nextc(Arg *arg) garbeam@73: { garbeam@73: Client *c; garbeam@73: garbeam@73: if(!sel) garbeam@73: return; garbeam@73: garbeam@73: if(!(c = next(sel->next))) garbeam@73: c = next(clients); garbeam@73: if(c) { garbeam@73: craise(c); garbeam@73: c->revert = sel; garbeam@73: focus(c); garbeam@73: } garbeam@73: } garbeam@73: garbeam@73: static void garbeam@73: ckill(Arg *arg) garbeam@73: { garbeam@73: if(!sel) garbeam@73: return; garbeam@73: if(sel->proto & WM_PROTOCOL_DELWIN) garbeam@73: send_message(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]); garbeam@73: else garbeam@73: XKillClient(dpy, sel->win); garbeam@73: } garbeam@73: