From 550d4ad5345c8038ed69fa1eae5a6ffec6af1e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:05:39 +0100 Subject: [PATCH] module/clock: export module info through the new module_info struct type --- config-verify.c | 10 ++-------- config.c | 17 ++--------------- modules/clock/clock.c | 31 ++++++++++++++++++++++++++++--- modules/clock/clock.h | 5 +---- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/config-verify.c b/config-verify.c index a91fcdf..d1223fb 100644 --- a/config-verify.c +++ b/config-verify.c @@ -11,6 +11,7 @@ #include "modules/alsa/alsa.h" #include "modules/backlight/backlight.h" #include "modules/battery/battery.h" +#include "modules/clock/clock.h" static const char * err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -462,13 +463,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info clock[] = { - {"date-format", false, &conf_verify_string}, - {"time-format", false, &conf_verify_string}, - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info label[] = { {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, @@ -521,6 +515,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"alsa", &module_alsa}, {"backlight", &module_backlight}, {"battery", &module_battery}, + {"clock", &module_clock}, }; static const struct { @@ -528,7 +523,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"clock", clock, sizeof(clock) / sizeof(clock[0])}, {"i3", i3, sizeof(i3) / sizeof(i3[0])}, {"label", label, sizeof(label) / sizeof(label[0])}, {"mpd", mpd, sizeof(mpd) / sizeof(mpd[0])}, diff --git a/config.c b/config.c index 775d139..57a6931 100644 --- a/config.c +++ b/config.c @@ -369,19 +369,6 @@ module_label_from_config(const struct yml_node *node, const struct font *parent_ return module_label(conf_to_particle(c, parent_font)); } -static struct module * -module_clock_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 *date_format = yml_get_value(node, "date-format"); - const struct yml_node *time_format = yml_get_value(node, "time-format"); - - return module_clock( - conf_to_particle(c, parent_font), - date_format != NULL ? yml_value_as_string(date_format) : "%x", - time_format != NULL ? yml_value_as_string(time_format) : "%H:%M"); -} - static struct module * module_xwindow_from_config(const struct yml_node *node, const struct font *parent_font) { @@ -563,11 +550,11 @@ conf_to_bar(const struct yml_node *bar) 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, "clock") == 0) + mods[idx] = module_clock.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); else if (strcmp(mod_name, "xwindow") == 0) mods[idx] = module_xwindow_from_config(m.value, font); else if (strcmp(mod_name, "i3") == 0) diff --git a/modules/clock/clock.c b/modules/clock/clock.c index 8b8e692..1bd3c36 100644 --- a/modules/clock/clock.c +++ b/modules/clock/clock.c @@ -7,6 +7,7 @@ #include #include "../../bar.h" +#include "../../config.h" struct private { struct particle *label; @@ -78,9 +79,8 @@ run(struct module_run_context *ctx) return 0; } -struct module * -module_clock(struct particle *label, - const char *date_format, const char *time_format) +static struct module * +clock_new(struct particle *label, const char *date_format, const char *time_format) { struct private *m = malloc(sizeof(*m)); m->label = label; @@ -94,3 +94,28 @@ module_clock(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 *date_format = yml_get_value(node, "date-format"); + const struct yml_node *time_format = yml_get_value(node, "time-format"); + + return clock_new( + conf_to_particle(c, parent_font), + date_format != NULL ? yml_value_as_string(date_format) : "%x", + time_format != NULL ? yml_value_as_string(time_format) : "%H:%M"); +} + +const struct module_info module_clock = { + .from_conf = &from_conf, + .attr_count = 4, + .attrs = { + {"date-format", false, &conf_verify_string}, + {"time-format", false, &conf_verify_string}, + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/clock/clock.h b/modules/clock/clock.h index 06c02f4..990ff64 100644 --- a/modules/clock/clock.h +++ b/modules/clock/clock.h @@ -1,7 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_clock( - struct particle *label, const char *date_format, const char *time_format); +extern const struct module_info module_clock;