aewl

annotate dev.c @ 45:7943c72e34eb

added pointer warps on kb-driven/manage-driven focus
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 12:00:20 +0200
parents 989178822938
children 58307ad56ec1
rev   line source
garbeam@8 1 /*
garbeam@8 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
garbeam@8 3 * See LICENSE file for license details.
garbeam@8 4 */
garbeam@8 5
garbeam@43 6 #include "dwm.h"
garbeam@8 7
garbeam@42 8 #include <stdlib.h>
garbeam@42 9 #include <string.h>
garbeam@42 10 #include <unistd.h>
garbeam@8 11 #include <X11/keysym.h>
garbeam@8 12
garbeam@31 13 /********** CUSTOMIZE **********/
garbeam@31 14
garbeam@33 15 const char *term[] = {
garbeam@44 16 "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
garbeam@31 17 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
garbeam@14 18 };
garbeam@34 19 const char *browse[] = { "firefox", NULL };
garbeam@14 20
garbeam@8 21 static Key key[] = {
garbeam@33 22 { Mod1Mask, XK_Return, (void (*)(void *))spawn, term },
garbeam@34 23 { Mod1Mask, XK_w, (void (*)(void *))spawn, browse },
garbeam@27 24 { Mod1Mask, XK_k, sel, "prev" },
garbeam@27 25 { Mod1Mask, XK_j, sel, "next" },
garbeam@34 26 { Mod1Mask, XK_space, toggle, NULL },
garbeam@28 27 { Mod1Mask, XK_m, max, NULL },
garbeam@32 28 { Mod1Mask | ShiftMask, XK_c, ckill, NULL },
garbeam@27 29 { Mod1Mask | ShiftMask, XK_q, quit, NULL },
garbeam@8 30 };
garbeam@8 31
garbeam@31 32 /********** CUSTOMIZE **********/
garbeam@31 33
garbeam@8 34 void
garbeam@33 35 update_keys(void)
garbeam@8 36 {
garbeam@8 37 unsigned int i, len;
garbeam@8 38 KeyCode code;
garbeam@8 39
garbeam@8 40 len = sizeof(key) / sizeof(key[0]);
garbeam@8 41 for(i = 0; i < len; i++) {
garbeam@8 42 code = XKeysymToKeycode(dpy, key[i].keysym);
garbeam@8 43 XUngrabKey(dpy, code, key[i].mod, root);
garbeam@8 44 XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
garbeam@8 45 }
garbeam@8 46 }
garbeam@9 47
garbeam@9 48 void
garbeam@9 49 keypress(XEvent *e)
garbeam@9 50 {
garbeam@9 51 XKeyEvent *ev = &e->xkey;
garbeam@9 52 unsigned int i, len;
garbeam@9 53 KeySym keysym;
garbeam@9 54
garbeam@9 55 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
garbeam@9 56 len = sizeof(key) / sizeof(key[0]);
garbeam@9 57 for(i = 0; i < len; i++)
garbeam@9 58 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
garbeam@9 59 if(key[i].func)
garbeam@14 60 key[i].func(key[i].aux);
garbeam@9 61 return;
garbeam@9 62 }
garbeam@9 63 }
garbeam@42 64
garbeam@42 65 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
garbeam@42 66 #define MouseMask (ButtonMask | PointerMotionMask)
garbeam@42 67
garbeam@42 68 void
garbeam@42 69 mresize(Client *c)
garbeam@42 70 {
garbeam@42 71 XEvent ev;
garbeam@42 72 int ocx, ocy;
garbeam@42 73
garbeam@42 74 ocx = c->x;
garbeam@42 75 ocy = c->y;
garbeam@42 76 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
garbeam@42 77 None, cursor[CurResize], CurrentTime) != GrabSuccess)
garbeam@42 78 return;
garbeam@42 79 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
garbeam@42 80 for(;;) {
garbeam@42 81 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
garbeam@42 82 switch(ev.type) {
garbeam@42 83 default: break;
garbeam@42 84 case Expose:
garbeam@42 85 handler[Expose](&ev);
garbeam@42 86 break;
garbeam@42 87 case MotionNotify:
garbeam@42 88 XFlush(dpy);
garbeam@42 89 c->w = abs(ocx - ev.xmotion.x);
garbeam@42 90 c->h = abs(ocy - ev.xmotion.y);
garbeam@42 91 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
garbeam@42 92 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
garbeam@42 93 resize(c);
garbeam@42 94 break;
garbeam@42 95 case ButtonRelease:
garbeam@42 96 XUngrabPointer(dpy, CurrentTime);
garbeam@42 97 return;
garbeam@42 98 }
garbeam@42 99 }
garbeam@42 100 }
garbeam@42 101
garbeam@42 102 void
garbeam@42 103 mmove(Client *c)
garbeam@42 104 {
garbeam@42 105 XEvent ev;
garbeam@42 106 int x1, y1, ocx, ocy, di;
garbeam@42 107 unsigned int dui;
garbeam@42 108 Window dummy;
garbeam@42 109
garbeam@42 110 ocx = c->x;
garbeam@42 111 ocy = c->y;
garbeam@42 112 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
garbeam@42 113 None, cursor[CurMove], CurrentTime) != GrabSuccess)
garbeam@42 114 return;
garbeam@42 115 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
garbeam@42 116 for(;;) {
garbeam@42 117 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
garbeam@42 118 switch (ev.type) {
garbeam@42 119 default: break;
garbeam@42 120 case Expose:
garbeam@42 121 handler[Expose](&ev);
garbeam@42 122 break;
garbeam@42 123 case MotionNotify:
garbeam@42 124 XFlush(dpy);
garbeam@42 125 c->x = ocx + (ev.xmotion.x - x1);
garbeam@42 126 c->y = ocy + (ev.xmotion.y - y1);
garbeam@42 127 resize(c);
garbeam@42 128 break;
garbeam@42 129 case ButtonRelease:
garbeam@42 130 XUngrabPointer(dpy, CurrentTime);
garbeam@42 131 return;
garbeam@42 132 }
garbeam@42 133 }
garbeam@42 134 }