Align compile-time color options with X resource colors

Two colors are more than enough!
This commit is contained in:
Bert Münnich 2019-01-23 21:18:12 +01:00
parent 9d244da512
commit 919ada1123
5 changed files with 37 additions and 32 deletions

View File

@ -14,11 +14,8 @@ static const char * const BAR_FONT = "monospace:size=8";
/* colors:
* (see X(7) section "COLOR NAMES" for valid values)
*/
static const char * const WIN_BG_COLOR = "#555555";
static const char * const WIN_FS_COLOR = "#000000";
static const char * const SEL_COLOR = "#EEEEEE";
static const char * const BAR_BG_COLOR = "#222222";
static const char * const BAR_FG_COLOR = "#EEEEEE";
static const char * const BG_COLOR = "#555555";
static const char * const FG_COLOR = "#EEEEEE";
#endif
#ifdef _IMAGE_CONFIG

View File

@ -497,7 +497,7 @@ void img_render(img_t *img)
}
imlib_image_put_back_data(data);
} else {
c = win->fullscreen ? win->fscol.pixel : win->bgcol.pixel;
c = win->fullscreen ? win->black.pixel : win->bg.pixel;
imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF);
imlib_image_fill_rectangle(0, 0, dw, dh);
}

9
sxiv.h
View File

@ -408,9 +408,10 @@ struct win {
Window xwin;
win_env_t env;
XftColor bgcol;
XftColor fscol;
XftColor selcol;
bool light; /* bg is lighter than fg */
XftColor bg;
XftColor fg;
XftColor black;
int x;
int y;
@ -430,8 +431,6 @@ struct win {
unsigned int h;
win_bar_t l;
win_bar_t r;
XftColor bgcol;
XftColor fgcol;
} bar;
};

View File

@ -468,14 +468,14 @@ void tns_mark(tns_t *tns, int n, bool mark)
if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
win_t *win = tns->win;
thumb_t *t = &tns->thumbs[n];
unsigned long col = win->fullscreen ? win->fscol.pixel : win->bgcol.pixel;
unsigned long col = win->fullscreen ? win->black.pixel : win->bg.pixel;
int x = t->x + t->w, y = t->y + t->h;
win_draw_rect(win, x - 1, y + 1, 1, tns->bw, true, 1, col);
win_draw_rect(win, x + 1, y - 1, tns->bw, 1, true, 1, col);
if (mark)
col = win->selcol.pixel;
col = win->fullscreen && win->light ? win->bg.pixel : win->fg.pixel;
win_draw_rect(win, x, y, tns->bw + 2, tns->bw + 2, true, 1, col);
@ -493,9 +493,9 @@ void tns_highlight(tns_t *tns, int n, bool hl)
int oxy = (tns->bw + 1) / 2 + 1, owh = tns->bw + 2;
if (hl)
col = win->selcol.pixel;
col = win->fullscreen && win->light ? win->bg.pixel : win->fg.pixel;
else
col = win->fullscreen ? win->fscol.pixel : win->bgcol.pixel;
col = win->fullscreen ? win->black.pixel : win->bg.pixel;
win_draw_rect(win, t->x - oxy, t->y - oxy, t->w + owh, t->h + owh,
false, tns->bw, col);

View File

@ -121,12 +121,18 @@ const char* win_res(Display *dpy, const char *name, const char *def)
}
}
unsigned int win_luminance(const XftColor *col)
{
return (col->color.red + col->color.green + col->color.blue) / 3;
}
#define INIT_ATOM_(atom) \
atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False);
void win_init(win_t *win)
{
win_env_t *e;
const char *bg, *fg;
memset(win, 0, sizeof(win_t));
@ -146,15 +152,12 @@ void win_init(win_t *win)
win_init_font(e, BAR_FONT);
win_alloc_color(e, win_res(e->dpy, RES_CLASS ".background", WIN_BG_COLOR),
&win->bgcol);
win_alloc_color(e, WIN_FS_COLOR, &win->fscol);
win_alloc_color(e, win_res(e->dpy, RES_CLASS ".foreground", SEL_COLOR),
&win->selcol);
win_alloc_color(e, win_res(e->dpy, RES_CLASS ".foreground", BAR_BG_COLOR),
&win->bar.bgcol);
win_alloc_color(e, win_res(e->dpy, RES_CLASS ".background", BAR_FG_COLOR),
&win->bar.fgcol);
bg = win_res(e->dpy, RES_CLASS ".background", BG_COLOR);
fg = win_res(e->dpy, RES_CLASS ".foreground", FG_COLOR);
win_alloc_color(e, bg, &win->bg);
win_alloc_color(e, fg, &win->fg);
win_alloc_color(e, "black", &win->black);
win->light = win_luminance(&win->bg) > win_luminance(&win->fg);
win->bar.l.size = BAR_L_LEN;
win->bar.r.size = BAR_R_LEN;
@ -294,7 +297,7 @@ void win_open(win_t *win)
win->buf.h = e->scrh;
win->buf.pm = XCreatePixmap(e->dpy, win->xwin,
win->buf.w, win->buf.h, e->depth);
XSetForeground(e->dpy, gc, fullscreen ? win->fscol.pixel : win->bgcol.pixel);
XSetForeground(e->dpy, gc, fullscreen ? win->black.pixel : win->bg.pixel);
XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h);
XSetWindowBackgroundPixmap(e->dpy, win->xwin, win->buf.pm);
@ -386,14 +389,14 @@ void win_clear(win_t *win)
win->buf.pm = XCreatePixmap(e->dpy, win->xwin,
win->buf.w, win->buf.h, e->depth);
}
XSetForeground(e->dpy, gc, win->fullscreen ? win->fscol.pixel : win->bgcol.pixel);
XSetForeground(e->dpy, gc, win->fullscreen ? win->black.pixel : win->bg.pixel);
XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h);
}
#define TEXTWIDTH(win, text, len) \
win_draw_text(win, NULL, NULL, 0, 0, text, len, 0)
int win_draw_text(win_t *win, XftDraw *d, XftColor *color, int x, int y,
int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, int x, int y,
char *text, int len, int w)
{
int err, tw = 0;
@ -432,6 +435,7 @@ void win_draw_bar(win_t *win)
win_env_t *e;
win_bar_t *l, *r;
XftDraw *d;
const XftColor *bg, *fg;
if ((l = &win->bar.l)->buf == NULL || (r = &win->bar.r)->buf == NULL)
return;
@ -442,23 +446,28 @@ void win_draw_bar(win_t *win)
d = XftDrawCreate(e->dpy, win->buf.pm, DefaultVisual(e->dpy, e->scr),
DefaultColormap(e->dpy, e->scr));
XSetForeground(e->dpy, gc, win->bar.bgcol.pixel);
if (win->fullscreen && !win->light)
bg = &win->bg, fg = &win->fg;
else
bg = &win->fg, fg = &win->bg;
XSetForeground(e->dpy, gc, bg->pixel);
XFillRectangle(e->dpy, win->buf.pm, gc, 0, win->h, win->w, win->bar.h);
XSetForeground(e->dpy, gc, win->bar.fgcol.pixel);
XSetBackground(e->dpy, gc, win->bar.bgcol.pixel);
XSetForeground(e->dpy, gc, fg->pixel);
XSetBackground(e->dpy, gc, bg->pixel);
if ((len = strlen(r->buf)) > 0) {
if ((tw = TEXTWIDTH(win, r->buf, len)) > w)
return;
x = win->w - tw - H_TEXT_PAD;
w -= tw;
win_draw_text(win, d, &win->bar.fgcol, x, y, r->buf, len, tw);
win_draw_text(win, d, fg, x, y, r->buf, len, tw);
}
if ((len = strlen(l->buf)) > 0) {
x = H_TEXT_PAD;
w -= 2 * H_TEXT_PAD; /* gap between left and right parts */
win_draw_text(win, d, &win->bar.fgcol, x, y, l->buf, len, w);
win_draw_text(win, d, fg, x, y, l->buf, len, w);
}
XftDrawDestroy(d);
}