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 * © 2006-2007 Jukka Salmi <jukka at salmi dot ch>
4 * © 2007 Premysl Hruby <dfenze at gmail dot com>
5 * © 2007 Szabolcs Nagy <nszabolcs at gmail dot com>
6 * See LICENSE file for license details. */
13 drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
16 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
18 gcv.foreground = col[ColFG];
19 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
20 x = (dc.font.ascent + dc.font.descent + 2) / 4;
24 r.width = r.height = x + 1;
25 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
28 r.width = r.height = x;
29 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
34 isoccupied(unsigned int t) {
37 for(c = clients; c; c = c->next)
44 textnw(const char *text, unsigned int len) {
48 XmbTextExtents(dc.font.set, text, len, NULL, &r);
51 return XTextWidth(dc.font.xfont, text, len);
61 for(i = 0; i < ntags; i++) {
62 dc.w = textw(tags[i]);
64 drawtext(tags[i], dc.sel);
65 drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
68 drawtext(tags[i], dc.norm);
69 drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm);
74 drawtext(lt->symbol, dc.norm);
82 drawtext(stext, dc.norm);
83 if((dc.w = dc.x - x) > bh) {
86 drawtext(sel->name, dc.sel);
87 drawsquare(sel->ismax, sel->isfloating, dc.sel);
90 drawtext(NULL, dc.norm);
92 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
97 drawtext(const char *text, unsigned long col[ColLast]) {
100 unsigned int len, olen;
101 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
103 XSetForeground(dpy, dc.gc, col[ColBG]);
104 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
108 olen = len = strlen(text);
109 if(len >= sizeof buf)
110 len = sizeof buf - 1;
111 memcpy(buf, text, len);
113 h = dc.font.ascent + dc.font.descent;
114 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
116 /* shorten text if necessary */
117 while(len && (w = textnw(buf, len)) > dc.w - h)
128 return; /* too long */
129 XSetForeground(dpy, dc.gc, col[ColFG]);
131 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
133 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
137 textw(const char *text) {
138 return textnw(text, strlen(text)) + dc.font.height;