forked from external/yambar
module/removables: export module info through the new module_info struct type
This commit is contained in:
parent
697e613b2e
commit
87640339e1
4 changed files with 39 additions and 36 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include "modules/label/label.h"
|
#include "modules/label/label.h"
|
||||||
#include "modules/mpd/mpd.h"
|
#include "modules/mpd/mpd.h"
|
||||||
#include "modules/network/network.h"
|
#include "modules/network/network.h"
|
||||||
|
#include "modules/removables/removables.h"
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
conf_err_prefix(const keychain_t *chain, const struct yml_node *node)
|
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;
|
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[] = {
|
static const struct attr_info xkb[] = {
|
||||||
{"content", true, &conf_verify_particle},
|
{"content", true, &conf_verify_particle},
|
||||||
{"anchors", false, NULL},
|
{"anchors", false, NULL},
|
||||||
|
@ -469,6 +462,7 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
||||||
{"label", &module_label},
|
{"label", &module_label},
|
||||||
{"mpd", &module_mpd},
|
{"mpd", &module_mpd},
|
||||||
{"network", &module_network},
|
{"network", &module_network},
|
||||||
|
{"removables", &module_removables},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
|
@ -476,7 +470,6 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
||||||
const struct attr_info *attrs;
|
const struct attr_info *attrs;
|
||||||
size_t count;
|
size_t count;
|
||||||
} modules[] = {
|
} modules[] = {
|
||||||
{"removables", removables, sizeof(removables) / sizeof(removables[0])},
|
|
||||||
{"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])},
|
{"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])},
|
||||||
{"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])},
|
{"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])},
|
||||||
};
|
};
|
||||||
|
|
22
config.c
22
config.c
|
@ -377,24 +377,6 @@ module_xkb_from_config(const struct yml_node *node,
|
||||||
return module_xkb(conf_to_particle(c, parent_font));
|
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 *
|
struct bar *
|
||||||
conf_to_bar(const struct yml_node *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);
|
mods[idx] = module_mpd.from_conf(m.value, font);
|
||||||
else if (strcmp(mod_name, "network") == 0)
|
else if (strcmp(mod_name, "network") == 0)
|
||||||
mods[idx] = module_network.from_conf(m.value, font);
|
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)
|
else if (strcmp(mod_name, "xwindow") == 0)
|
||||||
mods[idx] = module_xwindow_from_config(m.value, font);
|
mods[idx] = module_xwindow_from_config(m.value, font);
|
||||||
else if (strcmp(mod_name, "xkb") == 0)
|
else if (strcmp(mod_name, "xkb") == 0)
|
||||||
mods[idx] = module_xkb_from_config(m.value, font);
|
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
|
else
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
#define LOG_ENABLE_DBG 0
|
#define LOG_ENABLE_DBG 0
|
||||||
#include "../../log.h"
|
#include "../../log.h"
|
||||||
#include "../../bar.h"
|
#include "../../bar.h"
|
||||||
#include "../../tllist.h"
|
#include "../../config.h"
|
||||||
#include "../../particles/dynlist.h"
|
#include "../../particles/dynlist.h"
|
||||||
|
#include "../../tllist.h"
|
||||||
|
|
||||||
typedef tll(char *) mount_point_list_t;
|
typedef tll(char *) mount_point_list_t;
|
||||||
|
|
||||||
|
@ -544,8 +545,8 @@ run(struct module_run_context *ctx)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct module *
|
static struct module *
|
||||||
module_removables(struct particle *label, int left_spacing, int right_spacing)
|
removables_new(struct particle *label, int left_spacing, int right_spacing)
|
||||||
{
|
{
|
||||||
struct private *priv = malloc(sizeof(*priv));
|
struct private *priv = malloc(sizeof(*priv));
|
||||||
priv->label = label;
|
priv->label = label;
|
||||||
|
@ -560,3 +561,33 @@ module_removables(struct particle *label, int left_spacing, int right_spacing)
|
||||||
mod->content = &content;
|
mod->content = &content;
|
||||||
return mod;
|
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},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../../module.h"
|
#include "../../module.h"
|
||||||
#include "../../particle.h"
|
|
||||||
|
|
||||||
struct module *module_removables(
|
extern const struct module_info module_removables;
|
||||||
struct particle *label, int left_spacing, int right_spacing);
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue