garbeam@8: /* garbeam@8: * (C)opyright MMVI Anselm R. Garbe garbeam@8: * See LICENSE file for license details. garbeam@8: */ garbeam@8: garbeam@43: #include "dwm.h" garbeam@8: garbeam@42: #include garbeam@42: #include garbeam@42: #include garbeam@8: #include garbeam@8: garbeam@31: /********** CUSTOMIZE **********/ garbeam@31: garbeam@33: const char *term[] = { garbeam@44: "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn", garbeam@31: "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL garbeam@14: }; garbeam@34: const char *browse[] = { "firefox", NULL }; garbeam@46: const char *xlock[] = { "xlock", NULL }; garbeam@14: garbeam@8: static Key key[] = { garbeam@49: { Mod1Mask, XK_Return, spawn, { .argv = term } }, garbeam@49: { Mod1Mask, XK_w, spawn, { .argv = browse } }, garbeam@49: { Mod1Mask, XK_l, spawn, { .argv = xlock } }, garbeam@49: { Mod1Mask, XK_k, prevc, { 0 } }, garbeam@49: { Mod1Mask, XK_j, nextc, { 0 } }, garbeam@49: { Mod1Mask, XK_t, tiling, { 0 } }, garbeam@49: { Mod1Mask, XK_f, floating, { 0 } }, garbeam@49: { Mod1Mask, XK_m, max, { 0 } }, garbeam@49: { Mod1Mask, XK_0, tag, { .i = Tscratch } }, garbeam@49: { Mod1Mask, XK_1, tag, { .i = Tdev } }, garbeam@49: { Mod1Mask, XK_2, tag, { .i = Tirc } }, garbeam@49: { Mod1Mask, XK_3, tag, { .i = Twww } }, garbeam@49: { Mod1Mask, XK_4, tag, { .i = Twork } }, garbeam@49: { Mod1Mask | ShiftMask, XK_c, ckill, { 0 } }, garbeam@49: { Mod1Mask | ShiftMask, XK_q, quit, { 0 } }, garbeam@8: }; garbeam@8: garbeam@31: /********** CUSTOMIZE **********/ garbeam@31: garbeam@8: void garbeam@33: update_keys(void) garbeam@8: { garbeam@8: unsigned int i, len; garbeam@8: KeyCode code; garbeam@8: garbeam@8: len = sizeof(key) / sizeof(key[0]); garbeam@8: for(i = 0; i < len; i++) { garbeam@8: code = XKeysymToKeycode(dpy, key[i].keysym); garbeam@8: XUngrabKey(dpy, code, key[i].mod, root); garbeam@8: XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync); garbeam@8: } garbeam@8: } garbeam@9: garbeam@9: void garbeam@9: keypress(XEvent *e) garbeam@9: { garbeam@9: XKeyEvent *ev = &e->xkey; garbeam@9: unsigned int i, len; garbeam@9: KeySym keysym; garbeam@9: garbeam@9: keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); garbeam@9: len = sizeof(key) / sizeof(key[0]); garbeam@9: for(i = 0; i < len; i++) garbeam@9: if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { garbeam@9: if(key[i].func) garbeam@49: key[i].func(&key[i].arg); garbeam@9: return; garbeam@9: } garbeam@9: } garbeam@42: garbeam@42: #define ButtonMask (ButtonPressMask | ButtonReleaseMask) garbeam@42: #define MouseMask (ButtonMask | PointerMotionMask) garbeam@42: garbeam@42: void garbeam@42: mresize(Client *c) garbeam@42: { garbeam@42: XEvent ev; garbeam@42: int ocx, ocy; garbeam@42: garbeam@42: ocx = c->x; garbeam@42: ocy = c->y; garbeam@42: if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, garbeam@42: None, cursor[CurResize], CurrentTime) != GrabSuccess) garbeam@42: return; garbeam@42: XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); garbeam@42: for(;;) { garbeam@42: XMaskEvent(dpy, MouseMask | ExposureMask, &ev); garbeam@42: switch(ev.type) { garbeam@42: default: break; garbeam@42: case Expose: garbeam@42: handler[Expose](&ev); garbeam@42: break; garbeam@42: case MotionNotify: garbeam@42: XFlush(dpy); garbeam@42: c->w = abs(ocx - ev.xmotion.x); garbeam@42: c->h = abs(ocy - ev.xmotion.y); garbeam@42: c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; garbeam@42: c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; garbeam@42: resize(c); garbeam@42: break; garbeam@42: case ButtonRelease: garbeam@42: XUngrabPointer(dpy, CurrentTime); garbeam@42: return; garbeam@42: } garbeam@42: } garbeam@42: } garbeam@42: garbeam@42: void garbeam@42: mmove(Client *c) garbeam@42: { garbeam@42: XEvent ev; garbeam@42: int x1, y1, ocx, ocy, di; garbeam@42: unsigned int dui; garbeam@42: Window dummy; garbeam@42: garbeam@42: ocx = c->x; garbeam@42: ocy = c->y; garbeam@42: if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, garbeam@42: None, cursor[CurMove], CurrentTime) != GrabSuccess) garbeam@42: return; garbeam@42: XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); garbeam@42: for(;;) { garbeam@42: XMaskEvent(dpy, MouseMask | ExposureMask, &ev); garbeam@42: switch (ev.type) { garbeam@42: default: break; garbeam@42: case Expose: garbeam@42: handler[Expose](&ev); garbeam@42: break; garbeam@42: case MotionNotify: garbeam@42: XFlush(dpy); garbeam@42: c->x = ocx + (ev.xmotion.x - x1); garbeam@42: c->y = ocy + (ev.xmotion.y - y1); garbeam@42: resize(c); garbeam@42: break; garbeam@42: case ButtonRelease: garbeam@42: XUngrabPointer(dpy, CurrentTime); garbeam@42: return; garbeam@42: } garbeam@42: } garbeam@42: }