module/removables: export module info through the new module_info struct type

This commit is contained in:
Daniel Eklöf 2019-01-12 12:59:21 +01:00
parent 697e613b2e
commit 87640339e1
4 changed files with 39 additions and 36 deletions

View file

@ -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])},
};

View file

@ -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);
}

View file

@ -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},
},
};

View file

@ -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;