forked from external/yambar
module/mpd: export module info through the new module_info struct type
This commit is contained in:
parent
fb9f07dcad
commit
a16e2f5a53
4 changed files with 37 additions and 34 deletions
|
@ -14,6 +14,8 @@
|
|||
#include "modules/clock/clock.h"
|
||||
#include "modules/i3/i3.h"
|
||||
#include "modules/label/label.h"
|
||||
#include "modules/label/label.h"
|
||||
#include "modules/mpd/mpd.h"
|
||||
|
||||
const char *
|
||||
conf_err_prefix(const keychain_t *chain, const struct yml_node *node)
|
||||
|
@ -435,13 +437,6 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
|||
return false;
|
||||
}
|
||||
|
||||
static const struct attr_info mpd[] = {
|
||||
{"host", true, &conf_verify_string},
|
||||
{"port", false, &conf_verify_int},
|
||||
{"content", true, &conf_verify_particle},
|
||||
{"anchors", false, NULL},
|
||||
};
|
||||
|
||||
static const struct attr_info network[] = {
|
||||
{"name", true, &conf_verify_string},
|
||||
{"content", true, &conf_verify_particle},
|
||||
|
@ -477,6 +472,7 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
|||
{"clock", &module_clock},
|
||||
{"i3", &module_i3},
|
||||
{"label", &module_label},
|
||||
{"mpd", &module_mpd},
|
||||
};
|
||||
|
||||
static const struct {
|
||||
|
@ -484,7 +480,6 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
|||
const struct attr_info *attrs;
|
||||
size_t count;
|
||||
} modules[] = {
|
||||
{"mpd", mpd, sizeof(mpd) / sizeof(mpd[0])},
|
||||
{"network", network, sizeof(network) / sizeof(network[0])},
|
||||
{"removables", removables, sizeof(removables) / sizeof(removables[0])},
|
||||
{"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])},
|
||||
|
|
21
config.c
21
config.c
|
@ -377,20 +377,6 @@ module_xkb_from_config(const struct yml_node *node,
|
|||
return module_xkb(conf_to_particle(c, parent_font));
|
||||
}
|
||||
|
||||
static struct module *
|
||||
module_mpd_from_config(const struct yml_node *node,
|
||||
const struct font *parent_font)
|
||||
{
|
||||
const struct yml_node *host = yml_get_value(node, "host");
|
||||
const struct yml_node *port = yml_get_value(node, "port");
|
||||
const struct yml_node *c = yml_get_value(node, "content");
|
||||
|
||||
return module_mpd(
|
||||
yml_value_as_string(host),
|
||||
port != NULL ? yml_value_as_int(port) : 0,
|
||||
conf_to_particle(c, parent_font));
|
||||
}
|
||||
|
||||
static struct module *
|
||||
module_network_from_config(const struct yml_node *node,
|
||||
const struct font *parent_font)
|
||||
|
@ -522,13 +508,14 @@ conf_to_bar(const struct yml_node *bar)
|
|||
mods[idx] = module_i3.from_conf(m.value, font);
|
||||
else if (strcmp(mod_name, "label") == 0)
|
||||
mods[idx] = module_label.from_conf(m.value, font);
|
||||
else if (strcmp(mod_name, "mpd") == 0)
|
||||
mods[idx] = module_mpd.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)
|
||||
else if (strcmp(mod_name, "xkb") == 0)
|
||||
mods[idx] = module_xkb_from_config(m.value, font);
|
||||
else if (strcmp(mod_name, "mpd") == 0)
|
||||
mods[idx] = module_mpd_from_config(m.value, font);
|
||||
else if (strcmp(mod_name, "network") == 0)
|
||||
mods[idx] = module_network_from_config(m.value, font);
|
||||
else if (strcmp(mod_name, "removables") == 0)
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define LOG_ENABLE_DBG 0
|
||||
#include "../../log.h"
|
||||
#include "../../bar.h"
|
||||
#include "../../config.h"
|
||||
|
||||
enum state {
|
||||
STATE_OFFLINE = 1000,
|
||||
|
@ -451,8 +452,8 @@ refresh_in(struct module *mod, long milli_seconds)
|
|||
return r == 0;
|
||||
}
|
||||
|
||||
struct module *
|
||||
module_mpd(const char *host, uint16_t port, struct particle *label)
|
||||
static struct module *
|
||||
mpd_new(const char *host, uint16_t port, struct particle *label)
|
||||
{
|
||||
struct private *priv = malloc(sizeof(*priv));
|
||||
priv->host = strdup(host);
|
||||
|
@ -478,3 +479,28 @@ module_mpd(const char *host, uint16_t port, struct particle *label)
|
|||
mod->refresh_in = &refresh_in;
|
||||
return mod;
|
||||
}
|
||||
|
||||
static struct module *
|
||||
from_conf(const struct yml_node *node, const struct font *parent_font)
|
||||
{
|
||||
const struct yml_node *host = yml_get_value(node, "host");
|
||||
const struct yml_node *port = yml_get_value(node, "port");
|
||||
const struct yml_node *c = yml_get_value(node, "content");
|
||||
|
||||
return mpd_new(
|
||||
yml_value_as_string(host),
|
||||
port != NULL ? yml_value_as_int(port) : 0,
|
||||
conf_to_particle(c, parent_font));
|
||||
}
|
||||
|
||||
const struct module_info module_mpd = {
|
||||
.from_conf = &from_conf,
|
||||
.attr_count = 4,
|
||||
.attrs = {
|
||||
{"host", true, &conf_verify_string},
|
||||
{"port", false, &conf_verify_int},
|
||||
{"content", true, &conf_verify_particle},
|
||||
{"anchors", false, NULL},
|
||||
{NULL, false, NULL},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../../module.h"
|
||||
#include "../../particle.h"
|
||||
|
||||
struct module *module_mpd(
|
||||
const char *host, uint16_t port, struct particle *label);
|
||||
extern const struct module_info module_mpd;
|
||||
|
|
Loading…
Add table
Reference in a new issue