aewl
changeset 8:7066ff2fe8bc
added key handling
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Tue, 11 Jul 2006 11:50:18 +0200 |
parents | 49e2fc9fb94f |
children | d567f430a81d |
files | Makefile config.h key.c wm.c wm.h |
diffstat | 5 files changed, 44 insertions(+), 30 deletions(-) [+] |
line diff
1.1 --- a/Makefile Tue Jul 11 11:27:56 2006 +0200 1.2 +++ b/Makefile Tue Jul 11 11:50:18 2006 +0200 1.3 @@ -3,7 +3,7 @@ 1.4 1.5 include config.mk 1.6 1.7 -WMSRC = bar.c client.c draw.c event.c util.c wm.c 1.8 +WMSRC = bar.c client.c cmd.c draw.c event.c key.c util.c wm.c 1.9 WMOBJ = ${WMSRC:.c=.o} 1.10 MENSRC = menu.c draw.c util.c 1.11 MENOBJ = ${MENSRC:.c=.o}
2.1 --- a/config.h Tue Jul 11 11:27:56 2006 +0200 2.2 +++ b/config.h Tue Jul 11 11:50:18 2006 +0200 2.3 @@ -9,3 +9,5 @@ 2.4 #define BORDERCOLOR "#000000" 2.5 #define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \ 2.6 " `acpi | awk '{print $4}' | sed 's/,//'`" 2.7 +#define KEYS \ 2.8 + { Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn -*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*" },
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/key.c Tue Jul 11 11:50:18 2006 +0200 3.3 @@ -0,0 +1,26 @@ 3.4 +/* 3.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> 3.6 + * See LICENSE file for license details. 3.7 + */ 3.8 + 3.9 +#include "wm.h" 3.10 + 3.11 +#include <X11/keysym.h> 3.12 + 3.13 +static Key key[] = { 3.14 + KEYS 3.15 +}; 3.16 + 3.17 +void 3.18 +update_keys() 3.19 +{ 3.20 + unsigned int i, len; 3.21 + KeyCode code; 3.22 + 3.23 + len = sizeof(key) / sizeof(key[0]); 3.24 + for(i = 0; i < len; i++) { 3.25 + code = XKeysymToKeycode(dpy, key[i].keysym); 3.26 + XUngrabKey(dpy, code, key[i].mod, root); 3.27 + XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync); 3.28 + } 3.29 +}
4.1 --- a/wm.c Tue Jul 11 11:27:56 2006 +0200 4.2 +++ b/wm.c Tue Jul 11 11:50:18 2006 +0200 4.3 @@ -24,7 +24,6 @@ 4.4 4.5 char *bartext, tag[256]; 4.6 int screen, sel_screen; 4.7 -unsigned int lock_mask, numlock_mask; 4.8 4.9 /* draw structs */ 4.10 Brush brush = {0}; 4.11 @@ -144,32 +143,6 @@ 4.12 } 4.13 4.14 static void 4.15 -init_lock_keys() 4.16 -{ 4.17 - XModifierKeymap *modmap; 4.18 - KeyCode numlock; 4.19 - int i; 4.20 - static int masks[] = { 4.21 - ShiftMask, LockMask, ControlMask, Mod1Mask, 4.22 - Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask 4.23 - }; 4.24 - 4.25 - numlock_mask = 0; 4.26 - modmap = XGetModifierMapping(dpy); 4.27 - numlock = XKeysymToKeycode(dpy, XStringToKeysym("Num_Lock")); 4.28 - 4.29 - if(modmap && modmap->max_keypermod > 0) { 4.30 - int max = (sizeof(masks) / sizeof(int)) * modmap->max_keypermod; 4.31 - for(i = 0; i < max; i++) 4.32 - if(numlock && (modmap->modifiermap[i] == numlock)) 4.33 - numlock_mask = masks[i / modmap->max_keypermod]; 4.34 - } 4.35 - XFreeModifiermap(modmap); 4.36 - 4.37 - lock_mask = 255 & ~(numlock_mask | LockMask); 4.38 -} 4.39 - 4.40 -static void 4.41 cleanup() 4.42 { 4.43 /* 4.44 @@ -243,7 +216,7 @@ 4.45 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); 4.46 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); 4.47 4.48 - init_lock_keys(); 4.49 + update_keys(); 4.50 4.51 brush.drawable = XCreatePixmap(dpy, root, rect.width, rect.height, 4.52 DefaultDepth(dpy, screen));
5.1 --- a/wm.h Tue Jul 11 11:27:56 2006 +0200 5.2 +++ b/wm.h Tue Jul 11 11:50:18 2006 +0200 5.3 @@ -20,6 +20,7 @@ 5.4 enum { RFloat, RGrid, RLast }; 5.5 5.6 typedef struct Client Client; 5.7 +typedef struct Key Key; 5.8 5.9 struct Client { 5.10 char name[256]; 5.11 @@ -36,6 +37,13 @@ 5.12 Client *snext; 5.13 }; 5.14 5.15 +struct Key { 5.16 + unsigned long mod; 5.17 + KeySym keysym; 5.18 + void (*func)(char *arg); 5.19 + char *arg; 5.20 +}; 5.21 + 5.22 extern Display *dpy; 5.23 extern Window root, barwin; 5.24 extern Atom wm_atom[WMLast], net_atom[NetLast]; 5.25 @@ -46,7 +54,6 @@ 5.26 extern void (*handler[LASTEvent]) (XEvent *); 5.27 5.28 extern int screen, sel_screen; 5.29 -extern unsigned int lock_mask, numlock_mask; 5.30 extern char *bartext, tag[256]; 5.31 5.32 extern Brush brush; 5.33 @@ -55,9 +62,15 @@ 5.34 /* bar.c */ 5.35 extern void draw_bar(); 5.36 5.37 +/* cmd.c */ 5.38 +extern void run(char *arg); 5.39 + 5.40 /* client.c */ 5.41 extern Client *create_client(Window w, XWindowAttributes *wa); 5.42 extern void manage(Client *c); 5.43 5.44 +/* key.c */ 5.45 +extern void update_keys(); 5.46 + 5.47 /* wm.c */ 5.48 extern int win_proto(Window w);