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>
17 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
18 XSetForeground(dpy, dc.gc, dc.border);
21 points[1].x = dc.w - 1;
24 points[2].y = dc.h - 1;
25 points[3].x = -(dc.w - 1);
28 points[4].y = -(dc.h - 1);
29 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
33 textnw(const char *text, unsigned int len)
38 XmbTextExtents(dc.font.set, text, len, NULL, &r);
41 return XTextWidth(dc.font.xfont, text, len);
45 drawtext(const char *text, Bool invert)
51 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
53 XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
54 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
62 if(len >= sizeof(buf))
63 len = sizeof(buf) - 1;
64 memcpy(buf, text, len);
67 h = dc.font.ascent + dc.font.descent;
68 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
71 /* shorten text if necessary */
72 while(len && (w = textnw(buf, len)) > dc.w - h)
76 return; /* too long */
78 gcv.foreground = invert ? dc.bg : dc.fg;
79 gcv.background = invert ? dc.fg : dc.bg;
81 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
82 XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
86 gcv.font = dc.font.xfont->fid;
87 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
88 XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
99 for(c = clients; c; c = getnext(c->next))
108 Bool istile = arrange == dotile;
112 drawtext(NULL, !istile);
115 for(i = 0; i < ntags; i++) {
117 dc.w = textw(tags[i]);
119 drawtext(tags[i], (i == tsel));
121 drawtext(tags[i], (i != tsel));
125 dc.x = bx + bw - dc.w;
126 drawtext(stext, !istile);
127 if(sel && ((dc.w = dc.x - x) >= bh)) {
129 drawtext(sel->name, istile);
131 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
139 Bool istile = arrange == dotile;
143 XUnmapWindow(dpy, c->title);
144 XSetWindowBorder(dpy, c->win, dc.fg);
148 XSetWindowBorder(dpy, c->win, dc.bg);
149 XMapWindow(dpy, c->title);
154 for(i = 0; i < ntags; i++) {
157 dc.w = textw(tags[i]);
158 drawtext(tags[i], !istile);
162 dc.w = textw(c->name);
163 drawtext(c->name, !istile);
164 XCopyArea(dpy, dc.drawable, c->title, dc.gc, 0, 0, c->tw, c->th, 0, 0);
169 getcolor(const char *colstr)
171 Colormap cmap = DefaultColormap(dpy, screen);
174 XAllocNamedColor(dpy, cmap, colstr, &color, &color);
179 setfont(const char *fontstr)
181 char **missing, *def;
185 setlocale(LC_ALL, "");
187 XFreeFontSet(dpy, dc.font.set);
188 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
191 fprintf(stderr, "missing fontset: %s\n", missing[n]);
192 XFreeStringList(missing);
194 XFreeFontSet(dpy, dc.font.set);
199 XFontSetExtents *font_extents;
200 XFontStruct **xfonts;
203 dc.font.ascent = dc.font.descent = 0;
204 font_extents = XExtentsOfFontSet(dc.font.set);
205 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
206 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
207 if(dc.font.ascent < (*xfonts)->ascent)
208 dc.font.ascent = (*xfonts)->ascent;
209 if(dc.font.descent < (*xfonts)->descent)
210 dc.font.descent = (*xfonts)->descent;
216 XFreeFont(dpy, dc.font.xfont);
217 dc.font.xfont = NULL;
218 dc.font.xfont = XLoadQueryFont(dpy, fontstr);
220 dc.font.xfont = XLoadQueryFont(dpy, "fixed");
222 eprint("error, cannot init 'fixed' font\n");
223 dc.font.ascent = dc.font.xfont->ascent;
224 dc.font.descent = dc.font.xfont->descent;
226 dc.font.height = dc.font.ascent + dc.font.descent;
230 textw(const char *text)
232 return textnw(text, strlen(text)) + dc.font.height;