dwm-meillo

annotate dev.c @ 55:fcbf7213d96f

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