| @@ -121,12 +121,18 @@ const char* win_res(Display *dpy, const char *name, const char *def) |
| 121 | 121 | | } |
| 122 | 122 | | } |
| 123 | 123 | | |
| 124 | + | unsigned int win_luminance(const XftColor *col) |
| 125 | + | { |
| 126 | + | return (col->color.red + col->color.green + col->color.blue) / 3; |
| 127 | + | } |
| 128 | + | |
| 124 | 129 | | #define INIT_ATOM_(atom) \ |
| 125 | 130 | | atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False); |
| 126 | 131 | | |
| 127 | 132 | | void win_init(win_t *win) |
| 128 | 133 | | { |
| 129 | 134 | | win_env_t *e; |
| 135 | + | const char *bg, *fg; |
| 130 | 136 | | |
| 131 | 137 | | memset(win, 0, sizeof(win_t)); |
| 132 | 138 | | |
| @@ -146,15 +152,12 @@ void win_init(win_t *win) |
| 146 | 152 | | |
| 147 | 153 | | win_init_font(e, BAR_FONT); |
| 148 | 154 | | |
| 149 | | − | win_alloc_color(e, win_res(e->dpy, RES_CLASS ".background", WIN_BG_COLOR), |
| 150 | | − | &win->bgcol); |
| 151 | | − | win_alloc_color(e, WIN_FS_COLOR, &win->fscol); |
| 152 | | − | win_alloc_color(e, win_res(e->dpy, RES_CLASS ".foreground", SEL_COLOR), |
| 153 | | − | &win->selcol); |
| 154 | | − | win_alloc_color(e, win_res(e->dpy, RES_CLASS ".foreground", BAR_BG_COLOR), |
| 155 | | − | &win->bar.bgcol); |
| 156 | | − | win_alloc_color(e, win_res(e->dpy, RES_CLASS ".background", BAR_FG_COLOR), |
| 157 | | − | &win->bar.fgcol); |
| 155 | + | bg = win_res(e->dpy, RES_CLASS ".background", BG_COLOR); |
| 156 | + | fg = win_res(e->dpy, RES_CLASS ".foreground", FG_COLOR); |
| 157 | + | win_alloc_color(e, bg, &win->bg); |
| 158 | + | win_alloc_color(e, fg, &win->fg); |
| 159 | + | win_alloc_color(e, "black", &win->black); |
| 160 | + | win->light = win_luminance(&win->bg) > win_luminance(&win->fg); |
| 158 | 161 | | |
| 159 | 162 | | win->bar.l.size = BAR_L_LEN; |
| 160 | 163 | | win->bar.r.size = BAR_R_LEN; |
| @@ -294,7 +297,7 @@ void win_open(win_t *win) |
| 294 | 297 | | win->buf.h = e->scrh; |
| 295 | 298 | | win->buf.pm = XCreatePixmap(e->dpy, win->xwin, |
| 296 | 299 | | win->buf.w, win->buf.h, e->depth); |
| 297 | | − | XSetForeground(e->dpy, gc, fullscreen ? win->fscol.pixel : win->bgcol.pixel); |
| 300 | + | XSetForeground(e->dpy, gc, fullscreen ? win->black.pixel : win->bg.pixel); |
| 298 | 301 | | XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h); |
| 299 | 302 | | XSetWindowBackgroundPixmap(e->dpy, win->xwin, win->buf.pm); |
| 300 | 303 | | |
| @@ -386,14 +389,14 @@ void win_clear(win_t *win) |
| 386 | 389 | | win->buf.pm = XCreatePixmap(e->dpy, win->xwin, |
| 387 | 390 | | win->buf.w, win->buf.h, e->depth); |
| 388 | 391 | | } |
| 389 | | − | XSetForeground(e->dpy, gc, win->fullscreen ? win->fscol.pixel : win->bgcol.pixel); |
| 392 | + | XSetForeground(e->dpy, gc, win->fullscreen ? win->black.pixel : win->bg.pixel); |
| 390 | 393 | | XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h); |
| 391 | 394 | | } |
| 392 | 395 | | |
| 393 | 396 | | #define TEXTWIDTH(win, text, len) \ |
| 394 | 397 | | win_draw_text(win, NULL, NULL, 0, 0, text, len, 0) |
| 395 | 398 | | |
| 396 | | − | int win_draw_text(win_t *win, XftDraw *d, XftColor *color, int x, int y, |
| 399 | + | int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, int x, int y, |
| 397 | 400 | | char *text, int len, int w) |
| 398 | 401 | | { |
| 399 | 402 | | int err, tw = 0; |
| @@ -432,6 +435,7 @@ void win_draw_bar(win_t *win) |
| 432 | 435 | | win_env_t *e; |
| 433 | 436 | | win_bar_t *l, *r; |
| 434 | 437 | | XftDraw *d; |
| 438 | + | const XftColor *bg, *fg; |
| 435 | 439 | | |
| 436 | 440 | | if ((l = &win->bar.l)->buf == NULL || (r = &win->bar.r)->buf == NULL) |
| 437 | 441 | | return; |
| @@ -442,23 +446,28 @@ void win_draw_bar(win_t *win) |
| 442 | 446 | | d = XftDrawCreate(e->dpy, win->buf.pm, DefaultVisual(e->dpy, e->scr), |
| 443 | 447 | | DefaultColormap(e->dpy, e->scr)); |
| 444 | 448 | | |
| 445 | | − | XSetForeground(e->dpy, gc, win->bar.bgcol.pixel); |
| 449 | + | if (win->fullscreen && !win->light) |
| 450 | + | bg = &win->bg, fg = &win->fg; |
| 451 | + | else |
| 452 | + | bg = &win->fg, fg = &win->bg; |
| 453 | + | |
| 454 | + | XSetForeground(e->dpy, gc, bg->pixel); |
| 446 | 455 | | XFillRectangle(e->dpy, win->buf.pm, gc, 0, win->h, win->w, win->bar.h); |
| 447 | 456 | | |
| 448 | | − | XSetForeground(e->dpy, gc, win->bar.fgcol.pixel); |
| 449 | | − | XSetBackground(e->dpy, gc, win->bar.bgcol.pixel); |
| 457 | + | XSetForeground(e->dpy, gc, fg->pixel); |
| 458 | + | XSetBackground(e->dpy, gc, bg->pixel); |
| 450 | 459 | | |
| 451 | 460 | | if ((len = strlen(r->buf)) > 0) { |
| 452 | 461 | | if ((tw = TEXTWIDTH(win, r->buf, len)) > w) |
| 453 | 462 | | return; |
| 454 | 463 | | x = win->w - tw - H_TEXT_PAD; |
| 455 | 464 | | w -= tw; |
| 456 | | − | win_draw_text(win, d, &win->bar.fgcol, x, y, r->buf, len, tw); |
| 465 | + | win_draw_text(win, d, fg, x, y, r->buf, len, tw); |
| 457 | 466 | | } |
| 458 | 467 | | if ((len = strlen(l->buf)) > 0) { |
| 459 | 468 | | x = H_TEXT_PAD; |
| 460 | 469 | | w -= 2 * H_TEXT_PAD; /* gap between left and right parts */ |
| 461 | | − | win_draw_text(win, d, &win->bar.fgcol, x, y, l->buf, len, w); |
| 470 | + | win_draw_text(win, d, fg, x, y, l->buf, len, w); |
| 462 | 471 | | } |
| 463 | 472 | | XftDrawDestroy(d); |
| 464 | 473 | | } |