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

This commit is contained in:
Daniel Eklöf 2019-01-12 12:05:39 +01:00
parent e24923e7cc
commit 550d4ad534
4 changed files with 33 additions and 30 deletions

View file

@ -11,6 +11,7 @@
#include "modules/alsa/alsa.h"
#include "modules/backlight/backlight.h"
#include "modules/battery/battery.h"
#include "modules/clock/clock.h"
static const char *
err_prefix(const keychain_t *chain, const struct yml_node *node)
@ -462,13 +463,6 @@ verify_module(keychain_t *chain, const struct yml_node *node)
return false;
}
static const struct attr_info clock[] = {
{"date-format", false, &conf_verify_string},
{"time-format", false, &conf_verify_string},
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
};
static const struct attr_info label[] = {
{"content", true, &conf_verify_particle},
{"anchors", false, NULL},
@ -521,6 +515,7 @@ verify_module(keychain_t *chain, const struct yml_node *node)
{"alsa", &module_alsa},
{"backlight", &module_backlight},
{"battery", &module_battery},
{"clock", &module_clock},
};
static const struct {
@ -528,7 +523,6 @@ verify_module(keychain_t *chain, const struct yml_node *node)
const struct attr_info *attrs;
size_t count;
} modules[] = {
{"clock", clock, sizeof(clock) / sizeof(clock[0])},
{"i3", i3, sizeof(i3) / sizeof(i3[0])},
{"label", label, sizeof(label) / sizeof(label[0])},
{"mpd", mpd, sizeof(mpd) / sizeof(mpd[0])},

View file

@ -369,19 +369,6 @@ module_label_from_config(const struct yml_node *node, const struct font *parent_
return module_label(conf_to_particle(c, parent_font));
}
static struct module *
module_clock_from_config(const struct yml_node *node, const struct font *parent_font)
{
const struct yml_node *c = yml_get_value(node, "content");
const struct yml_node *date_format = yml_get_value(node, "date-format");
const struct yml_node *time_format = yml_get_value(node, "time-format");
return module_clock(
conf_to_particle(c, parent_font),
date_format != NULL ? yml_value_as_string(date_format) : "%x",
time_format != NULL ? yml_value_as_string(time_format) : "%H:%M");
}
static struct module *
module_xwindow_from_config(const struct yml_node *node, const struct font *parent_font)
{
@ -563,11 +550,11 @@ conf_to_bar(const struct yml_node *bar)
mods[idx] = module_backlight.from_conf(m.value, font);
else if (strcmp(mod_name, "battery") == 0)
mods[idx] = module_battery.from_conf(m.value, font);
else if (strcmp(mod_name, "clock") == 0)
mods[idx] = module_clock.from_conf(m.value, font);
else if (strcmp(mod_name, "label") == 0)
mods[idx] = module_label_from_config(m.value, font);
else if (strcmp(mod_name, "clock") == 0)
mods[idx] = module_clock_from_config(m.value, font);
else if (strcmp(mod_name, "xwindow") == 0)
mods[idx] = module_xwindow_from_config(m.value, font);
else if (strcmp(mod_name, "i3") == 0)

View file

@ -7,6 +7,7 @@
#include <poll.h>
#include "../../bar.h"
#include "../../config.h"
struct private {
struct particle *label;
@ -78,9 +79,8 @@ run(struct module_run_context *ctx)
return 0;
}
struct module *
module_clock(struct particle *label,
const char *date_format, const char *time_format)
static struct module *
clock_new(struct particle *label, const char *date_format, const char *time_format)
{
struct private *m = malloc(sizeof(*m));
m->label = label;
@ -94,3 +94,28 @@ module_clock(struct particle *label,
mod->content = &content;
return mod;
}
static struct module *
from_conf(const struct yml_node *node, const struct font *parent_font)
{
const struct yml_node *c = yml_get_value(node, "content");
const struct yml_node *date_format = yml_get_value(node, "date-format");
const struct yml_node *time_format = yml_get_value(node, "time-format");
return clock_new(
conf_to_particle(c, parent_font),
date_format != NULL ? yml_value_as_string(date_format) : "%x",
time_format != NULL ? yml_value_as_string(time_format) : "%H:%M");
}
const struct module_info module_clock = {
.from_conf = &from_conf,
.attr_count = 4,
.attrs = {
{"date-format", false, &conf_verify_string},
{"time-format", false, &conf_verify_string},
{"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_clock(
struct particle *label, const char *date_format, const char *time_format);
extern const struct module_info module_clock;