X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dmenu.c;h=c0addad867c5229e40edc3b2074966fffbc2f641;hb=ef00902fd91dba280aba605b1a812c2f0cdc3657;hp=d67c1ae8bddd2932e6b0d69332d4fb432d4ccd43;hpb=17232f493b07973bacd60abb2e957ccae829eb7e;p=dmenu.git diff --git a/dmenu.c b/dmenu.c index d67c1ae..c0addad 100644 --- a/dmenu.c +++ b/dmenu.c @@ -1,6 +1,7 @@ /* See LICENSE file for copyright and license details. */ #define _BSD_SOURCE #include +#include #include #include #include @@ -78,7 +79,7 @@ static unsigned int mw, mh; static unsigned int numlockmask = 0; static Bool running = True; static Display *dpy; -static DC dc = {0}; +static DC dc; static Item *allitems = NULL; /* first of all items */ static Item *item = NULL; /* first of pattern matching items */ static Item *sel = NULL; @@ -226,7 +227,7 @@ drawtext(const char *text, unsigned long col[ColLast]) { 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); @@ -280,8 +281,6 @@ initfont(const char *fontstr) { if(!fontstr || fontstr[0] == '\0') eprint("error, cannot load font: '%s'\n", fontstr); missing = NULL; - if(dc.font.set) - XFreeFontSet(dpy, dc.font.set); dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); if(missing) XFreeStringList(missing); @@ -301,9 +300,6 @@ initfont(const char *fontstr) { } } else { - if(dc.font.xfont) - XFreeFont(dpy, dc.font.xfont); - dc.font.xfont = NULL; if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) eprint("error, cannot load font: '%s'\n", fontstr); @@ -707,7 +703,7 @@ main(int argc, char *argv[]) { else eprint("usage: dmenu [-i] [-b] [-fn ] [-nb ] [-nf ]\n" " [-p ] [-sb ] [-sf ] [-v]\n"); - if(!XSupportsLocale()) + if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fprintf(stderr, "warning: no locale support\n"); if(!(dpy = XOpenDisplay(0))) eprint("dmenu: cannot open display\n");