1 /* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
7 #include <X11/Xlocale.h>
12 isoccupied(unsigned int t)
15 for(c = clients; c; c = c->next)
22 textnw(const char *text, unsigned int len) {
26 XmbTextExtents(dc.font.set, text, len, NULL, &r);
29 return XTextWidth(dc.font.xfont, text, len);
33 drawtext(const char *text, unsigned long col[ColLast], Bool hborder, Bool vborder) {
36 unsigned int len, olen;
38 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
40 XSetForeground(dpy, dc.gc, col[ColBG]);
41 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
45 olen = len = strlen(text);
48 memcpy(buf, text, len);
50 h = dc.font.ascent + dc.font.descent;
51 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
53 /* shorten text if necessary */
54 while(len && (w = textnw(buf, len)) > dc.w - h)
65 return; /* too long */
66 gcv.foreground = col[ColFG];
68 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
69 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
72 gcv.font = dc.font.xfont->fid;
73 XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
74 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
77 XDrawLine(dpy, dc.drawable, dc.gc, dc.x + 1, dc.y + 1, dc.x + 1, dc.y + dc.h - 1);
78 XDrawLine(dpy, dc.drawable, dc.gc, dc.x + dc.w - 2, dc.y + 1, dc.x + dc.w - 2, dc.y + dc.h - 1);
81 XDrawLine(dpy, dc.drawable, dc.gc, dc.x + 1, dc.y + 1, dc.x + dc.w - 2, dc.y + 1);
82 XDrawLine(dpy, dc.drawable, dc.gc, dc.x + 1, dc.y + dc.h - 2, dc.x + dc.w - 2, dc.y + dc.h - 2);
92 for(c = clients; c; c = getnext(c->next))
102 for(i = 0; i < ntags; i++) {
103 dc.w = textw(tags[i]);
105 drawtext(tags[i], dc.sel, sel && sel->tags[i], isoccupied(i));
107 drawtext(tags[i], dc.norm, sel && sel->tags[i], isoccupied(i));
111 drawtext(arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, dc.status, False, False);
119 drawtext(stext, dc.status, False, False);
120 if((dc.w = dc.x - x) > bh) {
122 drawtext(sel ? sel->name : NULL, sel ? dc.sel : dc.norm, False, False);
124 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
129 drawtitle(Client *c) {
130 if(c == sel && issel) {
132 XUnmapWindow(dpy, c->twin);
133 XSetWindowBorder(dpy, c->win, dc.sel[ColBG]);
136 XSetWindowBorder(dpy, c->win, dc.norm[ColBG]);
137 XMapWindow(dpy, c->twin);
140 drawtext(c->name, dc.norm, False,False);
141 XCopyArea(dpy, dc.drawable, c->twin, dc.gc, 0, 0, c->tw, c->th, 0, 0);
146 getcolor(const char *colstr) {
147 Colormap cmap = DefaultColormap(dpy, screen);
150 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
151 eprint("error, cannot allocate color '%s'\n", colstr);
156 setfont(const char *fontstr) {
157 char **missing, *def;
161 setlocale(LC_ALL, "");
163 XFreeFontSet(dpy, dc.font.set);
164 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
167 fprintf(stderr, "missing fontset: %s\n", missing[n]);
168 XFreeStringList(missing);
170 XFreeFontSet(dpy, dc.font.set);
175 XFontSetExtents *font_extents;
176 XFontStruct **xfonts;
178 dc.font.ascent = dc.font.descent = 0;
179 font_extents = XExtentsOfFontSet(dc.font.set);
180 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
181 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
182 if(dc.font.ascent < (*xfonts)->ascent)
183 dc.font.ascent = (*xfonts)->ascent;
184 if(dc.font.descent < (*xfonts)->descent)
185 dc.font.descent = (*xfonts)->descent;
191 XFreeFont(dpy, dc.font.xfont);
192 dc.font.xfont = NULL;
193 dc.font.xfont = XLoadQueryFont(dpy, fontstr);
195 dc.font.xfont = XLoadQueryFont(dpy, "fixed");
197 eprint("error, cannot init 'fixed' font\n");
198 dc.font.ascent = dc.font.xfont->ascent;
199 dc.font.descent = dc.font.xfont->descent;
201 dc.font.height = dc.font.ascent + dc.font.descent;
205 textw(const char *text) {
206 return textnw(text, strlen(text)) + dc.font.height;