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@33: { Mod1Mask, XK_Return, (void (*)(void *))spawn, term }, garbeam@34: { Mod1Mask, XK_w, (void (*)(void *))spawn, browse }, garbeam@46: { Mod1Mask, XK_l, (void (*)(void *))spawn, xlock }, garbeam@27: { Mod1Mask, XK_k, sel, "prev" }, garbeam@27: { Mod1Mask, XK_j, sel, "next" }, garbeam@46: { Mod1Mask, XK_t, tiling, NULL }, garbeam@48: { Mod1Mask, XK_f, floating, NULL }, garbeam@28: { Mod1Mask, XK_m, max, NULL }, garbeam@32: { Mod1Mask | ShiftMask, XK_c, ckill, NULL }, garbeam@27: { Mod1Mask | ShiftMask, XK_q, quit, NULL }, 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@14: key[i].func(key[i].aux); 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: }