widgetized bar labels, next is wmiimenu, then I can remove the outstanding crap from liblitz, afterwards I can enable the editable bars (read-only in first step)

This commit is contained in:
Anselm R. Garbe 2006-06-20 15:37:50 +02:00
parent 9eac7936bd
commit 03ea172fa4
5 changed files with 35 additions and 41 deletions

View File

@ -27,7 +27,9 @@ create_bar(Bar **b_link, char *name)
b->id = id++;
cext_strlcpy(b->name, name, sizeof(b->name));
b->color = def.normcolor;
b->bar = blitz_create_input(barpmap, bargc, &def.font);
b->bar->color = def.normcolor;
b->bar->align = CENTER;
for(i=b_link; *i; i=&(*i)->next)
if(strcmp((*i)->name, name) >= 0)
@ -41,11 +43,14 @@ create_bar(Bar **b_link, char *name)
void
destroy_bar(Bar **b_link, Bar *b)
{
Bar **i;
for(i=b_link; *i && *i != b; i=&(*i)->next);
*i = b->next;
Bar **p;
for(p=b_link; *p && *p != b; p=&(*p)->next);
*p = b->next;
b->next = free_bars;
if(b->bar->text)
free(b->bar->text);
blitz_destroy_input(b->bar);
free_bars = b;
}
@ -89,31 +94,21 @@ void
draw_bar()
{
unsigned int i = 0, w = 0, nb, size = 0;
BlitzDraw d = { 0 };
Bar *b = nil, *prev = nil;
d.gc = bargc;
d.drawable = barpmap;
d.rect = brect;
d.rect.x = d.rect.y = 0;
d.font = def.font;
d.color = def.normcolor;
blitz_drawlabel(&d);
blitz_drawborder(&d);
bartile->draw(bartile);
if(!lbar && !rbar)
goto MapBar;
for(b=lbar, nb=2 ;nb; --nb && (b = rbar))
for(; b && (w < brect.width); b=b->next, size++) {
b->rect.x = 0;
b->rect.y = 0;
b->rect.width = brect.height;
if(strlen(b->data))
b->rect.width += blitz_textwidth(&def.font, b->data);
b->rect.height = brect.height;
w += b->rect.width;
b->bar->rect.x = 0;
b->bar->rect.y = 0;
b->bar->rect.width = brect.height;
if(b->bar->text && strlen(b->bar->text))
b->bar->rect.width += blitz_textwidth(b->bar->font, b->bar->text);
b->bar->rect.height = brect.height;
w += b->bar->rect.width;
}
if(b) { /* give all bars same width */
@ -124,31 +119,24 @@ draw_bar()
w = brect.width / size;
for(b = lbar, nb=2 ;nb; b = rbar, nb--) {
for(; b; b=b->next) {
b->rect.x = i * w;
b->rect.width = w;
b->bar->rect.x = i * w;
b->bar->rect.width = w;
}
}
}
else { /* expand rbar properly */
if(rbar)
rbar->rect.width += (brect.width - w);
rbar->bar->rect.width += (brect.width - w);
for(b=lbar, nb=2 ;nb--; b = rbar)
for(; b; prev = b, b=b->next)
if(prev) b->rect.x = prev->rect.x + prev->rect.width;
if(prev) b->bar->rect.x = prev->bar->rect.x + prev->bar->rect.width;
}
for(b=lbar, nb=2 ;nb; b=rbar, nb--)
for(; b; b=b->next) {
d.color = b->color;
d.rect = b->rect;
d.data = b->data;
/* XXX: This is broken; everything shoult align EAST */
if(b == rbar)
d.align = EAST;
else
d.align = CENTER;
blitz_drawlabel(&d);
blitz_drawborder(&d);
b->bar->align = EAST;
b->bar->draw(b->bar);
}
MapBar:
XCopyArea(dpy, barpmap, barwin, bargc, 0, 0, brect.width, brect.height, 0, 0);

View File

@ -74,7 +74,7 @@ handle_buttonrelease(XEvent *e)
static char buf[32];
if(ev->window == barwin) {
for(b=lbar; b; b=b->next)
if(ispointinrect(ev->x, ev->y, &b->rect)) {
if(ispointinrect(ev->x, ev->y, &b->bar->rect)) {
snprintf(buf, sizeof(buf), "BarClick %s %d\n",
b->name, ev->button);
write_event(buf);

View File

@ -818,10 +818,12 @@ fs_clunk(Req *r) {
case FsFBar:
buf = f->bar->buf;
i = strlen(f->bar->buf);
parse_colors(&buf, &i, &f->bar->color);
parse_colors(&buf, &i, &f->bar->bar->color);
while(buf[i - 1] == '\n')
buf[--i] = '\0';
strncpy(f->bar->data, buf, 255);
if(f->bar->bar->text)
free(f->bar->bar->text);
f->bar->bar->text = strdup(buf);
draw_bar();
break;
case FsFEvent:

View File

@ -353,6 +353,10 @@ main(int argc, char *argv[])
barpmap = XCreatePixmap(dpy, barwin, brect.width, brect.height,
DefaultDepth(dpy, screen));
bartile = blitz_create_tile(barpmap, bargc);
bartile->rect = brect;
bartile->color = def.normcolor;
XMapRaised(dpy, barwin);
draw_bar();
scan_wins();
@ -362,6 +366,7 @@ main(int argc, char *argv[])
if(errstr)
fprintf(stderr, "wmii: fatal: %s\n", errstr);
blitz_destroy_tile(bartile);
ixp_server_close(&srv);
cleanup();
XCloseDisplay(dpy);

View File

@ -127,10 +127,8 @@ struct Bar {
Bar *next;
char buf[280];
char name[256];
char data[256];
BlitzColor color;
unsigned short id;
XRectangle rect;
BlitzWidget *bar;
};
typedef struct Rule Rule;
@ -196,6 +194,7 @@ Pixmap barpmap;
Window barwin;
GC bargc;
GC xorgc;
BlitzWidget *bartile;
XRectangle brect;
PackedQid root_qid;
Default def;