From: Anselm R Garbe Date: Mon, 25 Aug 2008 08:44:23 +0000 (+0100) Subject: grabbuttons() and grabkeys() are now independent from prior numlockmask initialization X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=288cf78b180db846ef2481124f3e7a8fe66c01f2;p=dwm.git grabbuttons() and grabkeys() are now independent from prior numlockmask initialization --- diff --git a/dwm.c b/dwm.c index 4ea16e0..89bca14 100644 --- a/dwm.c +++ b/dwm.c @@ -191,6 +191,7 @@ static void unmanage(Client *c); static void unmapnotify(XEvent *e); static void updatebar(void); static void updategeom(void); +static void updatenumlockmask(void); static void updatesizehints(Client *c); static void updatetitle(Client *c); static void updatewmhints(Client *c); @@ -735,34 +736,27 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) { void grabbuttons(Client *c, Bool focused) { - unsigned int i, j; - unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; - - XUngrabButton(dpy, AnyButton, AnyModifier, c->win); - if(focused) { - for(i = 0; i < LENGTH(buttons); i++) - if(buttons[i].click == ClkClientWin) - for(j = 0; j < LENGTH(modifiers); j++) - XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); - } else - XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, - BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + updatenumlockmask(); + { + unsigned int i, j; + unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; + XUngrabButton(dpy, AnyButton, AnyModifier, c->win); + if(focused) { + for(i = 0; i < LENGTH(buttons); i++) + if(buttons[i].click == ClkClientWin) + for(j = 0; j < LENGTH(modifiers); j++) + XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + } else + XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, + BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + } } void grabkeys(void) { - unsigned int i, j; - XModifierKeymap *modmap; - - /* update modifier map */ - modmap = XGetModifierMapping(dpy); - for(i = 0; i < 8; i++) - for(j = 0; j < modmap->max_keypermod; j++) - if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock)) - numlockmask = (1 << i); - XFreeModifiermap(modmap); - + updatenumlockmask(); { /* grab keys */ + unsigned int i, j; unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; KeyCode code; @@ -1575,6 +1569,20 @@ updategeom(void) { by = showbar ? (topbar ? wy - bh : wy + wh) : -bh; } +void +updatenumlockmask(void) { + unsigned int i, j; + XModifierKeymap *modmap; + + numlockmask = 0; + modmap = XGetModifierMapping(dpy); + for(i = 0; i < 8; i++) + for(j = 0; j < modmap->max_keypermod; j++) + if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock)) + numlockmask = (1 << i); + XFreeModifiermap(modmap); +} + void updatesizehints(Client *c) { long msize;