Xinqi Bao's Git
1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * (C)opyright MMVI-MMVII Sander van Dijk <a dot h dot vandijk at gmail dot com>
3 * See LICENSE file for license details.
11 drawtext(const char *text
, unsigned long col
[ColLast
]) {
14 unsigned int len
, olen
;
15 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
17 XSetForeground(dpy
, dc
.gc
, col
[ColBG
]);
18 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
22 olen
= len
= strlen(text
);
25 memcpy(buf
, text
, len
);
27 h
= dc
.font
.ascent
+ dc
.font
.descent
;
28 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
30 /* shorten text if necessary */
31 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
42 return; /* too long */
43 XSetForeground(dpy
, dc
.gc
, col
[ColFG
]);
45 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
47 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
51 textw(const char *text
) {
52 return textnw(text
, strlen(text
)) + dc
.font
.height
;
56 textnw(const char *text
, unsigned int len
) {
60 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
63 return XTextWidth(dc
.font
.xfont
, text
, len
);