Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
6 #define MIN(a, b) ((a) < (b) ? (a) : (b))
9 drawtext(DC
*dc
, const char *text
, unsigned long col
[ColLast
], Bool invert
) {
11 int i
, x
, y
, h
, len
, olen
;
12 XRectangle r
= { dc
->x
, dc
->y
, dc
->w
, dc
->h
};
14 XSetForeground(dc
->dpy
, dc
->gc
, col
[invert
? ColFG
: ColBG
]);
15 XFillRectangles(dc
->dpy
, dc
->drawable
, dc
->gc
, &r
, 1);
20 y
= dc
->y
+ ((h
+2) / 2) - (h
/ 2) + dc
->font
.ascent
;
22 /* shorten text if necessary */
23 for(len
= MIN(olen
, sizeof buf
); len
&& textnw(dc
, text
, len
) > dc
->w
- h
; len
--);
26 memcpy(buf
, text
, len
);
28 for(i
= len
; i
&& i
> len
- 3; buf
[--i
] = '.');
29 XSetForeground(dc
->dpy
, dc
->gc
, col
[invert
? ColBG
: ColFG
]);
31 XmbDrawString(dc
->dpy
, dc
->drawable
, dc
->font
.set
, dc
->gc
, x
, y
, buf
, len
);
33 XDrawString(dc
->dpy
, dc
->drawable
, dc
->gc
, x
, y
, buf
, len
);