From 87640339e1e136e9fd9e951a20109ad4209b5544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:59:21 +0100 Subject: [PATCH] module/removables: export module info through the new module_info struct type --- config-verify.c | 11 ++-------- config.c | 22 ++------------------ modules/removables/removables.c | 37 ++++++++++++++++++++++++++++++--- modules/removables/removables.h | 5 +---- 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/config-verify.c b/config-verify.c index 169914a..9a0409a 100644 --- a/config-verify.c +++ b/config-verify.c @@ -17,6 +17,7 @@ #include "modules/label/label.h" #include "modules/mpd/mpd.h" #include "modules/network/network.h" +#include "modules/removables/removables.h" const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -438,14 +439,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info removables[] = { - {"spacing", false, &conf_verify_int}, - {"left-spacing", false, &conf_verify_int}, - {"right-spacing", false, &conf_verify_int}, - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info xkb[] = { {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, @@ -469,6 +462,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"label", &module_label}, {"mpd", &module_mpd}, {"network", &module_network}, + {"removables", &module_removables}, }; static const struct { @@ -476,7 +470,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"removables", removables, sizeof(removables) / sizeof(removables[0])}, {"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])}, {"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])}, }; diff --git a/config.c b/config.c index fb25202..1d340ba 100644 --- a/config.c +++ b/config.c @@ -377,24 +377,6 @@ module_xkb_from_config(const struct yml_node *node, return module_xkb(conf_to_particle(c, parent_font)); } -static struct module * -module_removables_from_config(const struct yml_node *node, - const struct font *parent_font) -{ - const struct yml_node *content = yml_get_value(node, "content"); - const struct yml_node *spacing = yml_get_value(node, "spacing"); - const struct yml_node *left_spacing = yml_get_value(node, "left_spacing"); - const struct yml_node *right_spacing = yml_get_value(node, "right_spacing"); - - int left = spacing != NULL ? yml_value_as_int(spacing) : - left_spacing != NULL ? yml_value_as_int(left_spacing) : 0; - int right = spacing != NULL ? yml_value_as_int(spacing) : - right_spacing != NULL ? yml_value_as_int(right_spacing) : 0; - - return module_removables( - conf_to_particle(content, parent_font), left, right); -} - struct bar * conf_to_bar(const struct yml_node *bar) { @@ -501,14 +483,14 @@ conf_to_bar(const struct yml_node *bar) mods[idx] = module_mpd.from_conf(m.value, font); else if (strcmp(mod_name, "network") == 0) mods[idx] = module_network.from_conf(m.value, font); + else if (strcmp(mod_name, "removables") == 0) + mods[idx] = module_removables.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) mods[idx] = module_xkb_from_config(m.value, font); - else if (strcmp(mod_name, "removables") == 0) - mods[idx] = module_removables_from_config(m.value, font); else assert(false); } diff --git a/modules/removables/removables.c b/modules/removables/removables.c index eab132f..0b23d07 100644 --- a/modules/removables/removables.c +++ b/modules/removables/removables.c @@ -18,8 +18,9 @@ #define LOG_ENABLE_DBG 0 #include "../../log.h" #include "../../bar.h" -#include "../../tllist.h" +#include "../../config.h" #include "../../particles/dynlist.h" +#include "../../tllist.h" typedef tll(char *) mount_point_list_t; @@ -544,8 +545,8 @@ run(struct module_run_context *ctx) return 0; } -struct module * -module_removables(struct particle *label, int left_spacing, int right_spacing) +static struct module * +removables_new(struct particle *label, int left_spacing, int right_spacing) { struct private *priv = malloc(sizeof(*priv)); priv->label = label; @@ -560,3 +561,33 @@ module_removables(struct particle *label, int left_spacing, int right_spacing) mod->content = &content; return mod; } + +static struct module * +from_conf(const struct yml_node *node, const struct font *parent_font) +{ + const struct yml_node *content = yml_get_value(node, "content"); + const struct yml_node *spacing = yml_get_value(node, "spacing"); + const struct yml_node *left_spacing = yml_get_value(node, "left_spacing"); + const struct yml_node *right_spacing = yml_get_value(node, "right_spacing"); + + int left = spacing != NULL ? yml_value_as_int(spacing) : + left_spacing != NULL ? yml_value_as_int(left_spacing) : 0; + int right = spacing != NULL ? yml_value_as_int(spacing) : + right_spacing != NULL ? yml_value_as_int(right_spacing) : 0; + + return removables_new( + conf_to_particle(content, parent_font), left, right); +} + +const struct module_info module_removables = { + .from_conf = &from_conf, + .attr_count = 5, + .attrs = { + {"spacing", false, &conf_verify_int}, + {"left-spacing", false, &conf_verify_int}, + {"right-spacing", false, &conf_verify_int}, + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/removables/removables.h b/modules/removables/removables.h index 9d780fc..d5e96aa 100644 --- a/modules/removables/removables.h +++ b/modules/removables/removables.h @@ -1,7 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_removables( - struct particle *label, int left_spacing, int right_spacing); +extern const struct module_info module_removables;