aewl

annotate dev.c @ 49:466591c2f967

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