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>
20 drawtext(NULL, False, False);
22 if(arrange == floating) {
24 drawtext("~", False, False);
28 for(i = 0; i < TLast; i++) {
30 dc.w = textw(tags[i]);
31 drawtext(tags[i], i == tsel, True);
35 dc.w = textw(sel->name);
36 drawtext(sel->name, True, True);
39 dc.x = bx + bw - dc.w;
40 drawtext(stext, False, False);
42 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
47 draw_client(Client *c)
52 XUnmapWindow(dpy, c->title);
53 XSetWindowBorder(dpy, c->win, dc.fg);
57 XSetWindowBorder(dpy, c->win, dc.bg);
58 XMapWindow(dpy, c->title);
63 for(i = 0; i < TLast; i++) {
66 dc.w = textw(c->tags[i]);
67 drawtext(c->tags[i], False, True);
71 dc.w = textw(c->name);
72 drawtext(c->name, False, True);
73 XCopyArea(dpy, dc.drawable, c->title, dc.gc,
74 0, 0, c->tw, c->th, 0, 0);
82 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
83 XSetForeground(dpy, dc.gc, dc.border);
86 points[1].x = dc.w - 1;
89 points[2].y = dc.h - 1;
90 points[3].x = -(dc.w - 1);
93 points[4].y = -(dc.h - 1);
94 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
98 drawtext(const char *text, Bool invert, Bool border)
102 static char buf[256];
104 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
106 XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
107 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
117 if(len >= sizeof(buf))
118 len = sizeof(buf) - 1;
119 memcpy(buf, text, len);
122 h = dc.font.ascent + dc.font.descent;
123 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
126 /* shorten text if necessary */
127 while(len && (w = textnw(buf, len)) > dc.w - h)
131 return; /* too long */
133 gcv.foreground = invert ? dc.bg : dc.fg;
134 gcv.background = invert ? dc.fg : dc.bg;
136 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
137 XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
141 gcv.font = dc.font.xfont->fid;
142 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
143 XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
148 initcolor(const char *colstr)
151 Colormap cmap = DefaultColormap(dpy, screen);
153 XAllocNamedColor(dpy, cmap, colstr, &color, &color);
158 textnw(char *text, unsigned int len)
162 XmbTextExtents(dc.font.set, text, len, NULL, &r);
165 return XTextWidth(dc.font.xfont, text, len);
171 return textnw(text, strlen(text)) + dc.font.height;
175 initfont(const char *fontstr)
177 char **missing, *def;
181 setlocale(LC_ALL, "");
183 XFreeFontSet(dpy, dc.font.set);
184 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
187 fprintf(stderr, "missing fontset: %s\n", missing[n]);
188 XFreeStringList(missing);
190 XFreeFontSet(dpy, dc.font.set);
195 XFontSetExtents *font_extents;
196 XFontStruct **xfonts;
199 dc.font.ascent = dc.font.descent = 0;
200 font_extents = XExtentsOfFontSet(dc.font.set);
201 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
202 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
203 if(dc.font.ascent < (*xfonts)->ascent)
204 dc.font.ascent = (*xfonts)->ascent;
205 if(dc.font.descent < (*xfonts)->descent)
206 dc.font.descent = (*xfonts)->descent;
212 XFreeFont(dpy, dc.font.xfont);
213 dc.font.xfont = NULL;
214 dc.font.xfont = XLoadQueryFont(dpy, fontstr);
216 dc.font.xfont = XLoadQueryFont(dpy, "fixed");
218 error("error, cannot init 'fixed' font\n");
219 dc.font.ascent = dc.font.xfont->ascent;
220 dc.font.descent = dc.font.xfont->descent;
222 dc.font.height = dc.font.ascent + dc.font.descent;