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>
11 /* static functions */
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);
32 /* extern functions */
39 for(c = clients; c; c = getnext(c->next))
48 Bool istile = arrange == dotile;
52 drawtext(NULL, !istile, False);
55 for(i = 0; i < TLast; i++) {
57 dc.w = textw(tags[i]);
59 drawtext(tags[i], (i == tsel), True);
61 drawtext(tags[i], (i != tsel), True);
65 dc.w = textw(sel->name);
66 drawtext(sel->name, istile, True);
69 dc.x = bx + bw - dc.w;
70 drawtext(stext, !istile, False);
72 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
77 drawtext(const char *text, Bool invert, Bool border)
83 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
85 XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
86 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
96 if(len >= sizeof(buf))
97 len = sizeof(buf) - 1;
98 memcpy(buf, text, len);
101 h = dc.font.ascent + dc.font.descent;
102 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
105 /* shorten text if necessary */
106 while(len && (w = textnw(buf, len)) > dc.w - h)
110 return; /* too long */
112 gcv.foreground = invert ? dc.bg : dc.fg;
113 gcv.background = invert ? dc.fg : dc.bg;
115 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
116 XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
120 gcv.font = dc.font.xfont->fid;
121 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
122 XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
130 Bool istile = arrange == dotile;
134 XUnmapWindow(dpy, c->title);
135 XSetWindowBorder(dpy, c->win, dc.fg);
139 XSetWindowBorder(dpy, c->win, dc.bg);
140 XMapWindow(dpy, c->title);
145 for(i = 0; i < TLast; i++) {
148 dc.w = textw(c->tags[i]);
149 drawtext(c->tags[i], !istile, True);
153 dc.w = textw(c->name);
154 drawtext(c->name, !istile, True);
155 XCopyArea(dpy, dc.drawable, c->title, dc.gc,
156 0, 0, c->tw, c->th, 0, 0);
161 getcolor(const char *colstr)
164 Colormap cmap = DefaultColormap(dpy, screen);
166 XAllocNamedColor(dpy, cmap, colstr, &color, &color);
171 setfont(const char *fontstr)
173 char **missing, *def;
177 setlocale(LC_ALL, "");
179 XFreeFontSet(dpy, dc.font.set);
180 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
183 fprintf(stderr, "missing fontset: %s\n", missing[n]);
184 XFreeStringList(missing);
186 XFreeFontSet(dpy, dc.font.set);
191 XFontSetExtents *font_extents;
192 XFontStruct **xfonts;
195 dc.font.ascent = dc.font.descent = 0;
196 font_extents = XExtentsOfFontSet(dc.font.set);
197 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
198 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
199 if(dc.font.ascent < (*xfonts)->ascent)
200 dc.font.ascent = (*xfonts)->ascent;
201 if(dc.font.descent < (*xfonts)->descent)
202 dc.font.descent = (*xfonts)->descent;
208 XFreeFont(dpy, dc.font.xfont);
209 dc.font.xfont = NULL;
210 dc.font.xfont = XLoadQueryFont(dpy, fontstr);
212 dc.font.xfont = XLoadQueryFont(dpy, "fixed");
214 eprint("error, cannot init 'fixed' font\n");
215 dc.font.ascent = dc.font.xfont->ascent;
216 dc.font.descent = dc.font.xfont->descent;
218 dc.font.height = dc.font.ascent + dc.font.descent;
222 textnw(char *text, unsigned int len)
226 XmbTextExtents(dc.font.set, text, len, NULL, &r);
229 return XTextWidth(dc.font.xfont, text, len);
235 return textnw(text, strlen(text)) + dc.font.height;