summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/dwm.c b/dwm.c
index 8c51275..7643764 100644
--- a/dwm.c
+++ b/dwm.c
@@ -210,7 +210,7 @@ int xerrorstart(Display *dpy, XErrorEvent *ee);
210void zoom(const char *arg); 210void zoom(const char *arg);
211 211
212/* variables */ 212/* variables */
213char stext[256], buf[256]; 213char stext[256];
214int screen, sx, sy, sw, sh; 214int screen, sx, sy, sw, sh;
215int (*xerrorxlib)(Display *, XErrorEvent *); 215int (*xerrorxlib)(Display *, XErrorEvent *);
216int bx, by, bw, bh, blw, bgw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh; 216int bx, by, bw, bh, blw, bgw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh;
@@ -597,22 +597,23 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
597 int x, y, w, h; 597 int x, y, w, h;
598 unsigned int len, olen; 598 unsigned int len, olen;
599 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; 599 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
600 char buf[256];
600 601
601 XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); 602 XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
602 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); 603 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
603 if(!text) 604 if(!text)
604 return; 605 return;
605 w = 0;
606 olen = strlen(text); 606 olen = strlen(text);
607 len = MIN(olen, sizeof buf - 1); 607 len = MIN(olen, sizeof buf);
608 memcpy(buf, text, len); 608 memcpy(buf, text, len);
609 buf[len] = 0; 609 w = 0;
610 h = dc.font.ascent + dc.font.descent; 610 h = dc.font.ascent + dc.font.descent;
611 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; 611 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
612 x = dc.x + (h / 2); 612 x = dc.x + (h / 2);
613 /* shorten text if necessary */ 613 /* shorten text if necessary */
614 while(len && (w = textnw(buf, len)) > dc.w - h) 614 for(; len && (w = textnw(buf, len)) > dc.w - h; len--);
615 buf[--len] = 0; 615 if (!len)
616 return;
616 if(len < olen) { 617 if(len < olen) {
617 if(len > 1) 618 if(len > 1)
618 buf[len - 1] = '.'; 619 buf[len - 1] = '.';
@@ -621,8 +622,6 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
621 if(len > 3) 622 if(len > 3)
622 buf[len - 3] = '.'; 623 buf[len - 3] = '.';
623 } 624 }
624 if(w > dc.w)
625 return; /* too long */
626 XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); 625 XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
627 if(dc.font.set) 626 if(dc.font.set)
628 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); 627 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);