1 /* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
2 * © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
3 * See LICENSE file for license details. */
10 drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
13 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
15 gcv.foreground = col[ColFG];
16 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
17 x = (dc.font.ascent + dc.font.descent + 2) / 4;
21 r.width = r.height = x + 1;
22 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
25 r.width = r.height = x;
26 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
31 isoccupied(unsigned int t) {
34 for(c = clients; c; c = c->next)
41 textnw(const char *text, unsigned int len) {
45 XmbTextExtents(dc.font.set, text, len, NULL, &r);
48 return XTextWidth(dc.font.xfont, text, len);
58 for(i = 0; i < ntags; i++) {
59 dc.w = textw(tags[i]);
61 drawtext(tags[i], dc.sel);
62 drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
65 drawtext(tags[i], dc.norm);
66 drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm);
71 drawtext(lt->symbol, dc.norm);
79 drawtext(stext, dc.norm);
80 if((dc.w = dc.x - x) > bh) {
83 drawtext(sel->name, dc.sel);
84 drawsquare(sel->ismax, sel->isfloating, dc.sel);
87 drawtext(NULL, dc.norm);
89 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
94 drawtext(const char *text, unsigned long col[ColLast]) {
97 unsigned int len, olen;
98 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
100 XSetForeground(dpy, dc.gc, col[ColBG]);
101 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
105 olen = len = strlen(text);
106 if(len >= sizeof buf)
107 len = sizeof buf - 1;
108 memcpy(buf, text, len);
110 h = dc.font.ascent + dc.font.descent;
111 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
113 /* shorten text if necessary */
114 while(len && (w = textnw(buf, len)) > dc.w - h)
125 return; /* too long */
126 XSetForeground(dpy, dc.gc, col[ColFG]);
128 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
130 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
134 textw(const char *text) {
135 return textnw(text, strlen(text)) + dc.font.height;