Krolyxon
Commit f7557c5

Branches

Refs →

nsxivf7557c5

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
Author
Guilherme Freire
Date
2021-09-11 11:38 -0300
Committer
Berke Kocaoğlu · 2021-09-16 22:55 +0300
Parent
d8ec6f9
Commit
f7557c55b5a87a51daba825ed3f6155eed179221

+34 −22

5 files changed

  1. M image.c +1 −1
  2. M sxiv.1 +10 −4
  3. M sxiv.h +4 −2
  4. M thumbs.c +3 −3
  5. M window.c +16 −12
M image.c View
@@ -500,7 +500,7 @@ void img_render(img_t *img)
500500 }
501501 imlib_image_put_back_data(data);
502502 } else {
503− c = win->bg.pixel;
503+ c = win->win_bg.pixel;
504504 imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF);
505505 imlib_image_fill_rectangle(0, 0, dw, dh);
506506 }
M sxiv.1 View
@@ -381,11 +381,17 @@ Zoom out.
381381 .SH CONFIGURATION
382382 The following X resources are supported:
383383 .TP
384−.B background
385−Color of the window background and bar foreground
384+.B window.background
385+Color of the window background
386386 .TP
387−.B foreground
388−Color of the window foreground and bar background
387+.B window.foreground
388+Color of the window foreground
389+.TP
390+.B bar.background
391+Color of the bar background. Defaults to window.foreground
392+.TP
393+.B bar.foreground
394+Color of the bar foreground. Defaults to window.background
389395 .TP
390396 .B font
391397 Name of Xft bar font
M sxiv.h View
@@ -409,8 +409,10 @@ struct win {
409409 Window xwin;
410410 win_env_t env;
411411
412− XftColor bg;
413− XftColor fg;
412+ XftColor win_bg;
413+ XftColor win_fg;
414+ XftColor bar_bg;
415+ XftColor bar_fg;
414416
415417 int x;
416418 int y;
M thumbs.c View
@@ -469,14 +469,14 @@ void tns_mark(tns_t *tns, int n, bool mark)
469469 if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
470470 win_t *win = tns->win;
471471 thumb_t *t = &tns->thumbs[n];
472− unsigned long col = win->bg.pixel;
472+ unsigned long col = win->win_bg.pixel;
473473 int x = t->x + t->w, y = t->y + t->h;
474474
475475 win_draw_rect(win, x - 1, y + 1, 1, tns->bw, true, 1, col);
476476 win_draw_rect(win, x + 1, y - 1, tns->bw, 1, true, 1, col);
477477
478478 if (mark)
479− col = win->fg.pixel;
479+ col = win->win_fg.pixel;
480480
481481 win_draw_rect(win, x, y, tns->bw + 2, tns->bw + 2, true, 1, col);
482482
@@ -490,7 +490,7 @@ void tns_highlight(tns_t *tns, int n, bool hl)
490490 if (n >= 0 && n < *tns->cnt && tns->thumbs[n].im != NULL) {
491491 win_t *win = tns->win;
492492 thumb_t *t = &tns->thumbs[n];
493− unsigned long col = hl ? win->fg.pixel : win->bg.pixel;
493+ unsigned long col = hl ? win->win_fg.pixel : win->win_bg.pixel;
494494 int oxy = (tns->bw + 1) / 2 + 1, owh = tns->bw + 2;
495495
496496 win_draw_rect(win, t->x - oxy, t->y - oxy, t->w + owh, t->h + owh,
M window.c View
@@ -93,7 +93,7 @@ const char* win_res(XrmDatabase db, const char *name, const char *def)
9393 void win_init(win_t *win)
9494 {
9595 win_env_t *e;
96− const char *bg, *fg, *f;
96+ const char *win_bg, *win_fg, *bar_bg, *bar_fg, *f;
9797 char *res_man;
9898 XrmDatabase db;
9999 XVisualInfo vis;
@@ -133,10 +133,14 @@ void win_init(win_t *win)
133133 f = win_res(db, RES_CLASS ".font", "monospace-8");
134134 win_init_font(e, f);
135135
136− bg = win_res(db, RES_CLASS ".background", "white");
137− fg = win_res(db, RES_CLASS ".foreground", "black");
138− win_alloc_color(e, bg, &win->bg);
139− win_alloc_color(e, fg, &win->fg);
136+ win_bg = win_res(db, RES_CLASS ".window.background", "white");
137+ win_fg = win_res(db, RES_CLASS ".window.foreground", "black");
138+ bar_bg = win_res(db, RES_CLASS ".bar.background", win_bg);
139+ bar_fg = win_res(db, RES_CLASS ".bar.foreground", win_fg);
140+ win_alloc_color(e, win_bg, &win->win_bg);
141+ win_alloc_color(e, win_fg, &win->win_fg);
142+ win_alloc_color(e, bar_bg, &win->bar_bg);
143+ win_alloc_color(e, bar_fg, &win->bar_fg);
140144
141145 win->bar.l.size = BAR_L_LEN;
142146 win->bar.r.size = BAR_R_LEN;
@@ -297,7 +301,7 @@ void win_open(win_t *win)
297301 win->buf.h = e->scrh;
298302 win->buf.pm = XCreatePixmap(e->dpy, win->xwin,
299303 win->buf.w, win->buf.h, e->depth);
300− XSetForeground(e->dpy, gc, win->bg.pixel);
304+ XSetForeground(e->dpy, gc, win->win_bg.pixel);
301305 XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h);
302306 XSetWindowBackgroundPixmap(e->dpy, win->xwin, win->buf.pm);
303307
@@ -379,7 +383,7 @@ void win_clear(win_t *win)
379383 win->buf.pm = XCreatePixmap(e->dpy, win->xwin,
380384 win->buf.w, win->buf.h, e->depth);
381385 }
382− XSetForeground(e->dpy, gc, win->bg.pixel);
386+ XSetForeground(e->dpy, gc, win->win_bg.pixel);
383387 XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h);
384388 }
385389
@@ -436,23 +440,23 @@ void win_draw_bar(win_t *win)
436440 d = XftDrawCreate(e->dpy, win->buf.pm, e->vis,
437441 e->cmap);
438442
439− XSetForeground(e->dpy, gc, win->fg.pixel);
443+ XSetForeground(e->dpy, gc, win->bar_bg.pixel);
440444 XFillRectangle(e->dpy, win->buf.pm, gc, 0, win->h, win->w, win->bar.h);
441445
442− XSetForeground(e->dpy, gc, win->bg.pixel);
443− XSetBackground(e->dpy, gc, win->fg.pixel);
446+ XSetForeground(e->dpy, gc, win->win_bg.pixel);
447+ XSetBackground(e->dpy, gc, win->bar_bg.pixel);
444448
445449 if ((len = strlen(r->buf)) > 0) {
446450 if ((tw = TEXTWIDTH(win, r->buf, len)) > w)
447451 return;
448452 x = win->w - tw - H_TEXT_PAD;
449453 w -= tw;
450− win_draw_text(win, d, &win->bg, x, y, r->buf, len, tw);
454+ win_draw_text(win, d, &win->bar_fg, x, y, r->buf, len, tw);
451455 }
452456 if ((len = strlen(l->buf)) > 0) {
453457 x = H_TEXT_PAD;
454458 w -= 2 * H_TEXT_PAD; /* gap between left and right parts */
455− win_draw_text(win, d, &win->bg, x, y, l->buf, len, w);
459+ win_draw_text(win, d, &win->bar_fg, x, y, l->buf, len, w);
456460 }
457461 XftDrawDestroy(d);
458462 }