[hackers] wmii: new tip (= 1752)

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Tue, 06 Feb 2007 01:30:03 +0100

changeset: 1752:b6a27aa09d7a
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Mon Feb 05 19:25:29 2007 -0500
files: bar.c draw.c
description:
Fixed horizontal centering in the bar/draw_label. Vertical centering still sucks.

diff -r 96114c33427a -r b6a27aa09d7a bar.c
--- a/bar.c Mon Feb 05 20:41:59 2007 +0100
+++ b/bar.c Mon Feb 05 19:25:29 2007 -0500
@@ -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 -r 96114c33427a -r b6a27aa09d7a draw.c
--- a/draw.c Mon Feb 05 20:41:59 2007 +0100
+++ b/draw.c Mon Feb 05 19:25:29 2007 -0500
@@ -10,8 +10,8 @@ textwidth_l(BlitzFont *font, char *text,
 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) {
Received on Tue Feb 06 2007 - 01:30:04 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:54:55 UTC