2 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
8 #include <X11/Xlocale.h>
13 textnw(const char *text, unsigned int len)
18 XmbTextExtents(dc.font.set, text, len, NULL, &r);
21 return XTextWidth(dc.font.xfont, text, len);
25 drawtext(const char *text, unsigned int colidx, Bool highlight)
29 unsigned int len, olen;
31 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
33 XSetForeground(dpy, dc.gc, dc.bg[colidx]);
34 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
37 points[1].x = dc.w - 1;
40 points[2].y = dc.h - 1;
41 points[3].x = -(dc.w - 1);
44 points[4].y = -(dc.h - 1);
45 XSetForeground(dpy, dc.gc, dc.fg[colidx]);
46 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
52 olen = len = strlen(text);
53 if(len >= sizeof(buf))
54 len = sizeof(buf) - 1;
55 memcpy(buf, text, len);
58 h = dc.font.ascent + dc.font.descent;
59 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
62 /* shorten text if necessary */
63 while(len && (w = textnw(buf, len)) > dc.w - h)
75 return; /* too long */
77 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
79 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
80 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
83 points[0].x = dc.x + 1;
84 points[0].y = dc.y + 1;
85 points[1].x = dc.w - 3;
88 points[2].y = dc.h - 3;
89 points[3].x = -(dc.w - 3);
92 points[4].y = -(dc.h - 3);
93 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
104 for(c = clients; c; c = getnext(c->next))
113 Bool istile = arrange == dotile;
117 drawtext(NULL, istile ? 1 : 0, False);
120 for(i = 0; i < ntags; i++) {
122 dc.w = textw(tags[i]);
124 drawtext(tags[i], seltag[i] ? 0 : 1, sel && sel->tags[i]);
126 drawtext(tags[i], seltag[i] ? 1 : 0, sel && sel->tags[i]);
130 dc.x = bx + bw - dc.w;
135 drawtext(stext, istile ? 1 : 0, False);
137 if(sel && ((dc.w = dc.x - x) > bh)) {
139 drawtext(sel->name, istile ? 0 : 1, False);
141 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
149 Bool istile = arrange == dotile;
151 if(c == sel && issel) {
153 XUnmapWindow(dpy, c->twin);
154 XSetWindowBorder(dpy, c->win, dc.fg[1]);
158 XSetWindowBorder(dpy, c->win, dc.bg[0]);
159 XMapWindow(dpy, c->twin);
162 drawtext(c->name, istile ? 1 : 0, False);
163 XCopyArea(dpy, dc.drawable, c->twin, dc.gc, 0, 0, c->tw, c->th, 0, 0);
168 getcolor(const char *colstr)
170 Colormap cmap = DefaultColormap(dpy, screen);
173 XAllocNamedColor(dpy, cmap, colstr, &color, &color);
178 setfont(const char *fontstr)
180 char **missing, *def;
184 setlocale(LC_ALL, "");
186 XFreeFontSet(dpy, dc.font.set);
187 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
190 fprintf(stderr, "missing fontset: %s\n", missing[n]);
191 XFreeStringList(missing);
193 XFreeFontSet(dpy, dc.font.set);
198 XFontSetExtents *font_extents;
199 XFontStruct **xfonts;
202 dc.font.ascent = dc.font.descent = 0;
203 font_extents = XExtentsOfFontSet(dc.font.set);
204 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
205 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
206 if(dc.font.ascent < (*xfonts)->ascent)
207 dc.font.ascent = (*xfonts)->ascent;
208 if(dc.font.descent < (*xfonts)->descent)
209 dc.font.descent = (*xfonts)->descent;
215 XFreeFont(dpy, dc.font.xfont);
216 dc.font.xfont = NULL;
217 dc.font.xfont = XLoadQueryFont(dpy, fontstr);
219 dc.font.xfont = XLoadQueryFont(dpy, "fixed");
221 eprint("error, cannot init 'fixed' font\n");
222 dc.font.ascent = dc.font.xfont->ascent;
223 dc.font.descent = dc.font.xfont->descent;
225 dc.font.height = dc.font.ascent + dc.font.descent;
229 textw(const char *text)
231 return textnw(text, strlen(text)) + dc.font.height;