1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
10 drawcaret(unsigned long col[ColLast]) {
15 gcv.foreground = col[ColFG];
16 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
17 x = (dc.font.ascent + dc.font.descent) / 2;
19 pt[0].y = dc.y + 1 + x;
24 XDrawLines(dpy, dc.drawable, dc.gc, pt, 3, CoordModePrevious);
28 drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
31 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
33 gcv.foreground = col[ColFG];
34 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
35 x = (dc.font.ascent + dc.font.descent + 2) / 4;
39 r.width = r.height = x + 1;
40 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
43 r.width = r.height = x;
44 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
49 isoccupied(unsigned int t) {
52 for(c = clients; c; c = c->next)
59 textnw(const char *text, unsigned int len) {
63 XmbTextExtents(dc.font.set, text, len, NULL, &r);
66 return XTextWidth(dc.font.xfont, text, len);
76 for(i = 0; i < ntags; i++) {
77 dc.w = textw(tags[i]);
79 drawtext(tags[i], dc.sel);
80 drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
83 drawtext(tags[i], dc.norm);
84 drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm);
89 drawtext(lt->symbol, dc.norm);
97 drawtext(stext, dc.norm);
98 if((dc.w = dc.x - x) > bh) {
101 drawtext(sel->name, dc.sel);
106 drawtext(NULL, dc.norm);
108 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
113 drawtext(const char *text, unsigned long col[ColLast]) {
115 static char buf[256];
116 unsigned int len, olen;
118 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
120 XSetForeground(dpy, dc.gc, col[ColBG]);
121 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
125 olen = len = strlen(text);
126 if(len >= sizeof buf)
127 len = sizeof buf - 1;
128 memcpy(buf, text, len);
130 h = dc.font.ascent + dc.font.descent;
131 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
133 /* shorten text if necessary */
134 while(len && (w = textnw(buf, len)) > dc.w - h)
145 return; /* too long */
146 gcv.foreground = col[ColFG];
148 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
149 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
152 gcv.font = dc.font.xfont->fid;
153 XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
154 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
159 textw(const char *text) {
160 return textnw(text, strlen(text)) + dc.font.height;