diff --git a/bar.c b/bar.c index a9304e7..e620c40 100644 --- a/bar.c +++ b/bar.c @@ -19,7 +19,7 @@ static const int pal[] = {COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR #define MIN(a,b) ((a > b ? b : a)) int -draw (int x, int align, char *text) +draw (int x, int align, int fgcol, int bgcol, char *text) { int done = 0; int pos_x = x; @@ -38,7 +38,12 @@ draw (int x, int align, char *text) pos_x = bw - strw; 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 { 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); @@ -59,17 +64,18 @@ parse (char *text) int pos_x = 0; int align = 0; + int fgcol = 1; + int bgcol = 0; + xcb_clear_area (c, 0, win, 0, 0, bw, BAR_HEIGHT); for (;;) { 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++) { case 0x0: return; /* EOL */ case 0xA: return; /* NL */ - case 'f': if (*p == 'r') *p = '1'; if (isdigit (*p)) - 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)) - xcb_change_gc (c, gc, XCB_GC_BACKGROUND, (const uint32_t []){ pal[*p-'0'] }); p++; break; + case 'f': if (*p == 'r') *p = '1'; if (isdigit (*p)) { fgcol = *p-'0'; } p++; break; + case 'b': if (*p == 'r') *p = '0'; if (isdigit (*p)) { bgcol = *p-'0'; } p++; break; case 'l': align = 0; pos_x = 0; break; case 'c': align = 1; pos_x = 0; break; case 'r': align = 2; pos_x = 0; break; @@ -166,7 +172,7 @@ main (int argc, char **argv) xcb_flush (c); } /* There's no more data, but the user still wants to see it */ - while (permanent); + while (permanent) sleep(1); return 0; }