Multiple theme section & theme attribution to bars

This commit is contained in:
Martin Duquesnoy 2011-08-31 17:54:24 +02:00
parent 59887b16ab
commit 34f4e27c6b
7 changed files with 119 additions and 62 deletions

View File

@ -16,32 +16,51 @@
static void static void
config_theme(void) config_theme(void)
{ {
Theme *t;
size_t i, n; size_t i, n;
struct conf_sec *sec; struct conf_sec *sec, **ks;
char *name;
/* [themes] */
sec = fetch_section_first(NULL, "themes");
ks = fetch_section(sec, "theme");
if(!(n = fetch_section_count(ks)))
++n;
/* [theme]*/ /* [theme]*/
sec = fetch_section_first(NULL, "theme"); for(i = 0; i < n; ++i)
{
t = (Theme*)xcalloc(1, sizeof(Theme));
t->name = fetch_opt_first(ks[i], "default", "name").str;
/* bars */ /* bars */
W->conf.theme.bars.fg = color_atoh(fetch_opt_first(sec, "#CCCCCC", "bars_fg").str); t->bars.fg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "bars_fg").str);
W->conf.theme.bars.bg = color_atoh(fetch_opt_first(sec, "#222222", "bars_bg").str); t->bars.bg = color_atoh(fetch_opt_first(ks[i], "#222222", "bars_bg").str);
W->conf.theme.bars_width = fetch_opt_first(sec, "12", "bars_width").num; t->bars_width = fetch_opt_first(ks[i], "12", "bars_width").num;
/* /*
* Elements * Elements
*/ */
W->conf.theme.tags_n.fg = color_atoh(fetch_opt_first(sec, "#CCCCCC", "tags_normal_fg").str); t->tags_n.fg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "tags_normal_fg").str);
W->conf.theme.tags_n.bg = color_atoh(fetch_opt_first(sec, "#222222", "tags_normal_bg").str); t->tags_n.bg = color_atoh(fetch_opt_first(ks[i], "#222222", "tags_normal_bg").str);
W->conf.theme.tags_s.fg = color_atoh(fetch_opt_first(sec, "#222222", "tags_sel_fg").str); t->tags_s.fg = color_atoh(fetch_opt_first(ks[i], "#222222", "tags_sel_fg").str);
W->conf.theme.tags_s.bg = color_atoh(fetch_opt_first(sec, "#CCCCCC", "tags_sel_bg").str); t->tags_s.bg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "tags_sel_bg").str);
W->conf.theme.tags_border_col = color_atoh(fetch_opt_first(sec, "#888888", "tags_border_color").str); t->tags_border_col = color_atoh(fetch_opt_first(ks[i], "#888888", "tags_border_color").str);
W->conf.theme.tags_border_width = fetch_opt_first(sec, "0", "tags_border_width").num; t->tags_border_width = fetch_opt_first(ks[i], "0", "tags_border_width").num;
SLIST_INSERT_HEAD(&W->h.theme, t, next);
}
free(ks);
} }
static void static void
config_bars(void) config_bars(void)
{ {
Scr33n *s; Scr33n *s;
Theme *t;
size_t i, n; size_t i, n;
struct conf_sec *sec, **ks; struct conf_sec *sec, **ks;
int screenid; int screenid;
@ -57,10 +76,11 @@ config_bars(void)
{ {
elem = fetch_opt_first(ks[i], "", "elements").str; elem = fetch_opt_first(ks[i], "", "elements").str;
screenid = fetch_opt_first(ks[i], "-1", "screen").num; screenid = fetch_opt_first(ks[i], "-1", "screen").num;
t = name_to_theme(fetch_opt_first(ks[i], "default", "theme").str);
SLIST_FOREACH(s, &W->h.screen, next) SLIST_FOREACH(s, &W->h.screen, next)
if(screenid == s->id || screenid == -1) if(screenid == s->id || screenid == -1)
(Infobar*)infobar_new(s, elem); (Infobar*)infobar_new(s, t, elem);
} }
free(ks); free(ks);

View File

@ -69,6 +69,19 @@ modkey_keysym(const char *name)
return NoSymbol; return NoSymbol;
} }
static inline Theme*
name_to_theme(const char *name)
{
Theme *t;
SLIST_FOREACH(t, &W->h.theme, next)
if(!strcmp(t->name, name))
return t;
return SLIST_FIRST(&W->h.theme);
}
void config_init(void); void config_init(void);
#endif /* CONFIG_H */ #endif /* CONFIG_H */

View File

@ -42,7 +42,7 @@ 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 -= (W->conf.theme.tags_border_width << 1); e->geo.h -= (e->infobar->theme->tags_border_width << 1);
TAILQ_FOREACH(t, &e->infobar->screen->tags, next) TAILQ_FOREACH(t, &e->infobar->screen->tags, next)
{ {
@ -52,10 +52,10 @@ infobar_elem_tag_init(Element *e)
b = barwin_new(e->infobar->bar->win, j, 0, s, e->geo.h, 0, 0, false); b = barwin_new(e->infobar->bar->win, j, 0, s, e->geo.h, 0, 0, false);
/* Set border */ /* Set border */
if(W->conf.theme.tags_border_width) if(e->infobar->theme->tags_border_width)
{ {
XSetWindowBorder(W->dpy, b->win, W->conf.theme.tags_border_col); XSetWindowBorder(W->dpy, b->win, e->infobar->theme->tags_border_col);
XSetWindowBorderWidth(W->dpy, b->win, W->conf.theme.tags_border_width); XSetWindowBorderWidth(W->dpy, b->win, e->infobar->theme->tags_border_width);
} }
b->ptr = (void*)t; b->ptr = (void*)t;
@ -76,6 +76,8 @@ infobar_elem_tag_init(Element *e)
j += s; j += s;
} }
e->infobar->screen->elemupdate |= FLAGINT(ElemTag);
e->geo.w = j; e->geo.w = j;
} }
@ -93,13 +95,13 @@ infobar_elem_tag_update(Element *e)
/* TODO: color from conf */ /* TODO: color from conf */
if(t == sel) if(t == sel)
{ {
b->fg = W->conf.theme.tags_s.fg; b->fg = e->infobar->theme->tags_s.fg;
b->bg = W->conf.theme.tags_s.bg; b->bg = e->infobar->theme->tags_s.bg;
} }
else else
{ {
b->fg = W->conf.theme.tags_n.fg; b->fg = e->infobar->theme->tags_n.fg;
b->bg = W->conf.theme.tags_n.bg; b->bg = e->infobar->theme->tags_n.bg;
} }
barwin_refresh_color(b); barwin_refresh_color(b);
@ -168,24 +170,22 @@ infobar_elem_remove(Element *e)
} }
Infobar* Infobar*
infobar_new(Scr33n *s, const char *elem) infobar_new(Scr33n *s, Theme *theme, const char *elem)
{ {
int n; int n;
Infobar *i = (Infobar*)xcalloc(1, sizeof(Infobar)); Infobar *i = (Infobar*)xcalloc(1, sizeof(Infobar));
i->screen = s; i->screen = s;
i->theme = theme;
i->elemorder = xstrdup(elem); i->elemorder = xstrdup(elem);
/* Active all flags for first refresh */
s->elemupdate |= (1<<0) | (1<<1) /*pow(ElemLast, 2) - 1*/;
/* TODO: Position top/bottom */ /* TODO: Position top/bottom */
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, 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); theme->bars.fg, theme->bars.bg, false);
/* Render */ /* Render */
barwin_map(i->bar); barwin_map(i->bar);

View File

@ -10,11 +10,9 @@
#include "util.h" #include "util.h"
#include "draw.h" #include "draw.h"
#define INFOBAR_DEF_W (14)
enum { ElemTag = 0, ElemLayout, ElemSelbar, ElemStatus, ElemCustom, ElemLast }; enum { ElemTag = 0, ElemLayout, ElemSelbar, ElemStatus, ElemCustom, ElemLast };
Infobar *infobar_new(Scr33n *s, const char *elem); Infobar *infobar_new(Scr33n *s, Theme *theme, const char *elem);
void infobar_elem_update(Infobar *i); void infobar_elem_update(Infobar *i);
void infobar_refresh(Infobar *i); void infobar_refresh(Infobar *i);
void infobar_remove(Infobar *i); void infobar_remove(Infobar *i);
@ -37,7 +35,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 = W->conf.theme.bars_width; i->geo.h = i->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

@ -242,6 +242,7 @@ wmfs_quit(void)
/* Conf stuffs */ /* Conf stuffs */
FREE_LIST(Keybind, W->h.keybind); FREE_LIST(Keybind, W->h.keybind);
FREE_LIST(Theme, W->h.theme);
W->running = false; W->running = false;
} }

View File

@ -43,6 +43,7 @@ typedef struct Tag Tag;
typedef struct Client Client; typedef struct Client Client;
typedef struct Keybind Keybind; typedef struct Keybind Keybind;
typedef struct Mousebind Mousebind; typedef struct Mousebind Mousebind;
typedef struct Theme Theme;
struct Geo struct Geo
{ {
@ -81,6 +82,7 @@ struct Infobar
Barwin *bar; Barwin *bar;
Geo geo; Geo geo;
Scr33n *screen; Scr33n *screen;
Theme *theme;
char *elemorder; char *elemorder;
TAILQ_HEAD(esub, Element) elements; TAILQ_HEAD(esub, Element) elements;
SLIST_ENTRY(Infobar) next; SLIST_ENTRY(Infobar) next;
@ -145,6 +147,23 @@ struct Colpair
Color fg, bg; Color fg, bg;
}; };
struct Theme
{
char *name;
/* Bars */
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;
SLIST_ENTRY(Theme) next;
};
struct Config struct Config
{ {
/* Misc section */ /* Misc section */
@ -155,20 +174,6 @@ 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 */
@ -196,6 +201,7 @@ struct Wmfs
SLIST_HEAD(, Client) client; SLIST_HEAD(, Client) client;
SLIST_HEAD(, Keybind) keybind; SLIST_HEAD(, Keybind) keybind;
SLIST_HEAD(, Barwin) barwin; SLIST_HEAD(, Barwin) barwin;
SLIST_HEAD(, Theme) theme;
} h; } h;
/* Config options */ /* Config options */

View File

@ -2,7 +2,10 @@
# WMFS2 configuration file # WMFS2 configuration file
# #
[themes]
[theme] [theme]
# name = "default"
# Bars # Bars
bars_width = 14 bars_width = 14
@ -19,6 +22,20 @@
[/theme] [/theme]
[theme]
name = "perso"
bars_width = 20
bars_fg = "#222222"
bars_bg = "#CCCCCC"
tags_sel_bg = "#33AA33"
tags_normal_fg = "#AA3333"
[/theme]
[/themes]
[bars] [bars]
# element type: # element type:
@ -27,12 +44,14 @@
[bar] [bar]
screen = 0 screen = 0
elements = "tt" elements = "t"
theme = "default"
[/bar] [/bar]
[bar] [bar]
screen = 1 screen = 1
elements = "t" elements = "t"
theme = "perso"
[/bar] [/bar]
[/bars] [/bars]