diff --git a/config-verify.c b/config-verify.c index 91df71b..a91fcdf 100644 --- a/config-verify.c +++ b/config-verify.c @@ -10,6 +10,7 @@ #include "modules/alsa/alsa.h" #include "modules/backlight/backlight.h" +#include "modules/battery/battery.h" static const char * err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -461,13 +462,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info battery[] = { - {"name", true, &conf_verify_string}, - {"poll-interval", false, &conf_verify_int}, - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info clock[] = { {"date-format", false, &conf_verify_string}, {"time-format", false, &conf_verify_string}, @@ -526,6 +520,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) } modules_v2[] = { {"alsa", &module_alsa}, {"backlight", &module_backlight}, + {"battery", &module_battery}, }; static const struct { @@ -533,7 +528,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"battery", battery, sizeof(battery) / sizeof(battery[0])}, {"clock", clock, sizeof(clock) / sizeof(clock[0])}, {"i3", i3, sizeof(i3) / sizeof(i3[0])}, {"label", label, sizeof(label) / sizeof(label[0])}, diff --git a/config.c b/config.c index 8169dc5..775d139 100644 --- a/config.c +++ b/config.c @@ -416,20 +416,6 @@ module_i3_from_config(const struct yml_node *node, const struct font *parent_fon return module_i3(workspaces, yml_dict_length(c), left, right); } -static struct module * -module_battery_from_config(const struct yml_node *node, - const struct font *parent_font) -{ - const struct yml_node *c = yml_get_value(node, "content"); - const struct yml_node *name = yml_get_value(node, "name"); - const struct yml_node *poll_interval = yml_get_value(node, "poll_interval"); - - return module_battery( - yml_value_as_string(name), - conf_to_particle(c, parent_font), - poll_interval != NULL ? yml_value_as_int(poll_interval) : 60); -} - static struct module * module_xkb_from_config(const struct yml_node *node, const struct font *parent_font) @@ -575,6 +561,8 @@ conf_to_bar(const struct yml_node *bar) 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, "battery") == 0) + mods[idx] = module_battery.from_conf(m.value, font); else if (strcmp(mod_name, "label") == 0) mods[idx] = module_label_from_config(m.value, font); @@ -584,8 +572,6 @@ conf_to_bar(const struct yml_node *bar) mods[idx] = module_xwindow_from_config(m.value, font); else if (strcmp(mod_name, "i3") == 0) mods[idx] = module_i3_from_config(m.value, font); - else if (strcmp(mod_name, "battery") == 0) - 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, "mpd") == 0) diff --git a/modules/battery/battery.c b/modules/battery/battery.c index 2c3ba4f..e4442a1 100644 --- a/modules/battery/battery.c +++ b/modules/battery/battery.c @@ -16,6 +16,7 @@ #define LOG_MODULE "battery" #include "../../log.h" #include "../../bar.h" +#include "../../config.h" enum state { STATE_FULL, STATE_CHARGING, STATE_DISCHARGING }; @@ -326,9 +327,8 @@ out: return ret; } -struct module * -module_battery(const char *battery, struct particle *label, - int poll_interval_secs) +static struct module * +battery_new(const char *battery, struct particle *label, int poll_interval_secs) { struct private *m = malloc(sizeof(*m)); m->label = label; @@ -344,3 +344,28 @@ module_battery(const char *battery, 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 *c = yml_get_value(node, "content"); + const struct yml_node *name = yml_get_value(node, "name"); + const struct yml_node *poll_interval = yml_get_value(node, "poll_interval"); + + return battery_new( + yml_value_as_string(name), + conf_to_particle(c, parent_font), + poll_interval != NULL ? yml_value_as_int(poll_interval) : 60); +} + +const struct module_info module_battery = { + .from_conf = &from_conf, + .attr_count = 4, + .attrs = { + {"name", true, &conf_verify_string}, + {"poll-interval", false, &conf_verify_int}, + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/battery/battery.h b/modules/battery/battery.h index e025f3a..e8d89be 100644 --- a/modules/battery/battery.h +++ b/modules/battery/battery.h @@ -1,7 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_battery( - const char *battery, struct particle *label, int poll_interval_secs); +extern const struct module_info module_battery;