diff options
| -rw-r--r-- | drw.c | 35 |
1 files changed, 14 insertions, 21 deletions
| @@ -224,9 +224,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex | |||
| 224 | char buf[1024]; | 224 | char buf[1024]; |
| 225 | int tx, ty, th; | 225 | int tx, ty, th; |
| 226 | Extnts tex; | 226 | Extnts tex; |
| 227 | Colormap cmap; | 227 | XftDraw *d = NULL; |
| 228 | Visual *vis; | ||
| 229 | XftDraw *d; | ||
| 230 | Fnt *curfont, *nextfont; | 228 | Fnt *curfont, *nextfont; |
| 231 | size_t i, len; | 229 | size_t i, len; |
| 232 | int utf8strlen, utf8charlen, render; | 230 | int utf8strlen, utf8charlen, render; |
| @@ -238,22 +236,18 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex | |||
| 238 | XftResult result; | 236 | XftResult result; |
| 239 | int charexists = 0; | 237 | int charexists = 0; |
| 240 | 238 | ||
| 241 | if (!(render = x || y || w || h)) | 239 | if (!drw->scheme || !drw->fontcount) |
| 242 | w = ~w; | ||
| 243 | |||
| 244 | if (!drw || !drw->scheme) { | ||
| 245 | return 0; | 240 | return 0; |
| 246 | } else if (render) { | ||
| 247 | XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg->pix : drw->scheme->bg->pix); | ||
| 248 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); | ||
| 249 | } | ||
| 250 | 241 | ||
| 251 | if (!text || !drw->fontcount) { | 242 | if (!(render = x || y || w || h)) { |
| 252 | return 0; | 243 | w = ~w; |
| 253 | } else if (render) { | 244 | } else { |
| 254 | cmap = DefaultColormap(drw->dpy, drw->screen); | 245 | XSetForeground(drw->dpy, drw->gc, invert ? |
| 255 | vis = DefaultVisual(drw->dpy, drw->screen); | 246 | drw->scheme->fg->pix : drw->scheme->bg->pix); |
| 256 | d = XftDrawCreate(drw->dpy, drw->drawable, vis, cmap); | 247 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); |
| 248 | d = XftDrawCreate(drw->dpy, drw->drawable, | ||
| 249 | DefaultVisual(drw->dpy, drw->screen), | ||
| 250 | DefaultColormap(drw->dpy, drw->screen)); | ||
| 257 | } | 251 | } |
| 258 | 252 | ||
| 259 | curfont = drw->fonts[0]; | 253 | curfont = drw->fonts[0]; |
| @@ -325,7 +319,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex | |||
| 325 | if (!drw->fonts[0]->pattern) { | 319 | if (!drw->fonts[0]->pattern) { |
| 326 | /* Refer to the comment in drw_font_xcreate for more | 320 | /* Refer to the comment in drw_font_xcreate for more |
| 327 | * information. */ | 321 | * information. */ |
| 328 | die("The first font in the cache must be loaded from a font string.\n"); | 322 | die("the first font in the cache must be loaded from a font string.\n"); |
| 329 | } | 323 | } |
| 330 | 324 | ||
| 331 | fcpattern = FcPatternDuplicate(drw->fonts[0]->pattern); | 325 | fcpattern = FcPatternDuplicate(drw->fonts[0]->pattern); |
| @@ -344,14 +338,13 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex | |||
| 344 | if (curfont && XftCharExists(drw->dpy, curfont->xfont, utf8codepoint)) { | 338 | if (curfont && XftCharExists(drw->dpy, curfont->xfont, utf8codepoint)) { |
| 345 | drw->fonts[drw->fontcount++] = curfont; | 339 | drw->fonts[drw->fontcount++] = curfont; |
| 346 | } else { | 340 | } else { |
| 347 | if (curfont) | 341 | drw_font_free(curfont); |
| 348 | drw_font_free(curfont); | ||
| 349 | curfont = drw->fonts[0]; | 342 | curfont = drw->fonts[0]; |
| 350 | } | 343 | } |
| 351 | } | 344 | } |
| 352 | } | 345 | } |
| 353 | } | 346 | } |
| 354 | if (render) | 347 | if (d) |
| 355 | XftDrawDestroy(d); | 348 | XftDrawDestroy(d); |
| 356 | 349 | ||
| 357 | return x; | 350 | return x; |
