Add theme section

This commit is contained in:
Martin Duquesnoy 2011-08-31 00:11:06 +02:00
parent 55586bc20a
commit b1b249411f
5 changed files with 72 additions and 12 deletions

View File

@ -9,9 +9,35 @@
#include "tag.h" #include "tag.h"
#include "screen.h" #include "screen.h"
#include "infobar.h" #include "infobar.h"
#include "util.h"
#define CONFIG_DEFAULT_PATH ".config/wmfs/wmfsrc2" /* tmp */ #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 static void
config_bars(void) config_bars(void)
{ {
@ -131,6 +157,7 @@ config_init(void)
if(get_conf(path) == -1) if(get_conf(path) == -1)
errx(1, "parsing configuration file (%s) failed.", path); errx(1, "parsing configuration file (%s) failed.", path);
config_theme();
config_keybind(); config_keybind();
config_tag(); config_tag();
config_bars(); config_bars();

View File

@ -42,20 +42,20 @@ infobar_elem_tag_init(Element *e)
infobar_elem_placement(e); infobar_elem_placement(e);
j = e->geo.x; 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) TAILQ_FOREACH(t, &e->infobar->screen->tags, next)
{ {
s = draw_textw(t->name) + PAD; s = draw_textw(t->name) + PAD;
/* Init barwin */ /* 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 */ /* Set border */
if(ELEM_TAG_BORDER) if(W->conf.theme.tags_border_width)
{ {
XSetWindowBorder(W->dpy, b->win, 0x1B3500); XSetWindowBorder(W->dpy, b->win, W->conf.theme.tags_border_col);
XSetWindowBorderWidth(W->dpy, b->win, ELEM_TAG_BORDER); XSetWindowBorderWidth(W->dpy, b->win, W->conf.theme.tags_border_width);
} }
b->ptr = (void*)t; b->ptr = (void*)t;
@ -93,13 +93,13 @@ infobar_elem_tag_update(Element *e)
/* TODO: color from conf */ /* TODO: color from conf */
if(t == sel) if(t == sel)
{ {
b->fg = 0x000000; b->fg = W->conf.theme.tags_s.fg;
b->bg = 0x3D5700; b->bg = W->conf.theme.tags_s.bg;
} }
else else
{ {
b->fg = 0x3D5700; b->fg = W->conf.theme.tags_n.fg;
b->bg = 0x000000; b->bg = W->conf.theme.tags_n.bg;
} }
barwin_refresh_color(b); barwin_refresh_color(b);
@ -184,7 +184,8 @@ infobar_new(Scr33n *s, const char *elem)
infobar_placement(i); infobar_placement(i);
/* Barwin create */ /* 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 */ /* Render */
barwin_map(i->bar); barwin_map(i->bar);

View File

@ -11,7 +11,6 @@
#include "draw.h" #include "draw.h"
#define INFOBAR_DEF_W (14) #define INFOBAR_DEF_W (14)
#define ELEM_TAG_BORDER (1)
enum { ElemTag = 0, ElemLayout, ElemSelbar, ElemStatus, ElemCustom, ElemLast }; enum { ElemTag = 0, ElemLayout, ElemSelbar, ElemStatus, ElemCustom, ElemLast };
@ -38,7 +37,7 @@ infobar_placement(Infobar *i)
Infobar *h = SLIST_FIRST(&i->screen->infobars); Infobar *h = SLIST_FIRST(&i->screen->infobars);
i->geo = i->screen->geo; 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); i->geo.y += (h ? h->geo.y + h->geo.h : i->screen->geo.y);
} }

View File

@ -25,6 +25,17 @@
#define ATOI(s) strtol(s, NULL, 10) #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) #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 *xmalloc(size_t nmemb, size_t size);
void *xcalloc(size_t nmemb, size_t size); void *xcalloc(size_t nmemb, size_t size);
int xasprintf(char **strp, const char *fmt, ...); int xasprintf(char **strp, const char *fmt, ...);

View File

@ -140,6 +140,11 @@ struct Mousebind
SLIST_ENTRY(Mousebind) next; SLIST_ENTRY(Mousebind) next;
}; };
struct Colpair
{
Color fg, bg;
};
struct Config struct Config
{ {
/* Misc section */ /* Misc section */
@ -150,6 +155,20 @@ struct Config
bool focus_follow_movement; bool focus_follow_movement;
bool focus_pointer_click; bool focus_pointer_click;
} misc; } 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 */ /* Global struct */
@ -179,6 +198,9 @@ struct Wmfs
SLIST_HEAD(, Barwin) barwin; SLIST_HEAD(, Barwin) barwin;
} h; } h;
/* Config options */
struct Config conf;
/* /*
* Selected screen, from what you go everywhere; selected tag, * Selected screen, from what you go everywhere; selected tag,
* and then selected client. * and then selected client.