1 /* See LICENSE file for copyright and license details. */
8 drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
11 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
13 gcv.foreground = col[ColFG];
14 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
15 x = (dc.font.ascent + dc.font.descent + 2) / 4;
19 r.width = r.height = x + 1;
20 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
23 r.width = r.height = x;
24 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
29 isoccupied(unsigned int t) {
32 for(c = clients; c; c = c->next)
39 textnw(const char *text, unsigned int len) {
43 XmbTextExtents(dc.font.set, text, len, NULL, &r);
46 return XTextWidth(dc.font.xfont, text, len);
56 for(i = 0; i < ntags; i++) {
57 dc.w = textw(tags[i]);
59 drawtext(tags[i], dc.sel);
60 drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
63 drawtext(tags[i], dc.norm);
64 drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm);
69 drawtext(getsymbol(), dc.norm);
77 drawtext(stext, dc.norm);
78 if((dc.w = dc.x - x) > bh) {
81 drawtext(sel->name, dc.sel);
82 drawsquare(sel->ismax, sel->isfloating, dc.sel);
85 drawtext(NULL, dc.norm);
87 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
92 drawtext(const char *text, unsigned long col[ColLast]) {
95 unsigned int len, olen;
96 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
98 XSetForeground(dpy, dc.gc, col[ColBG]);
99 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
103 olen = len = strlen(text);
104 if(len >= sizeof buf)
105 len = sizeof buf - 1;
106 memcpy(buf, text, len);
108 h = dc.font.ascent + dc.font.descent;
109 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
111 /* shorten text if necessary */
112 while(len && (w = textnw(buf, len)) > dc.w - h)
123 return; /* too long */
124 XSetForeground(dpy, dc.gc, col[ColFG]);
126 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
128 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
132 textw(const char *text) {
133 return textnw(text, strlen(text)) + dc.font.height;