Multiple theme section & theme attribution to bars
This commit is contained in:
parent
59887b16ab
commit
34f4e27c6b
@ -16,32 +16,51 @@
|
||||
static void
|
||||
config_theme(void)
|
||||
{
|
||||
Theme *t;
|
||||
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]*/
|
||||
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 */
|
||||
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;
|
||||
t->bars.fg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "bars_fg").str);
|
||||
t->bars.bg = color_atoh(fetch_opt_first(ks[i], "#222222", "bars_bg").str);
|
||||
t->bars_width = fetch_opt_first(ks[i], "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;
|
||||
t->tags_n.fg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "tags_normal_fg").str);
|
||||
t->tags_n.bg = color_atoh(fetch_opt_first(ks[i], "#222222", "tags_normal_bg").str);
|
||||
t->tags_s.fg = color_atoh(fetch_opt_first(ks[i], "#222222", "tags_sel_fg").str);
|
||||
t->tags_s.bg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "tags_sel_bg").str);
|
||||
t->tags_border_col = color_atoh(fetch_opt_first(ks[i], "#888888", "tags_border_color").str);
|
||||
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
|
||||
config_bars(void)
|
||||
{
|
||||
Scr33n *s;
|
||||
Theme *t;
|
||||
size_t i, n;
|
||||
struct conf_sec *sec, **ks;
|
||||
int screenid;
|
||||
@ -57,10 +76,11 @@ config_bars(void)
|
||||
{
|
||||
elem = fetch_opt_first(ks[i], "", "elements").str;
|
||||
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)
|
||||
if(screenid == s->id || screenid == -1)
|
||||
(Infobar*)infobar_new(s, elem);
|
||||
(Infobar*)infobar_new(s, t, elem);
|
||||
}
|
||||
|
||||
free(ks);
|
||||
|
||||
@ -69,6 +69,19 @@ modkey_keysym(const char *name)
|
||||
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);
|
||||
|
||||
#endif /* CONFIG_H */
|
||||
|
||||
@ -42,7 +42,7 @@ infobar_elem_tag_init(Element *e)
|
||||
infobar_elem_placement(e);
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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);
|
||||
|
||||
/* 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);
|
||||
XSetWindowBorderWidth(W->dpy, b->win, W->conf.theme.tags_border_width);
|
||||
XSetWindowBorder(W->dpy, b->win, e->infobar->theme->tags_border_col);
|
||||
XSetWindowBorderWidth(W->dpy, b->win, e->infobar->theme->tags_border_width);
|
||||
}
|
||||
|
||||
b->ptr = (void*)t;
|
||||
@ -76,6 +76,8 @@ infobar_elem_tag_init(Element *e)
|
||||
j += s;
|
||||
}
|
||||
|
||||
e->infobar->screen->elemupdate |= FLAGINT(ElemTag);
|
||||
|
||||
e->geo.w = j;
|
||||
}
|
||||
|
||||
@ -93,13 +95,13 @@ infobar_elem_tag_update(Element *e)
|
||||
/* TODO: color from conf */
|
||||
if(t == sel)
|
||||
{
|
||||
b->fg = W->conf.theme.tags_s.fg;
|
||||
b->bg = W->conf.theme.tags_s.bg;
|
||||
b->fg = e->infobar->theme->tags_s.fg;
|
||||
b->bg = e->infobar->theme->tags_s.bg;
|
||||
}
|
||||
else
|
||||
{
|
||||
b->fg = W->conf.theme.tags_n.fg;
|
||||
b->bg = W->conf.theme.tags_n.bg;
|
||||
b->fg = e->infobar->theme->tags_n.fg;
|
||||
b->bg = e->infobar->theme->tags_n.bg;
|
||||
}
|
||||
|
||||
barwin_refresh_color(b);
|
||||
@ -168,24 +170,22 @@ infobar_elem_remove(Element *e)
|
||||
}
|
||||
|
||||
Infobar*
|
||||
infobar_new(Scr33n *s, const char *elem)
|
||||
infobar_new(Scr33n *s, Theme *theme, const char *elem)
|
||||
{
|
||||
int n;
|
||||
|
||||
Infobar *i = (Infobar*)xcalloc(1, sizeof(Infobar));
|
||||
|
||||
i->screen = s;
|
||||
i->theme = theme;
|
||||
i->elemorder = xstrdup(elem);
|
||||
|
||||
/* Active all flags for first refresh */
|
||||
s->elemupdate |= (1<<0) | (1<<1) /*pow(ElemLast, 2) - 1*/;
|
||||
|
||||
/* TODO: Position top/bottom */
|
||||
infobar_placement(i);
|
||||
|
||||
/* Barwin create */
|
||||
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 */
|
||||
barwin_map(i->bar);
|
||||
|
||||
@ -10,11 +10,9 @@
|
||||
#include "util.h"
|
||||
#include "draw.h"
|
||||
|
||||
#define INFOBAR_DEF_W (14)
|
||||
|
||||
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_refresh(Infobar *i);
|
||||
void infobar_remove(Infobar *i);
|
||||
@ -37,7 +35,7 @@ infobar_placement(Infobar *i)
|
||||
Infobar *h = SLIST_FIRST(&i->screen->infobars);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -242,6 +242,7 @@ wmfs_quit(void)
|
||||
|
||||
/* Conf stuffs */
|
||||
FREE_LIST(Keybind, W->h.keybind);
|
||||
FREE_LIST(Theme, W->h.theme);
|
||||
|
||||
W->running = false;
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ typedef struct Tag Tag;
|
||||
typedef struct Client Client;
|
||||
typedef struct Keybind Keybind;
|
||||
typedef struct Mousebind Mousebind;
|
||||
typedef struct Theme Theme;
|
||||
|
||||
struct Geo
|
||||
{
|
||||
@ -81,6 +82,7 @@ struct Infobar
|
||||
Barwin *bar;
|
||||
Geo geo;
|
||||
Scr33n *screen;
|
||||
Theme *theme;
|
||||
char *elemorder;
|
||||
TAILQ_HEAD(esub, Element) elements;
|
||||
SLIST_ENTRY(Infobar) next;
|
||||
@ -145,6 +147,23 @@ struct Colpair
|
||||
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
|
||||
{
|
||||
/* Misc section */
|
||||
@ -155,20 +174,6 @@ 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 */
|
||||
@ -196,6 +201,7 @@ struct Wmfs
|
||||
SLIST_HEAD(, Client) client;
|
||||
SLIST_HEAD(, Keybind) keybind;
|
||||
SLIST_HEAD(, Barwin) barwin;
|
||||
SLIST_HEAD(, Theme) theme;
|
||||
} h;
|
||||
|
||||
/* Config options */
|
||||
|
||||
@ -2,7 +2,10 @@
|
||||
# WMFS2 configuration file
|
||||
#
|
||||
|
||||
[themes]
|
||||
|
||||
[theme]
|
||||
# name = "default"
|
||||
|
||||
# Bars
|
||||
bars_width = 14
|
||||
@ -19,6 +22,20 @@
|
||||
|
||||
[/theme]
|
||||
|
||||
[theme]
|
||||
name = "perso"
|
||||
|
||||
bars_width = 20
|
||||
bars_fg = "#222222"
|
||||
bars_bg = "#CCCCCC"
|
||||
|
||||
tags_sel_bg = "#33AA33"
|
||||
tags_normal_fg = "#AA3333"
|
||||
|
||||
[/theme]
|
||||
|
||||
[/themes]
|
||||
|
||||
[bars]
|
||||
|
||||
# element type:
|
||||
@ -27,12 +44,14 @@
|
||||
|
||||
[bar]
|
||||
screen = 0
|
||||
elements = "tt"
|
||||
elements = "t"
|
||||
theme = "default"
|
||||
[/bar]
|
||||
|
||||
[bar]
|
||||
screen = 1
|
||||
elements = "t"
|
||||
theme = "perso"
|
||||
[/bar]
|
||||
|
||||
[/bars]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user