Xinqi Bao's Git
1 /* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
2 * © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
3 * See LICENSE file for license details. */
10 drawtext(const char *text
, unsigned long col
[ColLast
]) {
13 unsigned int len
, olen
;
14 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
16 XSetForeground(dpy
, dc
.gc
, col
[ColBG
]);
17 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
21 olen
= len
= strlen(text
);
24 memcpy(buf
, text
, len
);
26 h
= dc
.font
.ascent
+ dc
.font
.descent
;
27 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
29 /* shorten text if necessary */
30 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
41 return; /* too long */
42 XSetForeground(dpy
, dc
.gc
, col
[ColFG
]);
44 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
46 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
50 textw(const char *text
) {
51 return textnw(text
, strlen(text
)) + dc
.font
.height
;
55 textnw(const char *text
, unsigned int len
) {
59 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
62 return XTextWidth(dc
.font
.xfont
, text
, len
);