dwm-meillo

annotate dev.c @ 68:d31b5ad96b0b

prep 0.1
author Anselm R. Garbe <garbeam@wmii.de>
date Fri, 14 Jul 2006 18:40:31 +0200
parents 529901e6a227
children
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@46 20 const char *xlock[] = { "xlock", NULL };
garbeam@14 21
garbeam@8 22 static Key key[] = {
garbeam@53 23 /* modifier key function arguments */
garbeam@53 24 { Mod1Mask, XK_Return, zoom, { 0 } },
garbeam@53 25 { Mod1Mask, XK_k, prevc, { 0 } },
garbeam@53 26 { Mod1Mask, XK_j, nextc, { 0 } },
garbeam@53 27 { Mod1Mask, XK_m, max, { 0 } },
garbeam@53 28 { Mod1Mask, XK_0, view, { .i = Tscratch } },
garbeam@53 29 { Mod1Mask, XK_1, view, { .i = Tdev } },
garbeam@59 30 { Mod1Mask, XK_2, view, { .i = Twww } },
garbeam@59 31 { Mod1Mask, XK_3, view, { .i = Twork } },
garbeam@53 32 { Mod1Mask, XK_space, tiling, { 0 } },
garbeam@53 33 { Mod1Mask|ShiftMask, XK_space, floating, { 0 } },
garbeam@53 34 { Mod1Mask|ShiftMask, XK_0, ttrunc, { .i = Tscratch } },
garbeam@53 35 { Mod1Mask|ShiftMask, XK_1, ttrunc, { .i = Tdev } },
garbeam@59 36 { Mod1Mask|ShiftMask, XK_2, ttrunc, { .i = Twww } },
garbeam@59 37 { Mod1Mask|ShiftMask, XK_3, ttrunc, { .i = Twork } },
garbeam@53 38 { Mod1Mask|ShiftMask, XK_c, ckill, { 0 } },
garbeam@53 39 { Mod1Mask|ShiftMask, XK_q, quit, { 0 } },
garbeam@53 40 { Mod1Mask|ShiftMask, XK_Return, spawn, { .argv = term } },
garbeam@53 41 { Mod1Mask|ShiftMask, XK_w, spawn, { .argv = browse } },
garbeam@53 42 { Mod1Mask|ShiftMask, XK_l, spawn, { .argv = xlock } },
garbeam@53 43 { ControlMask, XK_0, tappend, { .i = Tscratch } },
garbeam@53 44 { ControlMask, XK_1, tappend, { .i = Tdev } },
garbeam@59 45 { ControlMask, XK_2, tappend, { .i = Twww } },
garbeam@59 46 { ControlMask, XK_3, tappend, { .i = Twork } },
garbeam@8 47 };
garbeam@8 48
garbeam@31 49 /********** CUSTOMIZE **********/
garbeam@31 50
garbeam@8 51 void
garbeam@33 52 update_keys(void)
garbeam@8 53 {
garbeam@51 54 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
garbeam@51 55 unsigned int i;
garbeam@8 56 KeyCode code;
garbeam@8 57
garbeam@8 58 for(i = 0; i < len; i++) {
garbeam@8 59 code = XKeysymToKeycode(dpy, key[i].keysym);
garbeam@8 60 XUngrabKey(dpy, code, key[i].mod, root);
garbeam@8 61 XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
garbeam@8 62 }
garbeam@8 63 }
garbeam@9 64
garbeam@9 65 void
garbeam@9 66 keypress(XEvent *e)
garbeam@9 67 {
garbeam@9 68 XKeyEvent *ev = &e->xkey;
garbeam@51 69 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
garbeam@51 70 unsigned int i;
garbeam@9 71 KeySym keysym;
garbeam@9 72
garbeam@9 73 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
garbeam@9 74 for(i = 0; i < len; i++)
garbeam@9 75 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
garbeam@9 76 if(key[i].func)
garbeam@49 77 key[i].func(&key[i].arg);
garbeam@9 78 return;
garbeam@9 79 }
garbeam@9 80 }
garbeam@42 81
garbeam@42 82 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
garbeam@42 83 #define MouseMask (ButtonMask | PointerMotionMask)
garbeam@42 84
garbeam@42 85 void
garbeam@42 86 mresize(Client *c)
garbeam@42 87 {
garbeam@42 88 XEvent ev;
garbeam@42 89 int ocx, ocy;
garbeam@42 90
garbeam@42 91 ocx = c->x;
garbeam@42 92 ocy = c->y;
garbeam@42 93 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
garbeam@42 94 None, cursor[CurResize], CurrentTime) != GrabSuccess)
garbeam@42 95 return;
garbeam@42 96 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
garbeam@42 97 for(;;) {
garbeam@42 98 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
garbeam@42 99 switch(ev.type) {
garbeam@42 100 default: break;
garbeam@42 101 case Expose:
garbeam@42 102 handler[Expose](&ev);
garbeam@42 103 break;
garbeam@42 104 case MotionNotify:
garbeam@42 105 XFlush(dpy);
garbeam@42 106 c->w = abs(ocx - ev.xmotion.x);
garbeam@42 107 c->h = abs(ocy - ev.xmotion.y);
garbeam@42 108 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
garbeam@42 109 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
garbeam@52 110 resize(c, True);
garbeam@42 111 break;
garbeam@42 112 case ButtonRelease:
garbeam@42 113 XUngrabPointer(dpy, CurrentTime);
garbeam@42 114 return;
garbeam@42 115 }
garbeam@42 116 }
garbeam@42 117 }
garbeam@42 118
garbeam@42 119 void
garbeam@42 120 mmove(Client *c)
garbeam@42 121 {
garbeam@42 122 XEvent ev;
garbeam@42 123 int x1, y1, ocx, ocy, di;
garbeam@42 124 unsigned int dui;
garbeam@42 125 Window dummy;
garbeam@42 126
garbeam@42 127 ocx = c->x;
garbeam@42 128 ocy = c->y;
garbeam@42 129 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
garbeam@42 130 None, cursor[CurMove], CurrentTime) != GrabSuccess)
garbeam@42 131 return;
garbeam@42 132 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
garbeam@42 133 for(;;) {
garbeam@42 134 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
garbeam@42 135 switch (ev.type) {
garbeam@42 136 default: break;
garbeam@42 137 case Expose:
garbeam@42 138 handler[Expose](&ev);
garbeam@42 139 break;
garbeam@42 140 case MotionNotify:
garbeam@42 141 XFlush(dpy);
garbeam@42 142 c->x = ocx + (ev.xmotion.x - x1);
garbeam@42 143 c->y = ocy + (ev.xmotion.y - y1);
garbeam@52 144 resize(c, False);
garbeam@42 145 break;
garbeam@42 146 case ButtonRelease:
garbeam@42 147 XUngrabPointer(dpy, CurrentTime);
garbeam@42 148 return;
garbeam@42 149 }
garbeam@42 150 }
garbeam@42 151 }