forked from external/yambar
module/backlight: export module info through the new module_info struct type
This commit is contained in:
parent
e536391df6
commit
3d36735f88
4 changed files with 33 additions and 28 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include "tllist.h"
|
#include "tllist.h"
|
||||||
|
|
||||||
#include "modules/alsa/alsa.h"
|
#include "modules/alsa/alsa.h"
|
||||||
|
#include "modules/backlight/backlight.h"
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
err_prefix(const keychain_t *chain, const struct yml_node *node)
|
err_prefix(const keychain_t *chain, const struct yml_node *node)
|
||||||
|
@ -460,12 +461,6 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct attr_info backlight[] = {
|
|
||||||
{"name", true, &conf_verify_string},
|
|
||||||
{"content", true, &conf_verify_particle},
|
|
||||||
{"anchors", false, NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct attr_info battery[] = {
|
static const struct attr_info battery[] = {
|
||||||
{"name", true, &conf_verify_string},
|
{"name", true, &conf_verify_string},
|
||||||
{"poll-interval", false, &conf_verify_int},
|
{"poll-interval", false, &conf_verify_int},
|
||||||
|
@ -530,6 +525,7 @@ verify_module(keychain_t *chain, const struct yml_node *node)
|
||||||
const struct module_info *info;
|
const struct module_info *info;
|
||||||
} modules_v2[] = {
|
} modules_v2[] = {
|
||||||
{"alsa", &module_alsa},
|
{"alsa", &module_alsa},
|
||||||
|
{"backlight", &module_backlight},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
|
@ -537,7 +533,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[] = {
|
||||||
{"backlight", backlight, sizeof(backlight) / sizeof(backlight[0])},
|
|
||||||
{"battery", battery, sizeof(battery) / sizeof(battery[0])},
|
{"battery", battery, sizeof(battery) / sizeof(battery[0])},
|
||||||
{"clock", clock, sizeof(clock) / sizeof(clock[0])},
|
{"clock", clock, sizeof(clock) / sizeof(clock[0])},
|
||||||
{"i3", i3, sizeof(i3) / sizeof(i3[0])},
|
{"i3", i3, sizeof(i3) / sizeof(i3[0])},
|
||||||
|
|
22
config.c
22
config.c
|
@ -438,17 +438,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_backlight_from_config(const struct yml_node *node,
|
|
||||||
const struct font *parent_font)
|
|
||||||
{
|
|
||||||
const struct yml_node *name = yml_get_value(node, "name");
|
|
||||||
const struct yml_node *c = yml_get_value(node, "content");
|
|
||||||
|
|
||||||
return module_backlight(
|
|
||||||
yml_value_as_string(name), conf_to_particle(c, parent_font));
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct module *
|
static struct module *
|
||||||
module_mpd_from_config(const struct yml_node *node,
|
module_mpd_from_config(const struct yml_node *node,
|
||||||
const struct font *parent_font)
|
const struct font *parent_font)
|
||||||
|
@ -582,7 +571,12 @@ conf_to_bar(const struct yml_node *bar)
|
||||||
struct yml_dict_iter m = yml_dict_iter(it.node);
|
struct yml_dict_iter m = yml_dict_iter(it.node);
|
||||||
const char *mod_name = yml_value_as_string(m.key);
|
const char *mod_name = yml_value_as_string(m.key);
|
||||||
|
|
||||||
if (strcmp(mod_name, "label") == 0)
|
if (strcmp(mod_name, "alsa") == 0)
|
||||||
|
mods[idx] = module_alsa.from_conf(m.value, font);
|
||||||
|
else if (strcmp(mod_name, "backlight") == 0)
|
||||||
|
mods[idx] = module_backlight.from_conf(m.value, font);
|
||||||
|
|
||||||
|
else if (strcmp(mod_name, "label") == 0)
|
||||||
mods[idx] = module_label_from_config(m.value, font);
|
mods[idx] = module_label_from_config(m.value, font);
|
||||||
else if (strcmp(mod_name, "clock") == 0)
|
else if (strcmp(mod_name, "clock") == 0)
|
||||||
mods[idx] = module_clock_from_config(m.value, font);
|
mods[idx] = module_clock_from_config(m.value, font);
|
||||||
|
@ -594,16 +588,12 @@ conf_to_bar(const struct yml_node *bar)
|
||||||
mods[idx] = module_battery_from_config(m.value, font);
|
mods[idx] = module_battery_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, "backlight") == 0)
|
|
||||||
mods[idx] = module_backlight_from_config(m.value, font);
|
|
||||||
else if (strcmp(mod_name, "mpd") == 0)
|
else if (strcmp(mod_name, "mpd") == 0)
|
||||||
mods[idx] = module_mpd_from_config(m.value, font);
|
mods[idx] = module_mpd_from_config(m.value, font);
|
||||||
else if (strcmp(mod_name, "network") == 0)
|
else if (strcmp(mod_name, "network") == 0)
|
||||||
mods[idx] = module_network_from_config(m.value, font);
|
mods[idx] = module_network_from_config(m.value, font);
|
||||||
else if (strcmp(mod_name, "removables") == 0)
|
else if (strcmp(mod_name, "removables") == 0)
|
||||||
mods[idx] = module_removables_from_config(m.value, font);
|
mods[idx] = module_removables_from_config(m.value, font);
|
||||||
else if (strcmp(mod_name, "alsa") == 0)
|
|
||||||
mods[idx] = module_alsa.from_conf(m.value, font);
|
|
||||||
else
|
else
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#define LOG_MODULE "battery"
|
#define LOG_MODULE "battery"
|
||||||
#include "../../log.h"
|
#include "../../log.h"
|
||||||
#include "../../bar.h"
|
#include "../../bar.h"
|
||||||
|
#include "../../config.h"
|
||||||
|
|
||||||
struct private {
|
struct private {
|
||||||
struct particle *label;
|
struct particle *label;
|
||||||
|
@ -198,8 +199,8 @@ run(struct module_run_context *ctx)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct module *
|
static struct module *
|
||||||
module_backlight(const char *device, struct particle *label)
|
backlight_new(const char *device, struct particle *label)
|
||||||
{
|
{
|
||||||
struct private *m = malloc(sizeof(*m));
|
struct private *m = malloc(sizeof(*m));
|
||||||
m->label = label;
|
m->label = label;
|
||||||
|
@ -214,3 +215,24 @@ module_backlight(const char *device, struct particle *label)
|
||||||
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 *name = yml_get_value(node, "name");
|
||||||
|
const struct yml_node *c = yml_get_value(node, "content");
|
||||||
|
|
||||||
|
return backlight_new(
|
||||||
|
yml_value_as_string(name), conf_to_particle(c, parent_font));
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct module_info module_backlight = {
|
||||||
|
.from_conf = &from_conf,
|
||||||
|
.attr_count = 3,
|
||||||
|
.attrs = {
|
||||||
|
{"name", true, &conf_verify_string},
|
||||||
|
{"content", true, &conf_verify_particle},
|
||||||
|
{"anchors", false, NULL},
|
||||||
|
{NULL, false, NULL},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../../module.h"
|
#include "../../module.h"
|
||||||
#include "../../particle.h"
|
|
||||||
|
|
||||||
struct module *module_backlight(const char *device, struct particle *label);
|
extern const struct module_info module_backlight;
|
||||||
|
|
Loading…
Add table
Reference in a new issue