2 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
9 #include <X11/Xlocale.h>
18 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
19 XSetForeground(dpy, dc.gc, dc.border);
22 points[1].x = dc.w - 1;
25 points[2].y = dc.h - 1;
26 points[3].x = -(dc.w - 1);
29 points[4].y = -(dc.h - 1);
30 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
34 textnw(char *text, unsigned int len)
39 XmbTextExtents(dc.font.set, text, len, NULL, &r);
42 return XTextWidth(dc.font.xfont, text, len);
46 drawtext(const char *text, Bool invert, Bool border)
52 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
54 XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
55 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
65 if(len >= sizeof(buf))
66 len = sizeof(buf) - 1;
67 memcpy(buf, text, len);
70 h = dc.font.ascent + dc.font.descent;
71 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
74 /* shorten text if necessary */
75 while(len && (w = textnw(buf, len)) > dc.w - h)
79 return; /* too long */
81 gcv.foreground = invert ? dc.bg : dc.fg;
82 gcv.background = invert ? dc.fg : dc.bg;
84 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
85 XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
89 gcv.font = dc.font.xfont->fid;
90 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
91 XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
102 for(c = clients; c; c = getnext(c->next, tsel))
111 Bool istile = arrange == dotile;
115 drawtext(NULL, !istile, False);
118 for(i = 0; i < TLast; i++) {
120 dc.w = textw(tags[i]);
122 drawtext(tags[i], (i == tsel), True);
124 drawtext(tags[i], (i != tsel), True);
128 dc.x = bx + bw - dc.w;
129 drawtext(stext, !istile, False);
130 if(sel && ((dc.w = dc.x - x) >= bh)) {
132 drawtext(sel->name, istile, True);
134 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
142 Bool istile = arrange == dotile;
146 XUnmapWindow(dpy, c->title);
147 XSetWindowBorder(dpy, c->win, dc.fg);
151 XSetWindowBorder(dpy, c->win, dc.bg);
152 XMapWindow(dpy, c->title);
157 for(i = 0; i < TLast; i++) {
160 dc.w = textw(c->tags[i]);
161 drawtext(c->tags[i], !istile, True);
165 dc.w = textw(c->name);
166 drawtext(c->name, !istile, True);
167 XCopyArea(dpy, dc.drawable, c->title, dc.gc, 0, 0, c->tw, c->th, 0, 0);
172 getcolor(const char *colstr)
174 Colormap cmap = DefaultColormap(dpy, screen);
177 XAllocNamedColor(dpy, cmap, colstr, &color, &color);
182 setfont(const char *fontstr)
184 char **missing, *def;
188 setlocale(LC_ALL, "");
190 XFreeFontSet(dpy, dc.font.set);
191 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
194 fprintf(stderr, "missing fontset: %s\n", missing[n]);
195 XFreeStringList(missing);
197 XFreeFontSet(dpy, dc.font.set);
202 XFontSetExtents *font_extents;
203 XFontStruct **xfonts;
206 dc.font.ascent = dc.font.descent = 0;
207 font_extents = XExtentsOfFontSet(dc.font.set);
208 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
209 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
210 if(dc.font.ascent < (*xfonts)->ascent)
211 dc.font.ascent = (*xfonts)->ascent;
212 if(dc.font.descent < (*xfonts)->descent)
213 dc.font.descent = (*xfonts)->descent;
219 XFreeFont(dpy, dc.font.xfont);
220 dc.font.xfont = NULL;
221 dc.font.xfont = XLoadQueryFont(dpy, fontstr);
223 dc.font.xfont = XLoadQueryFont(dpy, "fixed");
225 eprint("error, cannot init 'fixed' font\n");
226 dc.font.ascent = dc.font.xfont->ascent;
227 dc.font.descent = dc.font.xfont->descent;
229 dc.font.height = dc.font.ascent + dc.font.descent;
235 return textnw(text, strlen(text)) + dc.font.height;