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 * © 2007 Szabolcs Nagy <nszabolcs at gmail dot com>
5 * See LICENSE file for license details. */
12 drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
15 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
17 gcv.foreground = col[ColFG];
18 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
19 x = (dc.font.ascent + dc.font.descent + 2) / 4;
23 r.width = r.height = x + 1;
24 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
27 r.width = r.height = x;
28 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
33 isoccupied(unsigned int t) {
36 for(c = clients; c; c = c->next)
43 textnw(const char *text, unsigned int len) {
47 XmbTextExtents(dc.font.set, text, len, NULL, &r);
50 return XTextWidth(dc.font.xfont, text, len);
60 for(i = 0; i < ntags; i++) {
61 dc.w = textw(tags[i]);
63 drawtext(tags[i], dc.sel);
64 drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
67 drawtext(tags[i], dc.norm);
68 drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm);
73 drawtext(lt->symbol, dc.norm);
81 drawtext(stext, dc.norm);
82 if((dc.w = dc.x - x) > bh) {
85 drawtext(sel->name, dc.sel);
86 drawsquare(sel->ismax, sel->isfloating, dc.sel);
89 drawtext(NULL, dc.norm);
91 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
96 drawtext(const char *text, unsigned long col[ColLast]) {
99 unsigned int len, olen;
100 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
102 XSetForeground(dpy, dc.gc, col[ColBG]);
103 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
107 olen = len = strlen(text);
108 if(len >= sizeof buf)
109 len = sizeof buf - 1;
110 memcpy(buf, text, len);
112 h = dc.font.ascent + dc.font.descent;
113 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
115 /* shorten text if necessary */
116 while(len && (w = textnw(buf, len)) > dc.w - h)
127 return; /* too long */
128 XSetForeground(dpy, dc.gc, col[ColFG]);
130 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
132 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
136 textw(const char *text) {
137 return textnw(text, strlen(text)) + dc.font.height;