diff options
Diffstat (limited to 'dwm.c')
| -rw-r--r-- | dwm.c | 7 |
1 files changed, 3 insertions, 4 deletions
| @@ -551,7 +551,7 @@ drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]) { | |||
| 551 | 551 | ||
| 552 | void | 552 | void |
| 553 | drawtext(const char *text, ulong col[ColLast], Bool invert) { | 553 | drawtext(const char *text, ulong col[ColLast], Bool invert) { |
| 554 | int x, y, w, h; | 554 | int i, x, y, h; |
| 555 | uint len, olen; | 555 | uint len, olen; |
| 556 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | 556 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
| 557 | char buf[256]; | 557 | char buf[256]; |
| @@ -563,16 +563,15 @@ drawtext(const char *text, ulong col[ColLast], Bool invert) { | |||
| 563 | olen = strlen(text); | 563 | olen = strlen(text); |
| 564 | len = MIN(olen, sizeof buf); | 564 | len = MIN(olen, sizeof buf); |
| 565 | memcpy(buf, text, len); | 565 | memcpy(buf, text, len); |
| 566 | w = 0; | ||
| 567 | h = dc.font.ascent + dc.font.descent; | 566 | h = dc.font.ascent + dc.font.descent; |
| 568 | y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; | 567 | y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; |
| 569 | x = dc.x + (h / 2); | 568 | x = dc.x + (h / 2); |
| 570 | /* shorten text if necessary */ | 569 | /* shorten text if necessary */ |
| 571 | for(; len && (w = textnw(buf, len)) > dc.w - h; len--); | 570 | for(; len && (i = textnw(buf, len)) > dc.w - h; len--); |
| 572 | if(!len) | 571 | if(!len) |
| 573 | return; | 572 | return; |
| 574 | if(len < olen) | 573 | if(len < olen) |
| 575 | memcpy(&buf[MAX(0, len - 3)], "...", 3); | 574 | for(i = len; i >= MAX(0, len - 3); buf[i--] = '.'); |
| 576 | XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); | 575 | XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); |
| 577 | if(dc.font.set) | 576 | if(dc.font.set) |
| 578 | XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); | 577 | XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); |
