forked from external/yambar
module/alsa: export module info through the new module_info struct type
This commit is contained in:
parent
eaf061ee57
commit
e536391df6
4 changed files with 44 additions and 20 deletions
|
@ -8,6 +8,8 @@
|
|||
#include "log.h"
|
||||
#include "tllist.h"
|
||||
|
||||
#include "modules/alsa/alsa.h"
|
||||
|
||||
static const char *
|
||||
err_prefix(const keychain_t *chain, const struct yml_node *node)
|
||||
{
|
||||
|
@ -458,13 +460,6 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
|||
return false;
|
||||
}
|
||||
|
||||
static const struct attr_info alsa[] = {
|
||||
{"card", true, &conf_verify_string},
|
||||
{"mixer", true, &conf_verify_string},
|
||||
{"content", true, &conf_verify_particle},
|
||||
{"anchors", false, NULL},
|
||||
};
|
||||
|
||||
static const struct attr_info backlight[] = {
|
||||
{"name", true, &conf_verify_string},
|
||||
{"content", true, &conf_verify_particle},
|
||||
|
@ -529,12 +524,19 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
|||
{"anchors", false, NULL},
|
||||
};
|
||||
|
||||
/* TODO: this will dlopened later */
|
||||
static const struct {
|
||||
const char *name;
|
||||
const struct module_info *info;
|
||||
} modules_v2[] = {
|
||||
{"alsa", &module_alsa},
|
||||
};
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
const struct attr_info *attrs;
|
||||
size_t count;
|
||||
} modules[] = {
|
||||
{"alsa", alsa, sizeof(alsa) / sizeof(alsa[0])},
|
||||
{"backlight", backlight, sizeof(backlight) / sizeof(backlight[0])},
|
||||
{"battery", battery, sizeof(battery) / sizeof(battery[0])},
|
||||
{"clock", clock, sizeof(clock) / sizeof(clock[0])},
|
||||
|
@ -547,6 +549,22 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
|||
{"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])},
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < sizeof(modules_v2) / sizeof(modules_v2[0]); i++) {
|
||||
if (strcmp(modules_v2[i].name, mod_name) != 0)
|
||||
continue;
|
||||
|
||||
if (!conf_verify_dict(chain_push(chain, mod_name),
|
||||
values,
|
||||
modules_v2[i].info->attrs,
|
||||
modules_v2[i].info->attr_count))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
chain_pop(chain);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(modules) / sizeof(modules[0]); i++) {
|
||||
if (strcmp(modules[i].name, mod_name) != 0)
|
||||
continue;
|
||||
|
|
2
config.c
2
config.c
|
@ -603,7 +603,7 @@ conf_to_bar(const struct yml_node *bar)
|
|||
else if (strcmp(mod_name, "removables") == 0)
|
||||
mods[idx] = module_removables_from_config(m.value, font);
|
||||
else if (strcmp(mod_name, "alsa") == 0)
|
||||
mods[idx] = module_alsa_from_config(m.value, font);
|
||||
mods[idx] = module_alsa.from_conf(m.value, font);
|
||||
else
|
||||
assert(false);
|
||||
}
|
||||
|
|
|
@ -251,7 +251,7 @@ run(struct module_run_context *ctx)
|
|||
}
|
||||
|
||||
static struct module *
|
||||
module_alsa(const char *card, const char *mixer, struct particle *label)
|
||||
alsa_new(const char *card, const char *mixer, struct particle *label)
|
||||
{
|
||||
struct private *priv = malloc(sizeof(*priv));
|
||||
priv->label = label;
|
||||
|
@ -269,16 +269,27 @@ module_alsa(const char *card, const char *mixer, struct particle *label)
|
|||
return mod;
|
||||
}
|
||||
|
||||
struct module *
|
||||
module_alsa_from_config(const struct yml_node *node,
|
||||
const struct font *parent_font)
|
||||
static struct module *
|
||||
from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||
{
|
||||
const struct yml_node *card = yml_get_value(node, "card");
|
||||
const struct yml_node *mixer = yml_get_value(node, "mixer");
|
||||
const struct yml_node *content = yml_get_value(node, "content");
|
||||
|
||||
return module_alsa(
|
||||
return alsa_new(
|
||||
yml_value_as_string(card),
|
||||
yml_value_as_string(mixer),
|
||||
conf_to_particle(content, parent_font));
|
||||
}
|
||||
|
||||
const struct module_info module_alsa = {
|
||||
.from_conf = &from_conf,
|
||||
.attr_count = 4,
|
||||
.attrs = {
|
||||
{"card", true, &conf_verify_string},
|
||||
{"mixer", true, &conf_verify_string},
|
||||
{"content", true, &conf_verify_particle},
|
||||
{"anchors", false, NULL},
|
||||
{NULL, false, NULL}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../font.h"
|
||||
#include "../../module.h"
|
||||
#include "../../particle.h"
|
||||
#include "../../yml.h"
|
||||
|
||||
struct module *module_alsa_from_config(
|
||||
const struct yml_node *node, const struct font *parent_font);
|
||||
extern const struct module_info module_alsa;
|
||||
|
|
Loading…
Add table
Reference in a new issue