config: allow font/foreground attributes on modules too

Previously we allowed it on the bar, and on all particles. Now we also
allow it on all modules.

This allows us to specify a "default" font/foreground on a per-module
basis, having it applied to all the modules particles.
This commit is contained in:
Daniel Eklöf 2019-01-13 14:24:44 +01:00
parent 8dc278aaf2
commit a425378576
13 changed files with 47 additions and 14 deletions

View file

@ -191,18 +191,29 @@ conf_to_particle(const struct yml_node *node, struct conf_inherit inherited)
const char *on_click_template
= on_click != NULL ? yml_value_as_string(on_click) : NULL;
struct deco *deco = deco_node != NULL ? deco_from_config(deco_node) : NULL;
/*
* Font and foreground are inheritable attributes. Each particle
* may specify its own font/foreground values, which will then be
* used by itself, and all its sub-particles. If *not* specified,
* we inherit the values from our parent. Note that since
* particles actually *use* the font/foreground values, we must
* clone the font, since each particle takes ownership of its own
* font.
*/
struct font *font = font_node != NULL
? conf_to_font(font_node) : font_clone(inherited.font);
struct rgba foreground = foreground_node != NULL
? conf_to_color(foreground_node) : inherited.foreground;
struct deco *deco = deco_node != NULL ? deco_from_config(deco_node) : NULL;
/* Instantiate base/common particle */
struct particle *common = particle_common_new(
left, right, on_click_template, font, foreground, deco);
const struct particle_info *info = plugin_load_particle(type);
assert(info != NULL);
assert(info != NULL);
return info->from_conf(pair.value, common);
}
@ -312,8 +323,25 @@ conf_to_bar(const struct yml_node *bar)
struct yml_dict_iter m = yml_dict_iter(it.node);
const char *mod_name = yml_value_as_string(m.key);
/*
* These aren't used by the modules, but passed down
* to particles. This allows us to specify a default
* font and foreground for each module, and having it
* applied to all its particles.
*/
const struct yml_node *mod_font = yml_get_value(m.value, "font");
const struct yml_node *mod_foreground = yml_get_value(
m.value, "foreground");
struct conf_inherit mod_inherit = {
.font = mod_font != NULL
? conf_to_font(mod_font) : inherited.font,
.foreground = mod_foreground != NULL
? conf_to_color(mod_foreground) : inherited.foreground,
};
const struct module_info *info = plugin_load_module(mod_name);
mods[idx] = info->from_conf(m.value, inherited);
mods[idx] = info->from_conf(m.value, mod_inherit);
}
if (i == 0) {

View file

@ -15,6 +15,11 @@ struct module_info {
bool (*verify_conf)(keychain_t *chain, const struct yml_node *node);
struct module *(*from_conf)(const struct yml_node *node,
struct conf_inherit inherited);
#define MODULE_COMMON_ATTRS \
{"font", false, &conf_verify_font}, \
{"foreground", false, &conf_verify_color}, \
{NULL, false, NULL}
};
struct module_run_context {

View file

@ -288,7 +288,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
{"mixer", true, &conf_verify_string},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);

View file

@ -231,7 +231,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
{"name", true, &conf_verify_string},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);

View file

@ -364,7 +364,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
{"poll-interval", false, &conf_verify_int},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);

View file

@ -115,7 +115,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
{"time-format", false, &conf_verify_string},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);

View file

@ -710,7 +710,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
{"right-spacing", false, &conf_verify_int},
{"content", true, &verify_content},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);

View file

@ -60,7 +60,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
static const struct attr_info attrs[] = {
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);

View file

@ -499,7 +499,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
{"port", false, &conf_verify_int},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);

View file

@ -550,7 +550,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
{"name", true, &conf_verify_string},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);

View file

@ -585,7 +585,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
{"right-spacing", false, &conf_verify_int},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);

View file

@ -465,7 +465,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
static const struct attr_info attrs[] = {
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);

View file

@ -327,7 +327,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node)
static const struct attr_info attrs[] = {
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
{NULL, false, NULL}
MODULE_COMMON_ATTRS,
};
return conf_verify_dict(chain, node, attrs);