Krolyxon
Commit 8934744

Branches

Refs →

nsxiv8934744

Add colors and fonts to config.h (#115)

Adds a set of config vars to control window fg/bg, bar fg/bg, mark
color and bar font. This allows everything that can be done from
.Xresources to be configurable from config.h.
Author
Arthur Williams
Date
2021-10-09 12:04 -0700
Committer
NRK · 2021-10-29 12:53 +0600
Parent
850bc78
Commit
8934744c60a3ef34eb65a6082d59da8ad2234d6c

+15 −7

2 files changed

  1. M config.def.h +9 −1
  2. M window.c +6 −6
M config.def.h View
@@ -4,9 +4,17 @@
44 static const int WIN_WIDTH = 800;
55 static const int WIN_HEIGHT = 600;
66
7−/* colors and font are configured via X resource properties.
7+/* colors and font can be overwritten via X resource properties.
88 * See nsxiv(1), X(7) section Resources and xrdb(1) for more information.
99 */
10+static const char *DEFAULT_WIN_BG = "white";
11+static const char *DEFAULT_WIN_FG = "black";
12+static const char *DEFAULT_MARK_COLOR = NULL; /* NULL means it will default to window foreground */
13+#if HAVE_LIBFONTS
14+static const char *DEFAULT_BAR_BG = NULL; /* NULL means it will default to window background */
15+static const char *DEFAULT_BAR_FG = NULL; /* NULL means it will default to window foreground */
16+static const char *DEFAULT_FONT = "monospace-8";
17+#endif
1018
1119 #endif
1220 #ifdef _TITLE_CONFIG
M window.c View
@@ -133,20 +133,20 @@ void win_init(win_t *win)
133133 res_man = XResourceManagerString(e->dpy);
134134 db = res_man == NULL ? NULL : XrmGetStringDatabase(res_man);
135135
136− win_bg = win_res(db, RES_CLASS ".window.background", "white");
137− win_fg = win_res(db, RES_CLASS ".window.foreground", "black");
138− mrk_fg = win_res(db, RES_CLASS ".mark.foreground", win_fg);
136+ win_bg = win_res(db, RES_CLASS ".window.background", DEFAULT_WIN_BG);
137+ win_fg = win_res(db, RES_CLASS ".window.foreground", DEFAULT_WIN_FG);
138+ mrk_fg = win_res(db, RES_CLASS ".mark.foreground", DEFAULT_MARK_COLOR ? DEFAULT_MARK_COLOR : win_fg);
139139 win_alloc_color(e, win_bg, &win->win_bg);
140140 win_alloc_color(e, win_fg, &win->win_fg);
141141 win_alloc_color(e, mrk_fg, &win->mrk_fg);
142142
143143 #if HAVE_LIBFONTS
144− bar_bg = win_res(db, RES_CLASS ".bar.background", win_bg);
145− bar_fg = win_res(db, RES_CLASS ".bar.foreground", win_fg);
144+ bar_bg = win_res(db, RES_CLASS ".bar.background", DEFAULT_BAR_BG ? DEFAULT_BAR_BG : win_bg);
145+ bar_fg = win_res(db, RES_CLASS ".bar.foreground", DEFAULT_BAR_FG ? DEFAULT_BAR_FG : win_fg);
146146 xft_alloc_color(e, bar_bg, &win->bar_bg);
147147 xft_alloc_color(e, bar_fg, &win->bar_fg);
148148
149− f = win_res(db, RES_CLASS ".bar.font", "monospace-8");
149+ f = win_res(db, RES_CLASS ".bar.font", DEFAULT_FONT);
150150 win_init_font(e, f);
151151
152152 win->bar.l.size = BAR_L_LEN;