applied Cedric's NumLock patch

This commit is contained in:
arg@10ksloc.org 2006-08-01 12:41:38 +02:00
parent 1b63f832c5
commit 57416beefe

18
event.c
View File

@ -57,6 +57,9 @@ static Key key[] = {
{ MODKEY|ShiftMask, XK_w, spawn, { .argv = browse } }, { MODKEY|ShiftMask, XK_w, spawn, { .argv = browse } },
}; };
#define NumLockMask Mod2Mask
unsigned int valid_mask = 255 & ~( NumLockMask | LockMask);
/* END CUSTOMIZE */ /* END CUSTOMIZE */
/* static */ /* static */
@ -271,10 +274,11 @@ keypress(XEvent *e)
unsigned int i; unsigned int i;
KeySym keysym; KeySym keysym;
XKeyEvent *ev = &e->xkey; XKeyEvent *ev = &e->xkey;
ev->state &= valid_mask;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
for(i = 0; i < len; i++) for(i = 0; i < len; i++)
if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { if((keysym == key[i].keysym) && ((key[i].mod & valid_mask) == ev->state)) {
if(key[i].func) if(key[i].func)
key[i].func(&key[i].arg); key[i].func(&key[i].arg);
return; return;
@ -377,7 +381,19 @@ grabkeys()
for(i = 0; i < len; i++) { for(i = 0; i < len; i++) {
code = XKeysymToKeycode(dpy, key[i].keysym); code = XKeysymToKeycode(dpy, key[i].keysym);
XUngrabKey(dpy, code, key[i].mod, root); XUngrabKey(dpy, code, key[i].mod, root);
if (NumLockMask)
{
XUngrabKey(dpy, code, key[i].mod | NumLockMask, root);
XUngrabKey(dpy, code, key[i].mod | NumLockMask | LockMask, root);
}
XGrabKey(dpy, code, key[i].mod, root, True, XGrabKey(dpy, code, key[i].mod, root, True,
GrabModeAsync, GrabModeAsync); GrabModeAsync, GrabModeAsync);
if (NumLockMask)
{
XGrabKey(dpy, code, key[i].mod | NumLockMask, root, True,
GrabModeAsync, GrabModeAsync);
XGrabKey(dpy, code, key[i].mod | NumLockMask | LockMask, root, True,
GrabModeAsync, GrabModeAsync);
}
} }
} }