changed bar drawing, the top-right label's text is east-aligned and uses the available space, thus it is expanded

This commit is contained in:
Anselm R. Garbe 2006-03-26 16:37:03 +02:00
parent e64403e90c
commit a17657c62a
2 changed files with 27 additions and 36 deletions

View File

@ -13,6 +13,10 @@ comp_label(const void *l1, const void *l2)
{
Label *ll1 = *(Label **)l1;
Label *ll2 = *(Label **)l2;
if(ll1->intern && !ll2->intern)
return -1;
if(!ll1->intern && ll2->intern)
return 1;
return strcmp(ll1->name, ll2->name);
}
@ -80,11 +84,11 @@ update_bar_geometry()
void
draw_bar()
{
unsigned int i = 0, n = 0, x = 0, w = 0;
unsigned int i = 0, x = 0;
Draw d = { 0 };
Label *l = nil;
d.align = WEST;
d.align = CENTER;
d.gc = bargc;
d.drawable = barpmap;
d.rect = brect;
@ -97,55 +101,41 @@ draw_bar()
if(!nlabel)
return;
for(i = 0; (i < nlabel) && label[i]->intern; i++) {
for(i = 0; (i < nlabel) && (x < brect.width); i++) {
l = label[i];
if(nview && !strncmp(l->data, def.tag, sizeof(l->data)))
l->color = def.sel;
else
l->color = def.norm;
if(l->intern) {
if(nview && !strncmp(l->name, def.tag, sizeof(l->name)))
l->color = def.sel;
else
l->color = def.norm;
}
l->rect.y = 0;
l->rect.x = x;
l->rect.width = l->rect.height = brect.height;
l->rect.width = brect.height;
if(strlen(l->name))
l->rect.width += XTextWidth(xfont, l->name, strlen(l->name));
l->rect.width += XTextWidth(xfont, l->data, strlen(l->data));
l->rect.height = brect.height;
x += l->rect.width;
}
if(i)
n = i;
for(; i < nlabel; i++) {
l = label[i];
l->rect.x = x;
l->rect.y = 0;
l->rect.height = brect.height;
l->rect.width = brect.height;
if(strlen(l->data))
l->rect.width += XTextWidth(xfont, l->data, strlen(l->data));
w += l->rect.width;
}
if(w >= brect.width - x) {
/* failsafe mode, give all labels same width */
w = (brect.width - x) / (nlabel - n);
for(i = n; i < nlabel; i++) {
if(i != nlabel) { /* give all labels same width */
unsigned int w = brect.width / nlabel;
for(i = 0; i < nlabel; i++) {
l = label[i];
l->rect.x = x + i * w;
l->rect.x = i * w;
l->rect.width = w;
}
i--;
label[i]->rect.width = brect.width - label[i]->rect.x;
}
else if(n < nlabel) {
label[n]->rect.x = brect.width - w;
for(i = n + 1; i < nlabel; i++)
label[i]->rect.x = label[i - 1]->rect.x + label[i - 1]->rect.width;
}
label[nlabel - 1]->rect.width = brect.width - label[nlabel - 1]->rect.x;
for(i = 0; i < nlabel; i++) {
l = label[i];
d.color = l->color;
d.rect = l->rect;
d.data = l->data;
if(i + 1 == nlabel)
d.align = EAST;
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
}

View File

@ -197,7 +197,7 @@ update_client_property(Client *c, XPropertyEvent *e)
cext_strlcpy(c->name, (char*) name.value, sizeof(c->name));
free(name.value);
}
if(c->frame)
if(c->nframe)
draw_client(c);
break;
case XA_WM_TRANSIENT_FOR:
@ -221,7 +221,6 @@ draw_client(Client *c)
if(!c->nframe)
return; /* might not have been attached atm */
d.align = WEST;
d.drawable = c->framewin;
d.font = xfont;
d.gc = c->gc;
@ -245,6 +244,7 @@ draw_client(Client *c)
d.notch = nil;
tags2str(buf, sizeof(buf), c->tag, c->ntag);
d.align = WEST;
d.rect.x = d.rect.height + XTextWidth(xfont, buf, strlen(buf));
d.rect.width = c->frame[c->sel]->rect.width - d.rect.x;
d.data = c->name;
@ -257,6 +257,7 @@ draw_client(Client *c)
d.color.fg = d.color.bg;
d.color.bg = tmp;
}
d.align = CENTER;
d.rect.width = d.rect.x;
d.rect.x = 0;
d.data = buf;