From fb9f07dcadb00c61d7bed91cdabe3aa72036fad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:48:42 +0100 Subject: [PATCH] module/label: export module info through the new module_info struct type --- config-verify.c | 8 ++------ config.c | 11 ++--------- modules/label/label.c | 23 +++++++++++++++++++++-- modules/label/label.h | 4 +--- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/config-verify.c b/config-verify.c index aa4bd11..6504b19 100644 --- a/config-verify.c +++ b/config-verify.c @@ -13,6 +13,7 @@ #include "modules/battery/battery.h" #include "modules/clock/clock.h" #include "modules/i3/i3.h" +#include "modules/label/label.h" const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -434,11 +435,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info label[] = { - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info mpd[] = { {"host", true, &conf_verify_string}, {"port", false, &conf_verify_int}, @@ -480,6 +476,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"battery", &module_battery}, {"clock", &module_clock}, {"i3", &module_i3}, + {"label", &module_label}, }; static const struct { @@ -487,7 +484,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"label", label, sizeof(label) / sizeof(label[0])}, {"mpd", mpd, sizeof(mpd) / sizeof(mpd[0])}, {"network", network, sizeof(network) / sizeof(network[0])}, {"removables", removables, sizeof(removables) / sizeof(removables[0])}, diff --git a/config.c b/config.c index 7559384..b7907cb 100644 --- a/config.c +++ b/config.c @@ -362,13 +362,6 @@ conf_to_particle(const struct yml_node *node, const struct font *parent_font) return ret; } -static struct module * -module_label_from_config(const struct yml_node *node, const struct font *parent_font) -{ - const struct yml_node *c = yml_get_value(node, "content"); - return module_label(conf_to_particle(c, parent_font)); -} - static struct module * module_xwindow_from_config(const struct yml_node *node, const struct font *parent_font) { @@ -527,9 +520,9 @@ conf_to_bar(const struct yml_node *bar) mods[idx] = module_clock.from_conf(m.value, font); else if (strcmp(mod_name, "i3") == 0) mods[idx] = module_i3.from_conf(m.value, font); - else if (strcmp(mod_name, "label") == 0) - mods[idx] = module_label_from_config(m.value, font); + mods[idx] = module_label.from_conf(m.value, font); + else if (strcmp(mod_name, "xwindow") == 0) mods[idx] = module_xwindow_from_config(m.value, font); else if (strcmp(mod_name, "xkb") == 0) diff --git a/modules/label/label.c b/modules/label/label.c index 750082f..0533fa5 100644 --- a/modules/label/label.c +++ b/modules/label/label.c @@ -5,6 +5,8 @@ #include +#include "../../config.h" + struct private { struct particle *label; }; @@ -32,8 +34,8 @@ run(struct module_run_context *ctx) return 0; } -struct module * -module_label(struct particle *label) +static struct module * +label_new(struct particle *label) { struct private *m = malloc(sizeof(*m)); m->label = label; @@ -45,3 +47,20 @@ module_label(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"); + return label_new(conf_to_particle(c, parent_font)); +} + +const struct module_info module_label = { + .from_conf = &from_conf, + .attr_count = 2, + .attrs = { + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/label/label.h b/modules/label/label.h index 07a875e..b181d2d 100644 --- a/modules/label/label.h +++ b/modules/label/label.h @@ -1,6 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_label(struct particle *label); +extern const struct module_info module_label;