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
);
25 drawtext(const char *text
, Bool invert
)
32 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
34 XSetForeground(dpy
, dc
.gc
, invert
? dc
.fg
: dc
.bg
);
35 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
41 if(len
>= sizeof(buf
))
42 len
= sizeof(buf
) - 1;
43 memcpy(buf
, text
, len
);
46 h
= dc
.font
.ascent
+ dc
.font
.descent
;
47 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
50 /* shorten text if necessary */
51 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
55 return; /* too long */
57 gcv
.foreground
= invert
? dc
.bg
: dc
.fg
;
58 gcv
.background
= invert
? dc
.fg
: dc
.bg
;
60 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
, &gcv
);
61 XmbDrawImageString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
,
65 gcv
.font
= dc
.font
.xfont
->fid
;
66 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
| GCFont
, &gcv
);
67 XDrawImageString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
70 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
73 points
[1].x
= dc
.w
- 1;
76 points
[2].y
= dc
.h
- 1;
77 points
[3].x
= -(dc
.w
- 1);
80 points
[4].y
= -(dc
.h
- 1);
81 XDrawLines(dpy
, dc
.drawable
, dc
.gc
, points
, 5, CoordModePrevious
);
91 for(c
= clients
; c
; c
= getnext(c
->next
))
100 Bool istile
= arrange
== dotile
;
104 drawtext(NULL
, !istile
);
107 for(i
= 0; i
< ntags
; i
++) {
109 dc
.w
= textw(tags
[i
]);
111 drawtext(tags
[i
], (i
== tsel
));
113 drawtext(tags
[i
], (i
!= tsel
));
117 dc
.x
= bx
+ bw
- dc
.w
;
118 drawtext(stext
, !istile
);
119 if(sel
&& ((dc
.w
= dc
.x
- x
) >= bh
)) {
121 drawtext(sel
->name
, istile
);
123 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, bw
, bh
, 0, 0);
131 Bool istile
= arrange
== dotile
;
135 XUnmapWindow(dpy
, c
->title
);
136 XSetWindowBorder(dpy
, c
->win
, dc
.fg
);
140 XSetWindowBorder(dpy
, c
->win
, dc
.bg
);
141 XMapWindow(dpy
, c
->title
);
146 for(i
= 0; i
< ntags
; i
++) {
149 dc
.w
= textw(tags
[i
]);
150 drawtext(tags
[i
], !istile
);
154 dc
.w
= textw(c
->name
);
155 drawtext(c
->name
, !istile
);
156 XCopyArea(dpy
, dc
.drawable
, c
->title
, dc
.gc
, 0, 0, c
->tw
, c
->th
, 0, 0);
161 getcolor(const char *colstr
)
163 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 textw(const char *text
)
224 return textnw(text
, strlen(text
)) + dc
.font
.height
;