aewl
diff key.c @ 73:c2ddb9dbbd10
rearranged
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Fri, 14 Jul 2006 22:33:38 +0200 |
parents | |
children | 5370ef170cc9 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/key.c Fri Jul 14 22:33:38 2006 +0200 1.3 @@ -0,0 +1,192 @@ 1.4 +/* 1.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> 1.6 + * See LICENSE file for license details. 1.7 + */ 1.8 + 1.9 +#include <fcntl.h> 1.10 +#include <stdio.h> 1.11 +#include <stdlib.h> 1.12 +#include <string.h> 1.13 +#include <unistd.h> 1.14 +#include <X11/keysym.h> 1.15 +#include <X11/Xatom.h> 1.16 + 1.17 +#include "dwm.h" 1.18 + 1.19 +static void ckill(Arg *arg); 1.20 +static void nextc(Arg *arg); 1.21 +static void prevc(Arg *arg); 1.22 +static void max(Arg *arg); 1.23 +static void ttrunc(Arg *arg); 1.24 +static void tappend(Arg *arg); 1.25 +static void zoom(Arg *arg); 1.26 + 1.27 +/********** CUSTOMIZE **********/ 1.28 + 1.29 +const char *term[] = { 1.30 + "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn", 1.31 + "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL 1.32 +}; 1.33 +const char *browse[] = { "firefox", NULL }; 1.34 +const char *xlock[] = { "xlock", NULL }; 1.35 + 1.36 +Key key[] = { 1.37 + /* modifier key function arguments */ 1.38 + { Mod1Mask, XK_Return, zoom, { 0 } }, 1.39 + { Mod1Mask, XK_k, prevc, { 0 } }, 1.40 + { Mod1Mask, XK_j, nextc, { 0 } }, 1.41 + { Mod1Mask, XK_m, max, { 0 } }, 1.42 + { Mod1Mask, XK_0, view, { .i = Tscratch } }, 1.43 + { Mod1Mask, XK_1, view, { .i = Tdev } }, 1.44 + { Mod1Mask, XK_2, view, { .i = Twww } }, 1.45 + { Mod1Mask, XK_3, view, { .i = Twork } }, 1.46 + { Mod1Mask, XK_space, tiling, { 0 } }, 1.47 + { Mod1Mask|ShiftMask, XK_space, floating, { 0 } }, 1.48 + { Mod1Mask|ShiftMask, XK_0, ttrunc, { .i = Tscratch } }, 1.49 + { Mod1Mask|ShiftMask, XK_1, ttrunc, { .i = Tdev } }, 1.50 + { Mod1Mask|ShiftMask, XK_2, ttrunc, { .i = Twww } }, 1.51 + { Mod1Mask|ShiftMask, XK_3, ttrunc, { .i = Twork } }, 1.52 + { Mod1Mask|ShiftMask, XK_c, ckill, { 0 } }, 1.53 + { Mod1Mask|ShiftMask, XK_q, quit, { 0 } }, 1.54 + { Mod1Mask|ShiftMask, XK_Return, spawn, { .argv = term } }, 1.55 + { Mod1Mask|ShiftMask, XK_w, spawn, { .argv = browse } }, 1.56 + { Mod1Mask|ShiftMask, XK_l, spawn, { .argv = xlock } }, 1.57 + { ControlMask, XK_0, tappend, { .i = Tscratch } }, 1.58 + { ControlMask, XK_1, tappend, { .i = Tdev } }, 1.59 + { ControlMask, XK_2, tappend, { .i = Twww } }, 1.60 + { ControlMask, XK_3, tappend, { .i = Twork } }, 1.61 +}; 1.62 + 1.63 +/********** CUSTOMIZE **********/ 1.64 + 1.65 +void 1.66 +grabkeys() 1.67 +{ 1.68 + static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; 1.69 + unsigned int i; 1.70 + KeyCode code; 1.71 + 1.72 + for(i = 0; i < len; i++) { 1.73 + code = XKeysymToKeycode(dpy, key[i].keysym); 1.74 + XUngrabKey(dpy, code, key[i].mod, root); 1.75 + XGrabKey(dpy, code, key[i].mod, root, True, 1.76 + GrabModeAsync, GrabModeAsync); 1.77 + } 1.78 +} 1.79 + 1.80 +void 1.81 +keypress(XEvent *e) 1.82 +{ 1.83 + XKeyEvent *ev = &e->xkey; 1.84 + static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; 1.85 + unsigned int i; 1.86 + KeySym keysym; 1.87 + 1.88 + keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); 1.89 + for(i = 0; i < len; i++) 1.90 + if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { 1.91 + if(key[i].func) 1.92 + key[i].func(&key[i].arg); 1.93 + return; 1.94 + } 1.95 +} 1.96 + 1.97 +static void 1.98 +zoom(Arg *arg) 1.99 +{ 1.100 + Client **l, *c; 1.101 + 1.102 + if(!sel) 1.103 + return; 1.104 + 1.105 + if(sel == next(clients) && sel->next) { 1.106 + if((c = next(sel->next))) 1.107 + sel = c; 1.108 + } 1.109 + 1.110 + for(l = &clients; *l && *l != sel; l = &(*l)->next); 1.111 + *l = sel->next; 1.112 + 1.113 + sel->next = clients; /* pop */ 1.114 + clients = sel; 1.115 + arrange(NULL); 1.116 + focus(sel); 1.117 +} 1.118 + 1.119 +static void 1.120 +max(Arg *arg) 1.121 +{ 1.122 + if(!sel) 1.123 + return; 1.124 + sel->x = sx; 1.125 + sel->y = sy + bh; 1.126 + sel->w = sw - 2 * sel->border; 1.127 + sel->h = sh - 2 * sel->border - bh; 1.128 + craise(sel); 1.129 + resize(sel, False); 1.130 +} 1.131 + 1.132 +static void 1.133 +tappend(Arg *arg) 1.134 +{ 1.135 + if(!sel) 1.136 + return; 1.137 + 1.138 + sel->tags[arg->i] = tags[arg->i]; 1.139 + arrange(NULL); 1.140 +} 1.141 + 1.142 +static void 1.143 +ttrunc(Arg *arg) 1.144 +{ 1.145 + int i; 1.146 + if(!sel) 1.147 + return; 1.148 + 1.149 + for(i = 0; i < TLast; i++) 1.150 + sel->tags[i] = NULL; 1.151 + tappend(arg); 1.152 +} 1.153 + 1.154 +static void 1.155 +prevc(Arg *arg) 1.156 +{ 1.157 + Client *c; 1.158 + 1.159 + if(!sel) 1.160 + return; 1.161 + 1.162 + if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) { 1.163 + craise(c); 1.164 + focus(c); 1.165 + } 1.166 +} 1.167 + 1.168 +static void 1.169 +nextc(Arg *arg) 1.170 +{ 1.171 + Client *c; 1.172 + 1.173 + if(!sel) 1.174 + return; 1.175 + 1.176 + if(!(c = next(sel->next))) 1.177 + c = next(clients); 1.178 + if(c) { 1.179 + craise(c); 1.180 + c->revert = sel; 1.181 + focus(c); 1.182 + } 1.183 +} 1.184 + 1.185 +static void 1.186 +ckill(Arg *arg) 1.187 +{ 1.188 + if(!sel) 1.189 + return; 1.190 + if(sel->proto & WM_PROTOCOL_DELWIN) 1.191 + send_message(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]); 1.192 + else 1.193 + XKillClient(dpy, sel->win); 1.194 +} 1.195 +