dwm-meillo

annotate dev.c @ 52:d18f6dd0cf23

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