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 * © 2007 Premysl Hruby <dfenze at gmail dot com>
4 * See LICENSE file for license details. */
11 drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
14 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
16 gcv.foreground = col[ColFG];
17 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
18 x = (dc.font.ascent + dc.font.descent + 2) / 4;
22 r.width = r.height = x + 1;
23 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
26 r.width = r.height = x;
27 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
32 isoccupied(unsigned int t) {
35 for(c = clients; c; c = c->next)
42 textnw(const char *text, unsigned int len) {
46 XmbTextExtents(dc.font.set, text, len, NULL, &r);
49 return XTextWidth(dc.font.xfont, text, len);
59 for(i = 0; i < ntags; i++) {
60 dc.w = textw(tags[i]);
62 drawtext(tags[i], dc.sel);
63 drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
66 drawtext(tags[i], dc.norm);
67 drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm);
72 drawtext(lt->symbol, dc.norm);
80 drawtext(stext, dc.norm);
81 if((dc.w = dc.x - x) > bh) {
84 drawtext(sel->name, dc.sel);
85 drawsquare(sel->ismax, sel->isfloating, dc.sel);
88 drawtext(NULL, dc.norm);
90 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
95 drawtext(const char *text, unsigned long col[ColLast]) {
98 unsigned int len, olen;
99 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
101 XSetForeground(dpy, dc.gc, col[ColBG]);
102 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
106 olen = len = strlen(text);
107 if(len >= sizeof buf)
108 len = sizeof buf - 1;
109 memcpy(buf, text, len);
111 h = dc.font.ascent + dc.font.descent;
112 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
114 /* shorten text if necessary */
115 while(len && (w = textnw(buf, len)) > dc.w - h)
126 return; /* too long */
127 XSetForeground(dpy, dc.gc, col[ColFG]);
129 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
131 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
135 textw(const char *text) {
136 return textnw(text, strlen(text)) + dc.font.height;