Custom bar colors (#10)

* set bar and text colors independently

* change xresources to Program.class.resource

* rename color variables to win/bar_bg/fg

* change default bar colors to match window colors
This commit is contained in:
Guilherme Freire 2021-09-11 11:38:22 -03:00 committed by Berke Kocaoğlu
parent d8ec6f91a9
commit f7557c55b5
5 changed files with 34 additions and 22 deletions

View file

@ -500,7 +500,7 @@ void img_render(img_t *img)
}
imlib_image_put_back_data(data);
} else {
c = win->bg.pixel;
c = win->win_bg.pixel;
imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF);
imlib_image_fill_rectangle(0, 0, dw, dh);
}

14
sxiv.1
View file

@ -381,11 +381,17 @@ Zoom out.
.SH CONFIGURATION
The following X resources are supported:
.TP
.B background
Color of the window background and bar foreground
.B window.background
Color of the window background
.TP
.B foreground
Color of the window foreground and bar background
.B window.foreground
Color of the window foreground
.TP
.B bar.background
Color of the bar background. Defaults to window.foreground
.TP
.B bar.foreground
Color of the bar foreground. Defaults to window.background
.TP
.B font
Name of Xft bar font

6
sxiv.h
View file

@ -409,8 +409,10 @@ struct win {
Window xwin;
win_env_t env;
XftColor bg;
XftColor fg;
XftColor win_bg;
XftColor win_fg;
XftColor bar_bg;
XftColor bar_fg;
int x;
int y;

View file

@ -469,14 +469,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->bg.pixel;
unsigned long col = win->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->fg.pixel;
col = win->win_fg.pixel;
win_draw_rect(win, x, y, tns->bw + 2, tns->bw + 2, true, 1, col);
@ -490,7 +490,7 @@ void tns_highlight(tns_t *tns, int n, bool hl)
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 = hl ? win->fg.pixel : win->bg.pixel;
unsigned long col = hl ? win->win_fg.pixel : win->win_bg.pixel;
int oxy = (tns->bw + 1) / 2 + 1, owh = tns->bw + 2;
win_draw_rect(win, t->x - oxy, t->y - oxy, t->w + owh, t->h + owh,

View file

@ -93,7 +93,7 @@ const char* win_res(XrmDatabase db, const char *name, const char *def)
void win_init(win_t *win)
{
win_env_t *e;
const char *bg, *fg, *f;
const char *win_bg, *win_fg, *bar_bg, *bar_fg, *f;
char *res_man;
XrmDatabase db;
XVisualInfo vis;
@ -133,10 +133,14 @@ void win_init(win_t *win)
f = win_res(db, RES_CLASS ".font", "monospace-8");
win_init_font(e, f);
bg = win_res(db, RES_CLASS ".background", "white");
fg = win_res(db, RES_CLASS ".foreground", "black");
win_alloc_color(e, bg, &win->bg);
win_alloc_color(e, fg, &win->fg);
win_bg = win_res(db, RES_CLASS ".window.background", "white");
win_fg = win_res(db, RES_CLASS ".window.foreground", "black");
bar_bg = win_res(db, RES_CLASS ".bar.background", win_bg);
bar_fg = win_res(db, RES_CLASS ".bar.foreground", win_fg);
win_alloc_color(e, win_bg, &win->win_bg);
win_alloc_color(e, win_fg, &win->win_fg);
win_alloc_color(e, bar_bg, &win->bar_bg);
win_alloc_color(e, bar_fg, &win->bar_fg);
win->bar.l.size = BAR_L_LEN;
win->bar.r.size = BAR_R_LEN;
@ -297,7 +301,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, win->bg.pixel);
XSetForeground(e->dpy, gc, win->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);
@ -379,7 +383,7 @@ 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->bg.pixel);
XSetForeground(e->dpy, gc, win->win_bg.pixel);
XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h);
}
@ -436,23 +440,23 @@ void win_draw_bar(win_t *win)
d = XftDrawCreate(e->dpy, win->buf.pm, e->vis,
e->cmap);
XSetForeground(e->dpy, gc, win->fg.pixel);
XSetForeground(e->dpy, gc, win->bar_bg.pixel);
XFillRectangle(e->dpy, win->buf.pm, gc, 0, win->h, win->w, win->bar.h);
XSetForeground(e->dpy, gc, win->bg.pixel);
XSetBackground(e->dpy, gc, win->fg.pixel);
XSetForeground(e->dpy, gc, win->win_bg.pixel);
XSetBackground(e->dpy, gc, win->bar_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->bg, x, y, r->buf, len, tw);
win_draw_text(win, d, &win->bar_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->bg, x, y, l->buf, len, w);
win_draw_text(win, d, &win->bar_fg, x, y, l->buf, len, w);
}
XftDrawDestroy(d);
}