Fill the whole bar with the bg color. Yield when idling.

This commit is contained in:
LemonBoy 2012-07-16 14:29:05 +02:00
parent b1e71d2866
commit cb7597052b

22
bar.c
View File

@ -19,7 +19,7 @@ static const int pal[] = {COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR
#define MIN(a,b) ((a > b ? b : a)) #define MIN(a,b) ((a > b ? b : a))
int int
draw (int x, int align, char *text) draw (int x, int align, int fgcol, int bgcol, char *text)
{ {
int done = 0; int done = 0;
int pos_x = x; int pos_x = x;
@ -38,7 +38,12 @@ draw (int x, int align, char *text)
pos_x = bw - strw; pos_x = bw - strw;
break; break;
} }
/* Setup the colors */
xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[fgcol] });
xcb_change_gc (c, gc, XCB_GC_BACKGROUND, (const uint32_t []){ pal[bgcol] });
xcb_change_window_attributes (c, win, XCB_CW_BACK_PIXEL, (const uint32_t []){ pal[bgcol] });
/* Draw the background first */
xcb_clear_area (c, 0, win, pos_x, 0, strw, BAR_HEIGHT);
do { do {
xcb_image_text_8 (c, MIN(len - done, 255), win, gc, pos_x, bh - ft_height / 2, text + done); /* Bottom-left coords */ xcb_image_text_8 (c, MIN(len - done, 255), win, gc, pos_x, bh - ft_height / 2, text + done); /* Bottom-left coords */
done += MIN(len - done, 255); done += MIN(len - done, 255);
@ -59,17 +64,18 @@ parse (char *text)
int pos_x = 0; int pos_x = 0;
int align = 0; int align = 0;
int fgcol = 1;
int bgcol = 0;
xcb_clear_area (c, 0, win, 0, 0, bw, BAR_HEIGHT); xcb_clear_area (c, 0, win, 0, 0, bw, BAR_HEIGHT);
for (;;) { for (;;) {
if (*p == 0x0 || *p == 0xA || (*p == '\\' && p++ && *p != '\\' && strchr ("fblcr", *p))) { if (*p == 0x0 || *p == 0xA || (*p == '\\' && p++ && *p != '\\' && strchr ("fblcr", *p))) {
pos_x += draw (pos_x, align, parsed_text); pos_x += draw (pos_x, align, fgcol, bgcol, parsed_text);
switch (*p++) { switch (*p++) {
case 0x0: return; /* EOL */ case 0x0: return; /* EOL */
case 0xA: return; /* NL */ case 0xA: return; /* NL */
case 'f': if (*p == 'r') *p = '1'; if (isdigit (*p)) case 'f': if (*p == 'r') *p = '1'; if (isdigit (*p)) { fgcol = *p-'0'; } p++; break;
xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[*p-'0'] }); p++; break; case 'b': if (*p == 'r') *p = '0'; if (isdigit (*p)) { bgcol = *p-'0'; } p++; break;
case 'b': if (*p == 'r') *p = '0'; if (isdigit (*p))
xcb_change_gc (c, gc, XCB_GC_BACKGROUND, (const uint32_t []){ pal[*p-'0'] }); p++; break;
case 'l': align = 0; pos_x = 0; break; case 'l': align = 0; pos_x = 0; break;
case 'c': align = 1; pos_x = 0; break; case 'c': align = 1; pos_x = 0; break;
case 'r': align = 2; pos_x = 0; break; case 'r': align = 2; pos_x = 0; break;
@ -166,7 +172,7 @@ main (int argc, char **argv)
xcb_flush (c); xcb_flush (c);
} }
/* There's no more data, but the user still wants to see it */ /* There's no more data, but the user still wants to see it */
while (permanent); while (permanent) sleep(1);
return 0; return 0;
} }