diff --git a/wmfs2/src/config.c b/wmfs2/src/config.c index f83669a..6e4ace7 100755 --- a/wmfs2/src/config.c +++ b/wmfs2/src/config.c @@ -9,9 +9,35 @@ #include "tag.h" #include "screen.h" #include "infobar.h" +#include "util.h" #define CONFIG_DEFAULT_PATH ".config/wmfs/wmfsrc2" /* tmp */ +static void +config_theme(void) +{ + size_t i, n; + struct conf_sec *sec; + + /* [theme] */ + sec = fetch_section_first(NULL, "theme"); + + /* bars */ + W->conf.theme.bars.fg = color_atoh(fetch_opt_first(sec, "#CCCCCC", "bars_fg").str); + W->conf.theme.bars.bg = color_atoh(fetch_opt_first(sec, "#222222", "bars_bg").str); + W->conf.theme.bars_width = fetch_opt_first(sec, "12", "bars_width").num; + + /* + * Elements + */ + W->conf.theme.tags_n.fg = color_atoh(fetch_opt_first(sec, "#CCCCCC", "tags_normal_fg").str); + W->conf.theme.tags_n.bg = color_atoh(fetch_opt_first(sec, "#222222", "tags_normal_bg").str); + W->conf.theme.tags_s.fg = color_atoh(fetch_opt_first(sec, "#222222", "tags_sel_fg").str); + W->conf.theme.tags_s.bg = color_atoh(fetch_opt_first(sec, "#CCCCCC", "tags_sel_bg").str); + W->conf.theme.tags_border_col = color_atoh(fetch_opt_first(sec, "#888888", "tags_border_color").str); + W->conf.theme.tags_border_width = fetch_opt_first(sec, "0", "tags_border_width").num; +} + static void config_bars(void) { @@ -131,6 +157,7 @@ config_init(void) if(get_conf(path) == -1) errx(1, "parsing configuration file (%s) failed.", path); + config_theme(); config_keybind(); config_tag(); config_bars(); diff --git a/wmfs2/src/infobar.c b/wmfs2/src/infobar.c index d31338e..7eb1dcb 100755 --- a/wmfs2/src/infobar.c +++ b/wmfs2/src/infobar.c @@ -42,20 +42,20 @@ infobar_elem_tag_init(Element *e) infobar_elem_placement(e); j = e->geo.x; - e->geo.h -= (ELEM_TAG_BORDER << 1); + e->geo.h -= (W->conf.theme.tags_border_width << 1); TAILQ_FOREACH(t, &e->infobar->screen->tags, next) { s = draw_textw(t->name) + PAD; /* Init barwin */ - b = barwin_new(e->infobar->bar->win, j, 0, s, e->geo.h, 0x009900, 0x777777, false); + b = barwin_new(e->infobar->bar->win, j, 0, s, e->geo.h, 0, 0, false); /* Set border */ - if(ELEM_TAG_BORDER) + if(W->conf.theme.tags_border_width) { - XSetWindowBorder(W->dpy, b->win, 0x1B3500); - XSetWindowBorderWidth(W->dpy, b->win, ELEM_TAG_BORDER); + XSetWindowBorder(W->dpy, b->win, W->conf.theme.tags_border_col); + XSetWindowBorderWidth(W->dpy, b->win, W->conf.theme.tags_border_width); } b->ptr = (void*)t; @@ -93,13 +93,13 @@ infobar_elem_tag_update(Element *e) /* TODO: color from conf */ if(t == sel) { - b->fg = 0x000000; - b->bg = 0x3D5700; + b->fg = W->conf.theme.tags_s.fg; + b->bg = W->conf.theme.tags_s.bg; } else { - b->fg = 0x3D5700; - b->bg = 0x000000; + b->fg = W->conf.theme.tags_n.fg; + b->bg = W->conf.theme.tags_n.bg; } barwin_refresh_color(b); @@ -184,7 +184,8 @@ infobar_new(Scr33n *s, const char *elem) infobar_placement(i); /* Barwin create */ - i->bar = barwin_new(W->root, i->geo.x, i->geo.y, i->geo.w, i->geo.h, 0x222222, 0xCCCCCC, false); + i->bar = barwin_new(W->root, i->geo.x, i->geo.y, i->geo.w, i->geo.h, + W->conf.theme.bars.fg, W->conf.theme.bars.bg, false); /* Render */ barwin_map(i->bar); diff --git a/wmfs2/src/infobar.h b/wmfs2/src/infobar.h index 429be18..4ace2aa 100755 --- a/wmfs2/src/infobar.h +++ b/wmfs2/src/infobar.h @@ -11,7 +11,6 @@ #include "draw.h" #define INFOBAR_DEF_W (14) -#define ELEM_TAG_BORDER (1) enum { ElemTag = 0, ElemLayout, ElemSelbar, ElemStatus, ElemCustom, ElemLast }; @@ -38,7 +37,7 @@ infobar_placement(Infobar *i) Infobar *h = SLIST_FIRST(&i->screen->infobars); i->geo = i->screen->geo; - i->geo.h = INFOBAR_DEF_W; + i->geo.h = W->conf.theme.bars_width; i->geo.y += (h ? h->geo.y + h->geo.h : i->screen->geo.y); } diff --git a/wmfs2/src/util.h b/wmfs2/src/util.h index 78b6360..a4e87c5 100755 --- a/wmfs2/src/util.h +++ b/wmfs2/src/util.h @@ -25,6 +25,17 @@ #define ATOI(s) strtol(s, NULL, 10) #define INAREA(i, j, a) ((i) >= (a).x && (i) <= (a).x + (a).w && (j) >= (a).y && (j) <= (a).y + (a).h) +/* + * "#RRGGBB" -> 0xRRGGBB + */ +static inline Color +color_atoh(const char *col) +{ + int shift = (col[0] == '#'); + + return (Color)strtol(col + shift, NULL, 16); +} + void *xmalloc(size_t nmemb, size_t size); void *xcalloc(size_t nmemb, size_t size); int xasprintf(char **strp, const char *fmt, ...); diff --git a/wmfs2/src/wmfs.h b/wmfs2/src/wmfs.h index 83a80d7..86264ee 100755 --- a/wmfs2/src/wmfs.h +++ b/wmfs2/src/wmfs.h @@ -140,6 +140,11 @@ struct Mousebind SLIST_ENTRY(Mousebind) next; }; +struct Colpair +{ + Color fg, bg; +}; + struct Config { /* Misc section */ @@ -150,6 +155,20 @@ struct Config bool focus_follow_movement; bool focus_pointer_click; } misc; + + /* Theme section */ + struct + { + struct Colpair bars; + int bars_width; + + /* Elements */ + struct Colpair tags_n; /* normal */ + struct Colpair tags_s; /* selected */ + int tags_border_width; + Color tags_border_col; + + } theme; }; /* Global struct */ @@ -179,6 +198,9 @@ struct Wmfs SLIST_HEAD(, Barwin) barwin; } h; + /* Config options */ + struct Config conf; + /* * Selected screen, from what you go everywhere; selected tag, * and then selected client.