X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwm.c;h=fa8344a0f52906b2366ab190f90bdbc1ff0ef2ed;hb=2b4157eccd649682c200de837193dd0a24129dc7;hp=146d344d497819e197a32e797d1e92a07246e4f4;hpb=47f63dce550fab02f9d15aca5cec8c137125ac16;p=dwm.git diff --git a/dwm.c b/dwm.c index 146d344..fa8344a 100644 --- a/dwm.c +++ b/dwm.c @@ -158,6 +158,7 @@ static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); static void grabbuttons(Client *c, Bool focused); static void grabkeys(void); static void initfont(const char *fontstr); +static void initmodmap(void); static Bool isprotodel(Client *c); static void keypress(XEvent *e); static void killclient(const Arg *arg); @@ -581,7 +582,7 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) { y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; x = dc.x + (h / 2); /* shorten text if necessary */ - for(len = MIN(olen, sizeof buf); len && textnw(buf, len) > dc.w - h; len--); + for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--); if(!len) return; memcpy(buf, text, len); @@ -753,16 +754,6 @@ grabkeys(void) { unsigned int i, j; unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; KeyCode code; - XModifierKeymap *modmap; - - /* init 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); XUngrabKey(dpy, AnyKey, AnyModifier, root); for(i = 0; i < LENGTH(keys); i++) { @@ -813,6 +804,19 @@ initfont(const char *fontstr) { dc.font.height = dc.font.ascent + dc.font.descent; } +void +initmodmap(void) { + unsigned int i, j; + XModifierKeymap *modmap; + + 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); +} + Bool isprotodel(Client *c) { int i, n; @@ -925,8 +929,10 @@ mappingnotify(XEvent *e) { XMappingEvent *ev = &e->xmapping; XRefreshKeyboardMapping(ev); - if(ev->request == MappingKeyboard) + if(ev->request == MappingKeyboard) { + initmodmap(); grabkeys(); + } } void @@ -1128,7 +1134,7 @@ resizemouse(const Arg *arg) { return; XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); do { - XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask , &ev); + XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); switch(ev.type) { case ConfigureRequest: case Expose: @@ -1373,8 +1379,7 @@ setup(void) { XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); XSelectInput(dpy, root, wa.event_mask); - - /* grab keys */ + initmodmap(); grabkeys(); } @@ -1469,8 +1474,12 @@ togglefloating(const Arg *arg) { void toggletag(const Arg *arg) { - unsigned int mask = sel->tags ^ (arg->ui & TAGMASK); + unsigned int mask; + if (!sel) + return; + + mask = sel->tags ^ (arg->ui & TAGMASK); if(sel && mask) { sel->tags = mask; arrange();