simplified BlitzBrush once again

This commit is contained in:
Anselm R. Garbe 2006-06-22 11:46:39 +02:00
parent 92b0faadc2
commit ff0f239614
7 changed files with 19 additions and 42 deletions

View File

@ -48,8 +48,6 @@ destroy_bar(Bar **b_link, Bar *b)
*p = b->next; *p = b->next;
b->next = free_bars; b->next = free_bars;
if(b->brush.text)
free(b->brush.text);
free_bars = b; free_bars = b;
} }
@ -105,8 +103,8 @@ draw_bar()
b->brush.rect.x = 0; b->brush.rect.x = 0;
b->brush.rect.y = 0; b->brush.rect.y = 0;
b->brush.rect.width = brect.height; b->brush.rect.width = brect.height;
if(b->brush.text && strlen(b->brush.text)) if(b->text && strlen(b->text))
b->brush.rect.width += blitz_textwidth(b->brush.font, b->brush.text); b->brush.rect.width += blitz_textwidth(b->brush.font, b->text);
b->brush.rect.height = brect.height; b->brush.rect.height = brect.height;
w += b->brush.rect.width; w += b->brush.rect.width;
} }
@ -136,7 +134,7 @@ draw_bar()
for(; b; b=b->next) { for(; b; b=b->next) {
if(b == rbar) if(b == rbar)
b->brush.align = EAST; b->brush.align = EAST;
blitz_draw_input(&b->brush); blitz_draw_input(&b->brush, b->text);
} }
MapBar: MapBar:
XCopyArea(blz.display, bbrush.drawable, barwin, bbrush.gc, 0, 0, XCopyArea(blz.display, bbrush.drawable, barwin, bbrush.gc, 0, 0,

View File

@ -512,7 +512,6 @@ resize_client(Client *c, XRectangle *r, Bool ignore_xcall)
else else
XMoveResizeWindow(blz.display, c->framewin, 2 * rect.width + f->rect.x, XMoveResizeWindow(blz.display, c->framewin, 2 * rect.width + f->rect.x,
f->rect.y, f->rect.width, f->rect.height); f->rect.y, f->rect.width, f->rect.height);
resize_frame(f);
} }
c->rect.x = def.border; c->rect.x = def.border;

View File

@ -30,9 +30,6 @@ create_frame(Area *a, Client *c)
f->tile.font = &def.font; f->tile.font = &def.font;
f->tile.color = def.normcolor; f->tile.color = def.normcolor;
f->tagbar = f->titlebar = f->posbar = f->tile; f->tagbar = f->titlebar = f->posbar = f->tile;
f->tile.notch = &c->rect;
f->tagbar.text = c->tags;
f->titlebar.text = c->name;
f->titlebar.align = WEST; f->titlebar.align = WEST;
f->tagbar.align = f->posbar.align = CENTER; f->tagbar.align = f->posbar.align = CENTER;
@ -79,8 +76,6 @@ destroy_frame(Frame *f)
Area *a = f->area; Area *a = f->area;
Frame **ft, *pr = nil; Frame **ft, *pr = nil;
if(f->posbar.text)
free(f->posbar.text);
for(ft=&c->frame; *ft && *ft != f; pr = *ft, ft=&(*ft)->cnext); for(ft=&c->frame; *ft && *ft != f; pr = *ft, ft=&(*ft)->cnext);
cext_assert(*ft == f); cext_assert(*ft == f);
*ft = f->cnext; *ft = f->cnext;
@ -138,7 +133,7 @@ update_frame_widget_colors(Frame *f)
} }
void void
resize_frame(Frame *f) draw_frame(Frame *f)
{ {
Frame *p; Frame *p;
@ -158,12 +153,9 @@ resize_frame(Frame *f)
snprintf(buf, sizeof(buf), "%s%d/%d", snprintf(buf, sizeof(buf), "%s%d/%d",
(f->area == f->area->view->area) ? "~" : "", fidx + 1, size); (f->area == f->area->view->area) ? "~" : "", fidx + 1, size);
if(f->posbar.text)
free(f->posbar.text);
f->posbar.text = strdup(buf);
w = f->posbar.rect.width = w = f->posbar.rect.width =
f->posbar.rect.height + blitz_textwidth(&def.font, f->posbar.text); f->posbar.rect.height + blitz_textwidth(&def.font, buf);
f->posbar.rect.x = f->rect.width - f->posbar.rect.width; f->posbar.rect.x = f->rect.width - f->posbar.rect.width;
@ -171,7 +163,7 @@ resize_frame(Frame *f)
f->tagbar.rect = f->posbar.rect; f->tagbar.rect = f->posbar.rect;
f->tagbar.rect.x = 0; f->tagbar.rect.x = 0;
f->tagbar.rect.width = f->tagbar.rect.width =
f->tagbar.rect.height + blitz_textwidth(&def.font, f->tagbar.text); f->tagbar.rect.height + blitz_textwidth(&def.font, f->client->tags);
if(f->tagbar.rect.width > f->rect.width / 3) if(f->tagbar.rect.width > f->rect.width / 3)
f->tagbar.rect.width = f->rect.width / 3; f->tagbar.rect.width = f->rect.width / 3;
@ -179,15 +171,11 @@ resize_frame(Frame *f)
f->titlebar.rect = f->tagbar.rect; f->titlebar.rect = f->tagbar.rect;
f->titlebar.rect.x = f->tagbar.rect.x + f->tagbar.rect.width; f->titlebar.rect.x = f->tagbar.rect.x + f->tagbar.rect.width;
f->titlebar.rect.width = f->rect.width - (f->tagbar.rect.width + f->posbar.rect.width); f->titlebar.rect.width = f->rect.width - (f->tagbar.rect.width + f->posbar.rect.width);
}
void blitz_draw_tile(&f->tile);
draw_frame(Frame *f) blitz_draw_input(&f->tagbar, f->client->tags);
{ blitz_draw_input(&f->titlebar, f->client->name);
blitz_draw_input(&f->tile); blitz_draw_input(&f->posbar, buf);
blitz_draw_input(&f->tagbar);
blitz_draw_input(&f->titlebar);
blitz_draw_input(&f->posbar);
} }
void void

View File

@ -828,9 +828,7 @@ fs_clunk(Req *r) {
parse_colors(&buf, &i, &f->bar->brush.color); parse_colors(&buf, &i, &f->bar->brush.color);
while(buf[i - 1] == '\n') while(buf[i - 1] == '\n')
buf[--i] = '\0'; buf[--i] = '\0';
if(f->bar->brush.text) cext_strlcpy(f->bar->text, buf, sizeof(f->bar->text));
free(f->bar->brush.text);
f->bar->brush.text = strdup(buf);
draw_bar(); draw_bar();
break; break;
case FsFEvent: case FsFEvent:

View File

@ -126,6 +126,7 @@ typedef struct Bar Bar;
struct Bar { struct Bar {
Bar *next; Bar *next;
char buf[280]; char buf[280];
char text[256];
char name[256]; char name[256];
unsigned short id; unsigned short id;
BlitzBrush brush; BlitzBrush brush;

View File

@ -134,40 +134,36 @@ draw_menu()
brush.rect.x = 0; brush.rect.x = 0;
brush.rect.y = 0; brush.rect.y = 0;
brush.color = normcolor; brush.color = normcolor;
brush.text = nil;
blitz_draw_tile(&brush); blitz_draw_tile(&brush);
/* print command */ /* print command */
if(!title || text[0]) { if(!title || text[0]) {
brush.text = text;
brush.color = normcolor; brush.color = normcolor;
cmdw = cwidth; cmdw = cwidth;
if(cmdw && item.size) if(cmdw && item.size)
brush.rect.width = cmdw; brush.rect.width = cmdw;
blitz_draw_input(&brush, text);
} }
else { else {
cmdw = twidth; cmdw = twidth;
brush.text = title;
brush.color = selcolor; brush.color = selcolor;
brush.rect.width = cmdw; brush.rect.width = cmdw;
blitz_draw_input(&brush, title);
} }
blitz_draw_input(&brush);
offx += brush.rect.width; offx += brush.rect.width;
brush.align = CENTER; brush.align = CENTER;
if(item.size) { if(item.size) {
brush.color = normcolor; brush.color = normcolor;
brush.text = prevoff < curroff ? "<" : nil;
brush.rect.x = offx; brush.rect.x = offx;
brush.rect.width = seek; brush.rect.width = seek;
offx += brush.rect.width; offx += brush.rect.width;
blitz_draw_input(&brush); blitz_draw_input(&brush, prevoff < curroff ? "<" : nil);
/* determine maximum items */ /* determine maximum items */
for(i = curroff; i < nextoff; i++) { for(i = curroff; i < nextoff; i++) {
brush.text = item.data[i];
brush.rect.x = offx; brush.rect.x = offx;
brush.rect.width = blitz_textwidth(brush.font, brush.text); brush.rect.width = blitz_textwidth(brush.font, item.data[i]);
if(brush.rect.width > irect.width / 3) if(brush.rect.width > irect.width / 3)
brush.rect.width = irect.width / 3; brush.rect.width = irect.width / 3;
brush.rect.width += irect.height; brush.rect.width += irect.height;
@ -175,15 +171,14 @@ draw_menu()
brush.color = selcolor; brush.color = selcolor;
else else
brush.color = normcolor; brush.color = normcolor;
blitz_draw_input(&brush); blitz_draw_input(&brush, item.data[i]);
offx += brush.rect.width; offx += brush.rect.width;
} }
brush.color = normcolor; brush.color = normcolor;
brush.text = item.size > nextoff ? ">" : nil;
brush.rect.x = irect.width - seek; brush.rect.x = irect.width - seek;
brush.rect.width = seek; brush.rect.width = seek;
blitz_draw_input(&brush); blitz_draw_input(&brush, item.size > nextoff ? ">" : nil);
} }
XCopyArea(blz.display, brush.drawable, win, brush.gc, 0, 0, irect.width, XCopyArea(blz.display, brush.drawable, win, brush.gc, 0, 0, irect.width,
irect.height, 0, 0); irect.height, 0, 0);

View File

@ -57,15 +57,13 @@ struct BlitzBrush {
BlitzAlign align; BlitzAlign align;
BlitzFont *font; BlitzFont *font;
XRectangle rect; /* relative rect */ XRectangle rect; /* relative rect */
XRectangle *notch; /* relative notch rect */
char *text;
}; };
/* color.c */ /* color.c */
int blitz_loadcolor(Blitz *blitz, BlitzColor *c); int blitz_loadcolor(Blitz *blitz, BlitzColor *c);
/* brush.c */ /* brush.c */
void blitz_draw_input(BlitzBrush *b); void blitz_draw_input(BlitzBrush *b, char *text);
void blitz_draw_tile(BlitzBrush *b); void blitz_draw_tile(BlitzBrush *b);
/* font.c */ /* font.c */