X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dwm.c;h=ba24d9a6b78ec79a58fa66d460b630bfc8cfd050;hb=258c3380305683de8031871cf95c1cc04ed7ad9e;hp=146d344d497819e197a32e797d1e92a07246e4f4;hpb=47f63dce550fab02f9d15aca5cec8c137125ac16;p=dwm.git diff --git a/dwm.c b/dwm.c index 146d344..ba24d9a 100644 --- a/dwm.c +++ b/dwm.c @@ -581,7 +581,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); @@ -751,25 +751,27 @@ grabbuttons(Client *c, Bool focused) { void grabkeys(void) { unsigned int i, j; - unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; - KeyCode code; XModifierKeymap *modmap; - /* init modifier map */ + /* update modifier map */ modmap = XGetModifierMapping(dpy); for(i = 0; i < 8; i++) - for(j = 0; j < modmap->max_keypermod; j++) { + 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++) { - code = XKeysymToKeycode(dpy, keys[i].keysym); - for(j = 0; j < LENGTH(modifiers); j++) - XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True, - GrabModeAsync, GrabModeAsync); + { /* grab keys */ + unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; + KeyCode code; + + XUngrabKey(dpy, AnyKey, AnyModifier, root); + for(i = 0; i < LENGTH(keys); i++) { + code = XKeysymToKeycode(dpy, keys[i].keysym); + for(j = 0; j < LENGTH(modifiers); j++) + XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True, + GrabModeAsync, GrabModeAsync); + } } } @@ -779,8 +781,6 @@ initfont(const char *fontstr) { int i, n; missing = NULL; - if(dc.font.set) - XFreeFontSet(dpy, dc.font.set); dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); if(missing) { while(n--) @@ -1128,7 +1128,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 +1373,6 @@ setup(void) { XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); XSelectInput(dpy, root, wa.event_mask); - - /* grab keys */ grabkeys(); } @@ -1469,8 +1467,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();