Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
8 drawtext(const char *text
, unsigned long col
[ColLast
]) {
11 unsigned int len
, olen
;
12 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
14 XSetForeground(dpy
, dc
.gc
, col
[ColBG
]);
15 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
19 olen
= len
= strlen(text
);
22 memcpy(buf
, text
, len
);
24 h
= dc
.font
.ascent
+ dc
.font
.descent
;
25 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
27 /* shorten text if necessary */
28 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
39 return; /* too long */
40 XSetForeground(dpy
, dc
.gc
, col
[ColFG
]);
42 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
44 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
48 textw(const char *text
) {
49 return textnw(text
, strlen(text
)) + dc
.font
.height
;
53 textnw(const char *text
, unsigned int len
) {
57 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
60 return XTextWidth(dc
.font
.xfont
, text
, len
);