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); imlib_image_put_back_data(data);
} else { } else {
c = win->bg.pixel; c = win->win_bg.pixel;
imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF); imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF);
imlib_image_fill_rectangle(0, 0, dw, dh); imlib_image_fill_rectangle(0, 0, dw, dh);
} }

14
sxiv.1
View File

@ -381,11 +381,17 @@ Zoom out.
.SH CONFIGURATION .SH CONFIGURATION
The following X resources are supported: The following X resources are supported:
.TP .TP
.B background .B window.background
Color of the window background and bar foreground Color of the window background
.TP .TP
.B foreground .B window.foreground
Color of the window foreground and bar background 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 .TP
.B font .B font
Name of Xft bar font Name of Xft bar font

6
sxiv.h
View File

@ -409,8 +409,10 @@ struct win {
Window xwin; Window xwin;
win_env_t env; win_env_t env;
XftColor bg; XftColor win_bg;
XftColor fg; XftColor win_fg;
XftColor bar_bg;
XftColor bar_fg;
int x; int x;
int y; 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) { if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
win_t *win = tns->win; win_t *win = tns->win;
thumb_t *t = &tns->thumbs[n]; 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; 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, 1, tns->bw, true, 1, col);
win_draw_rect(win, x + 1, y - 1, tns->bw, 1, true, 1, col); win_draw_rect(win, x + 1, y - 1, tns->bw, 1, true, 1, col);
if (mark) 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); 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) { if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
win_t *win = tns->win; win_t *win = tns->win;
thumb_t *t = &tns->thumbs[n]; 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; 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, 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) void win_init(win_t *win)
{ {
win_env_t *e; win_env_t *e;
const char *bg, *fg, *f; const char *win_bg, *win_fg, *bar_bg, *bar_fg, *f;
char *res_man; char *res_man;
XrmDatabase db; XrmDatabase db;
XVisualInfo vis; XVisualInfo vis;
@ -133,10 +133,14 @@ void win_init(win_t *win)
f = win_res(db, RES_CLASS ".font", "monospace-8"); f = win_res(db, RES_CLASS ".font", "monospace-8");
win_init_font(e, f); win_init_font(e, f);
bg = win_res(db, RES_CLASS ".background", "white"); win_bg = win_res(db, RES_CLASS ".window.background", "white");
fg = win_res(db, RES_CLASS ".foreground", "black"); win_fg = win_res(db, RES_CLASS ".window.foreground", "black");
win_alloc_color(e, bg, &win->bg); bar_bg = win_res(db, RES_CLASS ".bar.background", win_bg);
win_alloc_color(e, fg, &win->fg); 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.l.size = BAR_L_LEN;
win->bar.r.size = BAR_R_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.h = e->scrh;
win->buf.pm = XCreatePixmap(e->dpy, win->xwin, win->buf.pm = XCreatePixmap(e->dpy, win->xwin,
win->buf.w, win->buf.h, e->depth); 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); XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h);
XSetWindowBackgroundPixmap(e->dpy, win->xwin, win->buf.pm); 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.pm = XCreatePixmap(e->dpy, win->xwin,
win->buf.w, win->buf.h, e->depth); 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); 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, d = XftDrawCreate(e->dpy, win->buf.pm, e->vis,
e->cmap); 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); XFillRectangle(e->dpy, win->buf.pm, gc, 0, win->h, win->w, win->bar.h);
XSetForeground(e->dpy, gc, win->bg.pixel); XSetForeground(e->dpy, gc, win->win_bg.pixel);
XSetBackground(e->dpy, gc, win->fg.pixel); XSetBackground(e->dpy, gc, win->bar_bg.pixel);
if ((len = strlen(r->buf)) > 0) { if ((len = strlen(r->buf)) > 0) {
if ((tw = TEXTWIDTH(win, r->buf, len)) > w) if ((tw = TEXTWIDTH(win, r->buf, len)) > w)
return; return;
x = win->w - tw - H_TEXT_PAD; x = win->w - tw - H_TEXT_PAD;
w -= tw; 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) { if ((len = strlen(l->buf)) > 0) {
x = H_TEXT_PAD; x = H_TEXT_PAD;
w -= 2 * H_TEXT_PAD; /* gap between left and right parts */ 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); XftDrawDestroy(d);
} }