diff --git a/config-verify.c b/config-verify.c index 9d9af2f..91df71b 100644 --- a/config-verify.c +++ b/config-verify.c @@ -9,6 +9,7 @@ #include "tllist.h" #include "modules/alsa/alsa.h" +#include "modules/backlight/backlight.h" static const char * err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -460,12 +461,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info backlight[] = { - {"name", true, &conf_verify_string}, - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info battery[] = { {"name", true, &conf_verify_string}, {"poll-interval", false, &conf_verify_int}, @@ -530,6 +525,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct module_info *info; } modules_v2[] = { {"alsa", &module_alsa}, + {"backlight", &module_backlight}, }; static const struct { @@ -537,7 +533,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"backlight", backlight, sizeof(backlight) / sizeof(backlight[0])}, {"battery", battery, sizeof(battery) / sizeof(battery[0])}, {"clock", clock, sizeof(clock) / sizeof(clock[0])}, {"i3", i3, sizeof(i3) / sizeof(i3[0])}, diff --git a/config.c b/config.c index f712b18..8169dc5 100644 --- a/config.c +++ b/config.c @@ -438,17 +438,6 @@ module_xkb_from_config(const struct yml_node *node, return module_xkb(conf_to_particle(c, parent_font)); } -static struct module * -module_backlight_from_config(const struct yml_node *node, - const struct font *parent_font) -{ - const struct yml_node *name = yml_get_value(node, "name"); - const struct yml_node *c = yml_get_value(node, "content"); - - return module_backlight( - yml_value_as_string(name), conf_to_particle(c, parent_font)); -} - static struct module * module_mpd_from_config(const struct yml_node *node, const struct font *parent_font) @@ -582,7 +571,12 @@ 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); - if (strcmp(mod_name, "label") == 0) + if (strcmp(mod_name, "alsa") == 0) + mods[idx] = module_alsa.from_conf(m.value, font); + else if (strcmp(mod_name, "backlight") == 0) + mods[idx] = module_backlight.from_conf(m.value, font); + + else if (strcmp(mod_name, "label") == 0) mods[idx] = module_label_from_config(m.value, font); else if (strcmp(mod_name, "clock") == 0) mods[idx] = module_clock_from_config(m.value, font); @@ -594,16 +588,12 @@ conf_to_bar(const struct yml_node *bar) mods[idx] = module_battery_from_config(m.value, font); else if (strcmp(mod_name, "xkb") == 0) mods[idx] = module_xkb_from_config(m.value, font); - else if (strcmp(mod_name, "backlight") == 0) - mods[idx] = module_backlight_from_config(m.value, font); else if (strcmp(mod_name, "mpd") == 0) mods[idx] = module_mpd_from_config(m.value, font); else if (strcmp(mod_name, "network") == 0) mods[idx] = module_network_from_config(m.value, font); else if (strcmp(mod_name, "removables") == 0) mods[idx] = module_removables_from_config(m.value, font); - else if (strcmp(mod_name, "alsa") == 0) - mods[idx] = module_alsa.from_conf(m.value, font); else assert(false); } diff --git a/modules/backlight/backlight.c b/modules/backlight/backlight.c index 4c6a7bb..1ba2334 100644 --- a/modules/backlight/backlight.c +++ b/modules/backlight/backlight.c @@ -15,6 +15,7 @@ #define LOG_MODULE "battery" #include "../../log.h" #include "../../bar.h" +#include "../../config.h" struct private { struct particle *label; @@ -198,8 +199,8 @@ run(struct module_run_context *ctx) return 0; } -struct module * -module_backlight(const char *device, struct particle *label) +static struct module * +backlight_new(const char *device, struct particle *label) { struct private *m = malloc(sizeof(*m)); m->label = label; @@ -214,3 +215,24 @@ module_backlight(const char *device, struct particle *label) mod->content = &content; return mod; } + +static struct module * +from_conf(const struct yml_node *node, const struct font *parent_font) +{ + const struct yml_node *name = yml_get_value(node, "name"); + const struct yml_node *c = yml_get_value(node, "content"); + + return backlight_new( + yml_value_as_string(name), conf_to_particle(c, parent_font)); +} + +const struct module_info module_backlight = { + .from_conf = &from_conf, + .attr_count = 3, + .attrs = { + {"name", true, &conf_verify_string}, + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/backlight/backlight.h b/modules/backlight/backlight.h index ab0b9b3..f390f2e 100644 --- a/modules/backlight/backlight.h +++ b/modules/backlight/backlight.h @@ -1,6 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_backlight(const char *device, struct particle *label); +extern const struct module_info module_backlight;