diff --git a/sowm.c b/sowm.c index 96f8340..436ba03 100644 --- a/sowm.c +++ b/sowm.c @@ -11,8 +11,8 @@ #include "sowm.h" static client *list = {0}, *ws_list[10] = {0}, *cur; -static int ws = 1, sw, sh, wx, wy, numlock = 0; -static unsigned int ww, wh; +static int ws = 1, sw, sh, wx, wy; +static unsigned int ww, wh, clean_mask; static Display *d; static XButtonEvent mouse; @@ -66,10 +66,11 @@ void notify_motion(XEvent *e) { void key_press(XEvent *e) { KeySym keysym = XkbKeycodeToKeysym(d, e->xkey.keycode, 0, 0); + unsigned mod = clean_mask & e->xkey.state; for (unsigned int i=0; i < sizeof(keys)/sizeof(*keys); ++i) if (keys[i].keysym == keysym && - mod_clean(keys[i].mod) == mod_clean(e->xkey.state)) + keys[i].mod == mod) keys[i].function(keys[i].arg); } @@ -239,32 +240,41 @@ void run(const Arg arg) { execvp((char*)arg.com[0], (char**)arg.com); } -void input_grab(Window root) { - unsigned int i, j, modifiers[] = {0, LockMask, numlock, numlock|LockMask}; +// Taken from DWM. Many thanks. https://git.suckless.org/dwm +static unsigned int numlockmask(void) { + unsigned int nlm = 0; XModifierKeymap *modmap = XGetModifierMapping(d); - KeyCode code; + KeyCode code = XKeysymToKeycode(d, XK_Num_Lock); - for (i = 0; i < 8; i++) - for (int k = 0; k < modmap->max_keypermod; k++) - if (modmap->modifiermap[i * modmap->max_keypermod + k] - == XKeysymToKeycode(d, 0xff7f)) - numlock = (1 << i); + for (unsigned int i = 0; i < 8; i++) + for (int m = modmap->max_keypermod, k = 0; k < m; k++) + if (modmap->modifiermap[i * m + k] == code) + nlm = 1<