Xinqi Bao's Git
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>
13 textnw(const char *text
, unsigned int len
)
18 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
21 return XTextWidth(dc
.font
.xfont
, text
, len
);
30 points
[1].x
= dc
.w
- 1;
33 points
[2].y
= dc
.h
- 1;
34 points
[3].x
= -(dc
.w
- 1);
37 points
[4].y
= -(dc
.h
- 1);
38 XDrawLines(dpy
, dc
.drawable
, dc
.gc
, points
, 5, CoordModePrevious
);
42 drawtext(const char *text
, Bool invert
, Bool highlight
)
46 unsigned int len
, olen
;
49 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
51 XSetForeground(dpy
, dc
.gc
, invert
? dc
.fg
: dc
.bg
);
52 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
53 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
54 XSetForeground(dpy
, dc
.gc
, dc
.border
);
61 olen
= len
= strlen(text
);
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
)
84 return; /* too long */
85 gcv
.foreground
= invert
? dc
.bg
: dc
.fg
;
86 gcv
.background
= invert
? dc
.fg
: dc
.bg
;
88 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
, &gcv
);
89 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
92 gcv
.font
= dc
.font
.xfont
->fid
;
93 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
| GCFont
, &gcv
);
94 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
114 for(c
= clients
; c
; c
= getnext(c
->next
))
123 Bool istile
= arrange
== dotile
;
127 drawtext(NULL
, !istile
, False
);
130 for(i
= 0; i
< ntags
; i
++) {
132 dc
.w
= textw(tags
[i
]);
134 drawtext(tags
[i
], seltag
[i
], sel
&& sel
->tags
[i
]);
136 drawtext(tags
[i
], !seltag
[i
], sel
&& sel
->tags
[i
]);
140 dc
.x
= bx
+ bw
- dc
.w
;
145 drawtext(stext
, !istile
, False
);
147 if(sel
&& ((dc
.w
= dc
.x
- x
) > bh
)) {
149 drawtext(sel
->name
, istile
, False
);
151 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, bw
, bh
, 0, 0);
159 Bool istile
= arrange
== dotile
;
161 if(c
== sel
&& issel
) {
163 XUnmapWindow(dpy
, c
->twin
);
164 XSetWindowBorder(dpy
, c
->win
, dc
.fg
);
168 XSetWindowBorder(dpy
, c
->win
, dc
.bg
);
169 XMapWindow(dpy
, c
->twin
);
172 drawtext(c
->name
, !istile
, False
);
173 XCopyArea(dpy
, dc
.drawable
, c
->twin
, dc
.gc
, 0, 0, c
->tw
, c
->th
, 0, 0);
178 getcolor(const char *colstr
)
180 Colormap cmap
= DefaultColormap(dpy
, screen
);
183 XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
);
188 setfont(const char *fontstr
)
190 char **missing
, *def
;
194 setlocale(LC_ALL
, "");
196 XFreeFontSet(dpy
, dc
.font
.set
);
197 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
200 fprintf(stderr
, "missing fontset: %s\n", missing
[n
]);
201 XFreeStringList(missing
);
203 XFreeFontSet(dpy
, dc
.font
.set
);
208 XFontSetExtents
*font_extents
;
209 XFontStruct
**xfonts
;
212 dc
.font
.ascent
= dc
.font
.descent
= 0;
213 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
214 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
215 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
216 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
217 dc
.font
.ascent
= (*xfonts
)->ascent
;
218 if(dc
.font
.descent
< (*xfonts
)->descent
)
219 dc
.font
.descent
= (*xfonts
)->descent
;
225 XFreeFont(dpy
, dc
.font
.xfont
);
226 dc
.font
.xfont
= NULL
;
227 dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
);
229 dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed");
231 eprint("error, cannot init 'fixed' font\n");
232 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
233 dc
.font
.descent
= dc
.font
.xfont
->descent
;
235 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
239 textw(const char *text
)
241 return textnw(text
, strlen(text
)) + dc
.font
.height
;