commit 859e7ff1656382788559e5918a4aa2f7a2416178
parent 25f2063d1ee2c070ccfe81309bcbaeaf3f7ffbff
Author: Kris Maglione <jg@suckless.org>
Date: Mon, 5 Feb 2007 19:25:29 -0500
Fixed horizontal centering in the bar/draw_label. Vertical centering still sucks.
Diffstat:
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/bar.c b/bar.c
@@ -73,7 +73,7 @@ draw_bar(WMScreen *s) {
for(b=s->lbar, nb=2 ;nb; --nb && (b = s->rbar))
for(; b; b=b->next) {
b->brush.rect.x = b->brush.rect.y = 0;
- b->brush.rect.width = def.font.height;
+ b->brush.rect.width = def.font.height & ~1;
if(b->text && strlen(b->text))
b->brush.rect.width += textwidth(b->brush.font, b->text);
b->brush.rect.height = s->brect.height;
diff --git a/draw.c b/draw.c
@@ -10,8 +10,8 @@ unsigned int
textwidth_l(BlitzFont *font, char *text, unsigned int len) {
if(font->set) {
XRectangle r;
- XmbTextExtents(font->set, text, len, nil, &r);
- return r.width;
+ XmbTextExtents(font->set, text, len, &r, nil);
+ return r.width - 1;
}
return XTextWidth(font->xfont, text, len);
}
@@ -88,6 +88,7 @@ draw_label(BlitzBrush *b, char *text) {
unsigned int x, y, w, h, len;
Bool shortened = False;
static char buf[2048];
+ XRectangle r = {0};
XGCValues gcv;
draw_tile(b);
@@ -101,7 +102,8 @@ draw_label(BlitzBrush *b, char *text) {
h = b->font->ascent + b->font->descent;
y = b->rect.y + b->rect.height / 2 - h / 2 + b->font->ascent;
/* shorten text if necessary */
- while(len && (w = textwidth(b->font, buf)) > b->rect.width - h) {
+ while(len
+ && (w = textwidth(b->font, buf)) > b->rect.width - (b->font->height & ~1)) {
buf[--len] = 0;
shortened = True;
}
@@ -116,12 +118,17 @@ draw_label(BlitzBrush *b, char *text) {
if (len > 1)
buf[len - 1] = '.';
}
+
+ if(b->font->set) {
+ XmbTextExtents(b->font->set, text, len, &r, nil);
+ }
+
switch (b->align) {
case EAST:
x = b->rect.x + b->rect.width - (w + (b->font->height / 2));
break;
default:
- x = b->rect.x + (b->font->height / 2);
+ x = b->rect.x + (b->font->height / 2) - r.x;
break;
}
if(b->font->set) {