-/* local functions */
-static void buttonpress(XEvent *e);
-static void configurerequest(XEvent *e);
-static void destroynotify(XEvent *e);
-static void enternotify(XEvent *e);
-static void leavenotify(XEvent *e);
-static void expose(XEvent *e);
-static void keypress(XEvent *e);
-static void maprequest(XEvent *e);
-static void propertynotify(XEvent *e);
-static void unmapnotify(XEvent *e);
-
-void (*handler[LASTEvent]) (XEvent *) = {
- [ButtonPress] = buttonpress,
- [ConfigureRequest] = configurerequest,
- [DestroyNotify] = destroynotify,
- [EnterNotify] = enternotify,
- [LeaveNotify] = leavenotify,
- [Expose] = expose,
- [KeyPress] = keypress,
- [MapRequest] = maprequest,
- [PropertyNotify] = propertynotify,
- [UnmapNotify] = unmapnotify
-};
-
-void
-grabkeys()
-{
- static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
- unsigned int i;
- KeyCode code;
-
- for(i = 0; i < len; i++) {
- code = XKeysymToKeycode(dpy, key[i].keysym);
- XUngrabKey(dpy, code, key[i].mod, root);
- XGrabKey(dpy, code, key[i].mod, root, True,
- GrabModeAsync, GrabModeAsync);
- }
-}
-
-static void
-keypress(XEvent *e)
-{
- XKeyEvent *ev = &e->xkey;
- static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
- unsigned int i;
- KeySym keysym;
-
- keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
- for(i = 0; i < len; i++)
- if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
- if(key[i].func)
- key[i].func(&key[i].arg);
- return;
- }
-}
-
-static void
-resizemouse(Client *c)
-{
- XEvent ev;
- int ocx, ocy;
-
- ocx = c->x;
- ocy = c->y;
- if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
- None, cursor[CurResize], CurrentTime) != GrabSuccess)
- return;
- XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
- for(;;) {
- XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
- switch(ev.type) {
- default: break;
- case Expose:
- handler[Expose](&ev);
- break;
- case MotionNotify:
- XFlush(dpy);
- c->w = abs(ocx - ev.xmotion.x);
- c->h = abs(ocy - ev.xmotion.y);
- c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
- c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
- resize(c, True);
- break;
- case ButtonRelease:
- XUngrabPointer(dpy, CurrentTime);
- return;
- }
- }
-}
-
-static void
-movemouse(Client *c)
-{
- XEvent ev;
- int x1, y1, ocx, ocy, di;
- unsigned int dui;
- Window dummy;