dwm-meillo

annotate key.c @ 74:5370ef170cc9

sanitized names
author Anselm R. Garbe <garbeam@wmii.de>
date Fri, 14 Jul 2006 22:54:09 +0200
parents c2ddb9dbbd10
children
rev   line source
garbeam@73 1 /*
garbeam@73 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
garbeam@73 3 * See LICENSE file for license details.
garbeam@73 4 */
garbeam@73 5
garbeam@73 6 #include <fcntl.h>
garbeam@73 7 #include <stdio.h>
garbeam@73 8 #include <stdlib.h>
garbeam@73 9 #include <string.h>
garbeam@73 10 #include <unistd.h>
garbeam@73 11 #include <X11/keysym.h>
garbeam@73 12 #include <X11/Xatom.h>
garbeam@73 13
garbeam@73 14 #include "dwm.h"
garbeam@73 15
garbeam@73 16 static void ckill(Arg *arg);
garbeam@73 17 static void nextc(Arg *arg);
garbeam@73 18 static void prevc(Arg *arg);
garbeam@73 19 static void max(Arg *arg);
garbeam@73 20 static void ttrunc(Arg *arg);
garbeam@73 21 static void tappend(Arg *arg);
garbeam@73 22 static void zoom(Arg *arg);
garbeam@73 23
garbeam@73 24 /********** CUSTOMIZE **********/
garbeam@73 25
garbeam@73 26 const char *term[] = {
garbeam@73 27 "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
garbeam@73 28 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
garbeam@73 29 };
garbeam@73 30 const char *browse[] = { "firefox", NULL };
garbeam@73 31 const char *xlock[] = { "xlock", NULL };
garbeam@73 32
garbeam@73 33 Key key[] = {
garbeam@73 34 /* modifier key function arguments */
garbeam@73 35 { Mod1Mask, XK_Return, zoom, { 0 } },
garbeam@73 36 { Mod1Mask, XK_k, prevc, { 0 } },
garbeam@73 37 { Mod1Mask, XK_j, nextc, { 0 } },
garbeam@73 38 { Mod1Mask, XK_m, max, { 0 } },
garbeam@73 39 { Mod1Mask, XK_0, view, { .i = Tscratch } },
garbeam@73 40 { Mod1Mask, XK_1, view, { .i = Tdev } },
garbeam@73 41 { Mod1Mask, XK_2, view, { .i = Twww } },
garbeam@73 42 { Mod1Mask, XK_3, view, { .i = Twork } },
garbeam@73 43 { Mod1Mask, XK_space, tiling, { 0 } },
garbeam@73 44 { Mod1Mask|ShiftMask, XK_space, floating, { 0 } },
garbeam@73 45 { Mod1Mask|ShiftMask, XK_0, ttrunc, { .i = Tscratch } },
garbeam@73 46 { Mod1Mask|ShiftMask, XK_1, ttrunc, { .i = Tdev } },
garbeam@73 47 { Mod1Mask|ShiftMask, XK_2, ttrunc, { .i = Twww } },
garbeam@73 48 { Mod1Mask|ShiftMask, XK_3, ttrunc, { .i = Twork } },
garbeam@73 49 { Mod1Mask|ShiftMask, XK_c, ckill, { 0 } },
garbeam@73 50 { Mod1Mask|ShiftMask, XK_q, quit, { 0 } },
garbeam@73 51 { Mod1Mask|ShiftMask, XK_Return, spawn, { .argv = term } },
garbeam@73 52 { Mod1Mask|ShiftMask, XK_w, spawn, { .argv = browse } },
garbeam@73 53 { Mod1Mask|ShiftMask, XK_l, spawn, { .argv = xlock } },
garbeam@73 54 { ControlMask, XK_0, tappend, { .i = Tscratch } },
garbeam@73 55 { ControlMask, XK_1, tappend, { .i = Tdev } },
garbeam@73 56 { ControlMask, XK_2, tappend, { .i = Twww } },
garbeam@73 57 { ControlMask, XK_3, tappend, { .i = Twork } },
garbeam@73 58 };
garbeam@73 59
garbeam@73 60 /********** CUSTOMIZE **********/
garbeam@73 61
garbeam@73 62 void
garbeam@73 63 grabkeys()
garbeam@73 64 {
garbeam@73 65 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
garbeam@73 66 unsigned int i;
garbeam@73 67 KeyCode code;
garbeam@73 68
garbeam@73 69 for(i = 0; i < len; i++) {
garbeam@73 70 code = XKeysymToKeycode(dpy, key[i].keysym);
garbeam@73 71 XUngrabKey(dpy, code, key[i].mod, root);
garbeam@73 72 XGrabKey(dpy, code, key[i].mod, root, True,
garbeam@73 73 GrabModeAsync, GrabModeAsync);
garbeam@73 74 }
garbeam@73 75 }
garbeam@73 76
garbeam@73 77 void
garbeam@73 78 keypress(XEvent *e)
garbeam@73 79 {
garbeam@73 80 XKeyEvent *ev = &e->xkey;
garbeam@73 81 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
garbeam@73 82 unsigned int i;
garbeam@73 83 KeySym keysym;
garbeam@73 84
garbeam@73 85 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
garbeam@73 86 for(i = 0; i < len; i++)
garbeam@73 87 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
garbeam@73 88 if(key[i].func)
garbeam@73 89 key[i].func(&key[i].arg);
garbeam@73 90 return;
garbeam@73 91 }
garbeam@73 92 }
garbeam@73 93
garbeam@73 94 static void
garbeam@73 95 zoom(Arg *arg)
garbeam@73 96 {
garbeam@73 97 Client **l, *c;
garbeam@73 98
garbeam@73 99 if(!sel)
garbeam@73 100 return;
garbeam@73 101
garbeam@74 102 if(sel == getnext(clients) && sel->next) {
garbeam@74 103 if((c = getnext(sel->next)))
garbeam@73 104 sel = c;
garbeam@73 105 }
garbeam@73 106
garbeam@73 107 for(l = &clients; *l && *l != sel; l = &(*l)->next);
garbeam@73 108 *l = sel->next;
garbeam@73 109
garbeam@73 110 sel->next = clients; /* pop */
garbeam@73 111 clients = sel;
garbeam@73 112 arrange(NULL);
garbeam@73 113 focus(sel);
garbeam@73 114 }
garbeam@73 115
garbeam@73 116 static void
garbeam@73 117 max(Arg *arg)
garbeam@73 118 {
garbeam@73 119 if(!sel)
garbeam@73 120 return;
garbeam@73 121 sel->x = sx;
garbeam@73 122 sel->y = sy + bh;
garbeam@73 123 sel->w = sw - 2 * sel->border;
garbeam@73 124 sel->h = sh - 2 * sel->border - bh;
garbeam@74 125 higher(sel);
garbeam@73 126 resize(sel, False);
garbeam@73 127 }
garbeam@73 128
garbeam@73 129 static void
garbeam@73 130 tappend(Arg *arg)
garbeam@73 131 {
garbeam@73 132 if(!sel)
garbeam@73 133 return;
garbeam@73 134
garbeam@73 135 sel->tags[arg->i] = tags[arg->i];
garbeam@73 136 arrange(NULL);
garbeam@73 137 }
garbeam@73 138
garbeam@73 139 static void
garbeam@73 140 ttrunc(Arg *arg)
garbeam@73 141 {
garbeam@73 142 int i;
garbeam@73 143 if(!sel)
garbeam@73 144 return;
garbeam@73 145
garbeam@73 146 for(i = 0; i < TLast; i++)
garbeam@73 147 sel->tags[i] = NULL;
garbeam@73 148 tappend(arg);
garbeam@73 149 }
garbeam@73 150
garbeam@73 151 static void
garbeam@73 152 prevc(Arg *arg)
garbeam@73 153 {
garbeam@73 154 Client *c;
garbeam@73 155
garbeam@73 156 if(!sel)
garbeam@73 157 return;
garbeam@73 158
garbeam@73 159 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
garbeam@74 160 higher(c);
garbeam@73 161 focus(c);
garbeam@73 162 }
garbeam@73 163 }
garbeam@73 164
garbeam@73 165 static void
garbeam@73 166 nextc(Arg *arg)
garbeam@73 167 {
garbeam@73 168 Client *c;
garbeam@73 169
garbeam@73 170 if(!sel)
garbeam@73 171 return;
garbeam@73 172
garbeam@74 173 if(!(c = getnext(sel->next)))
garbeam@74 174 c = getnext(clients);
garbeam@73 175 if(c) {
garbeam@74 176 higher(c);
garbeam@73 177 c->revert = sel;
garbeam@73 178 focus(c);
garbeam@73 179 }
garbeam@73 180 }
garbeam@73 181
garbeam@73 182 static void
garbeam@73 183 ckill(Arg *arg)
garbeam@73 184 {
garbeam@73 185 if(!sel)
garbeam@73 186 return;
garbeam@73 187 if(sel->proto & WM_PROTOCOL_DELWIN)
garbeam@74 188 sendevent(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
garbeam@73 189 else
garbeam@73 190 XKillClient(dpy, sel->win);
garbeam@73 191 }
garbeam@73 192