From 8809cbb4814d8d78aad3e709dd4b86a065f47204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 11:18:46 +0100 Subject: [PATCH 01/31] Put each module in its own subdirectory --- CMakeLists.txt | 22 +++++++++++----------- config.c | 22 +++++++++++----------- modules/{ => alsa}/alsa.c | 6 +++--- modules/{ => alsa}/alsa.h | 4 ++-- modules/{ => backlight}/backlight.c | 4 ++-- modules/{ => backlight}/backlight.h | 4 ++-- modules/{ => battery}/battery.c | 4 ++-- modules/{ => battery}/battery.h | 4 ++-- modules/{ => clock}/clock.c | 2 +- modules/{ => clock}/clock.h | 4 ++-- modules/{ => i3}/i3.c | 6 +++--- modules/{ => i3}/i3.h | 4 ++-- modules/{ => label}/label.c | 0 modules/{ => label}/label.h | 4 ++-- modules/{ => mpd}/mpd.c | 4 ++-- modules/{ => mpd}/mpd.h | 4 ++-- modules/{ => network}/network.c | 10 ++++++---- modules/{ => network}/network.h | 4 ++-- modules/{ => removables}/removables.c | 8 ++++---- modules/{ => removables}/removables.h | 4 ++-- modules/{ => xkb}/xkb.c | 6 +++--- modules/{ => xkb}/xkb.h | 4 ++-- modules/{ => xwindow}/xwindow.c | 6 +++--- modules/{ => xwindow}/xwindow.h | 4 ++-- 24 files changed, 73 insertions(+), 71 deletions(-) rename modules/{ => alsa}/alsa.c (99%) rename modules/{ => alsa}/alsa.h (66%) rename modules/{ => backlight}/backlight.c (99%) rename modules/{ => backlight}/backlight.h (63%) rename modules/{ => battery}/battery.c (99%) rename modules/{ => battery}/battery.h (68%) rename modules/{ => clock}/clock.c (98%) rename modules/{ => clock}/clock.h (69%) rename modules/{ => i3}/i3.c (99%) rename modules/{ => i3}/i3.h (83%) rename modules/{ => label}/label.c (100%) rename modules/{ => label}/label.h (55%) rename modules/{ => mpd}/mpd.c (99%) rename modules/{ => mpd}/mpd.h (69%) rename modules/{ => network}/network.c (98%) rename modules/{ => network}/network.h (62%) rename modules/{ => removables}/removables.c (99%) rename modules/{ => removables}/removables.h (68%) rename modules/{ => xkb}/xkb.c (99%) rename modules/{ => xkb}/xkb.h (54%) rename modules/{ => xwindow}/xwindow.c (99%) rename modules/{ => xwindow}/xwindow.h (56%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d2853a..140cb2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,17 +51,17 @@ add_executable(f00bar particles/ramp.c particles/ramp.h particles/string.c particles/string.h - modules/alsa.c modules/alsa.h - modules/backlight.c modules/backlight.h - modules/battery.c modules/battery.h - modules/clock.c modules/clock.h - modules/i3.c modules/i3.h - modules/label.c modules/label.h - modules/mpd.c modules/mpd.h - modules/network.c modules/network.h - modules/removables.c modules/removables.h - modules/xkb.c modules/xkb.h - modules/xwindow.c modules/xwindow.h + modules/alsa/alsa.c modules/alsa/alsa.h + modules/backlight/backlight.c modules/backlight/backlight.h + modules/battery/battery.c modules/battery/battery.h + modules/clock/clock.c modules/clock/clock.h + modules/i3/i3.c modules/i3/i3.h + modules/label/label.c modules/label/label.h + modules/mpd/mpd.c modules/mpd/mpd.h + modules/network/network.c modules/network/network.h + modules/removables/removables.c modules/removables/removables.h + modules/xkb/xkb.c modules/xkb/xkb.h + modules/xwindow/xwindow.c modules/xwindow/xwindow.h ) target_compile_definitions(f00bar PRIVATE _GNU_SOURCE) diff --git a/config.c b/config.c index fcedfef..3bc9c1b 100644 --- a/config.c +++ b/config.c @@ -21,17 +21,17 @@ #include "particles/string.h" #include "module.h" -#include "modules/alsa.h" -#include "modules/backlight.h" -#include "modules/battery.h" -#include "modules/clock.h" -#include "modules/i3.h" -#include "modules/label.h" -#include "modules/mpd.h" -#include "modules/network.h" -#include "modules/removables.h" -#include "modules/xkb.h" -#include "modules/xwindow.h" +#include "modules/alsa/alsa.h" +#include "modules/backlight/backlight.h" +#include "modules/battery/battery.h" +#include "modules/clock/clock.h" +#include "modules/i3/i3.h" +#include "modules/label/label.h" +#include "modules/mpd/mpd.h" +#include "modules/network/network.h" +#include "modules/removables/removables.h" +#include "modules/xkb/xkb.h" +#include "modules/xwindow/xwindow.h" #include "config-verify.h" diff --git a/modules/alsa.c b/modules/alsa/alsa.c similarity index 99% rename from modules/alsa.c rename to modules/alsa/alsa.c index b67aabb..d4311ca 100644 --- a/modules/alsa.c +++ b/modules/alsa/alsa.c @@ -7,9 +7,9 @@ #define LOG_MODULE "alsa" #define LOG_ENABLE_DBG 0 -#include "../log.h" -#include "../bar.h" -#include "../tllist.h" +#include "../../log.h" +#include "../../bar.h" +#include "../../tllist.h" struct private { char *card; diff --git a/modules/alsa.h b/modules/alsa/alsa.h similarity index 66% rename from modules/alsa.h rename to modules/alsa/alsa.h index ec539e1..4c63775 100644 --- a/modules/alsa.h +++ b/modules/alsa/alsa.h @@ -1,7 +1,7 @@ #pragma once -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" struct module *module_alsa( const char *card, const char *mixer, struct particle *label); diff --git a/modules/backlight.c b/modules/backlight/backlight.c similarity index 99% rename from modules/backlight.c rename to modules/backlight/backlight.c index 7a3e08d..4c6a7bb 100644 --- a/modules/backlight.c +++ b/modules/backlight/backlight.c @@ -13,8 +13,8 @@ #include #define LOG_MODULE "battery" -#include "../log.h" -#include "../bar.h" +#include "../../log.h" +#include "../../bar.h" struct private { struct particle *label; diff --git a/modules/backlight.h b/modules/backlight/backlight.h similarity index 63% rename from modules/backlight.h rename to modules/backlight/backlight.h index f1e3a90..ab0b9b3 100644 --- a/modules/backlight.h +++ b/modules/backlight/backlight.h @@ -1,6 +1,6 @@ #pragma once -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" struct module *module_backlight(const char *device, struct particle *label); diff --git a/modules/battery.c b/modules/battery/battery.c similarity index 99% rename from modules/battery.c rename to modules/battery/battery.c index 43c2bee..2c3ba4f 100644 --- a/modules/battery.c +++ b/modules/battery/battery.c @@ -14,8 +14,8 @@ #include #define LOG_MODULE "battery" -#include "../log.h" -#include "../bar.h" +#include "../../log.h" +#include "../../bar.h" enum state { STATE_FULL, STATE_CHARGING, STATE_DISCHARGING }; diff --git a/modules/battery.h b/modules/battery/battery.h similarity index 68% rename from modules/battery.h rename to modules/battery/battery.h index 1d268ab..e025f3a 100644 --- a/modules/battery.h +++ b/modules/battery/battery.h @@ -1,7 +1,7 @@ #pragma once -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" struct module *module_battery( const char *battery, struct particle *label, int poll_interval_secs); diff --git a/modules/clock.c b/modules/clock/clock.c similarity index 98% rename from modules/clock.c rename to modules/clock/clock.c index a9f57e6..8b8e692 100644 --- a/modules/clock.c +++ b/modules/clock/clock.c @@ -6,7 +6,7 @@ #include -#include "../bar.h" +#include "../../bar.h" struct private { struct particle *label; diff --git a/modules/clock.h b/modules/clock/clock.h similarity index 69% rename from modules/clock.h rename to modules/clock/clock.h index 2af48db..06c02f4 100644 --- a/modules/clock.h +++ b/modules/clock/clock.h @@ -1,7 +1,7 @@ #pragma once -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" struct module *module_clock( struct particle *label, const char *date_format, const char *time_format); diff --git a/modules/i3.c b/modules/i3/i3.c similarity index 99% rename from modules/i3.c rename to modules/i3/i3.c index b910355..d55eb50 100644 --- a/modules/i3.c +++ b/modules/i3/i3.c @@ -19,10 +19,10 @@ #define LOG_MODULE "i3" #define LOG_ENABLE_DBG 0 -#include "../log.h" -#include "../bar.h" +#include "../../log.h" +#include "../../bar.h" -#include "../particles/dynlist.h" +#include "../../particles/dynlist.h" struct ws_content { char *name; diff --git a/modules/i3.h b/modules/i3/i3.h similarity index 83% rename from modules/i3.h rename to modules/i3/i3.h index d6be4e5..33b323b 100644 --- a/modules/i3.h +++ b/modules/i3/i3.h @@ -1,7 +1,7 @@ #pragma once -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" /* Maps workspace name to a content particle. */ struct i3_workspaces { diff --git a/modules/label.c b/modules/label/label.c similarity index 100% rename from modules/label.c rename to modules/label/label.c diff --git a/modules/label.h b/modules/label/label.h similarity index 55% rename from modules/label.h rename to modules/label/label.h index 7f04a10..07a875e 100644 --- a/modules/label.h +++ b/modules/label/label.h @@ -1,6 +1,6 @@ #pragma once -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" struct module *module_label(struct particle *label); diff --git a/modules/mpd.c b/modules/mpd/mpd.c similarity index 99% rename from modules/mpd.c rename to modules/mpd/mpd.c index 58583f6..13b3889 100644 --- a/modules/mpd.c +++ b/modules/mpd/mpd.c @@ -16,8 +16,8 @@ #define LOG_MODULE "mpd" #define LOG_ENABLE_DBG 0 -#include "../log.h" -#include "../bar.h" +#include "../../log.h" +#include "../../bar.h" enum state { STATE_OFFLINE = 1000, diff --git a/modules/mpd.h b/modules/mpd/mpd.h similarity index 69% rename from modules/mpd.h rename to modules/mpd/mpd.h index 3a69b7c..e1c5183 100644 --- a/modules/mpd.h +++ b/modules/mpd/mpd.h @@ -2,8 +2,8 @@ #include -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" struct module *module_mpd( const char *host, uint16_t port, struct particle *label); diff --git a/modules/network.c b/modules/network/network.c similarity index 98% rename from modules/network.c rename to modules/network/network.c index 9e747c1..e7da46d 100644 --- a/modules/network.c +++ b/modules/network/network.c @@ -16,10 +16,10 @@ #define LOG_MODULE "network" #define LOG_ENABLE_DBG 0 -#include "../log.h" -#include "../module.h" -#include "../bar.h" -#include "../tllist.h" +#include "../../log.h" +#include "../../module.h" +#include "../../bar.h" +#include "../../tllist.h" struct af_addr { int family; @@ -141,6 +141,8 @@ netlink_connect(void) .nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV6_IFADDR, }; + LOG_WARN("nl_pid_value = 0x%08x", addr.nl_pid); + if (bind(sock, (const struct sockaddr *)&addr, sizeof(addr)) == -1) { LOG_ERRNO("failed to bind netlink socket"); close(sock); diff --git a/modules/network.h b/modules/network/network.h similarity index 62% rename from modules/network.h rename to modules/network/network.h index 6ec57bd..6c3fee7 100644 --- a/modules/network.h +++ b/modules/network/network.h @@ -1,6 +1,6 @@ #pragma once -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" struct module *module_network(const char *iface, struct particle *label); diff --git a/modules/removables.c b/modules/removables/removables.c similarity index 99% rename from modules/removables.c rename to modules/removables/removables.c index 263206f..eab132f 100644 --- a/modules/removables.c +++ b/modules/removables/removables.c @@ -16,10 +16,10 @@ #define LOG_MODULE "removables" #define LOG_ENABLE_DBG 0 -#include "../log.h" -#include "../bar.h" -#include "../tllist.h" -#include "../particles/dynlist.h" +#include "../../log.h" +#include "../../bar.h" +#include "../../tllist.h" +#include "../../particles/dynlist.h" typedef tll(char *) mount_point_list_t; diff --git a/modules/removables.h b/modules/removables/removables.h similarity index 68% rename from modules/removables.h rename to modules/removables/removables.h index ff94a18..9d780fc 100644 --- a/modules/removables.h +++ b/modules/removables/removables.h @@ -1,7 +1,7 @@ #pragma once -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" struct module *module_removables( struct particle *label, int left_spacing, int right_spacing); diff --git a/modules/xkb.c b/modules/xkb/xkb.c similarity index 99% rename from modules/xkb.c rename to modules/xkb/xkb.c index ca99058..48d1854 100644 --- a/modules/xkb.c +++ b/modules/xkb/xkb.c @@ -11,9 +11,9 @@ #include #define LOG_MODULE "xkb" -#include "../log.h" -#include "../bar.h" -#include "../xcb.h" +#include "../../log.h" +#include "../../bar.h" +#include "../../xcb.h" struct layout { char *name; diff --git a/modules/xkb.h b/modules/xkb/xkb.h similarity index 54% rename from modules/xkb.h rename to modules/xkb/xkb.h index d8ec03d..c23129b 100644 --- a/modules/xkb.h +++ b/modules/xkb/xkb.h @@ -1,5 +1,5 @@ #pragma once -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" struct module *module_xkb(struct particle *label); diff --git a/modules/xwindow.c b/modules/xwindow/xwindow.c similarity index 99% rename from modules/xwindow.c rename to modules/xwindow/xwindow.c index f699192..515c0a0 100644 --- a/modules/xwindow.c +++ b/modules/xwindow/xwindow.c @@ -15,9 +15,9 @@ #include #define LOG_MODULE "xkb" -#include "../log.h" -#include "../bar.h" -#include "../xcb.h" +#include "../../log.h" +#include "../../bar.h" +#include "../../xcb.h" struct private { /* Accessed from bar thread only */ diff --git a/modules/xwindow.h b/modules/xwindow/xwindow.h similarity index 56% rename from modules/xwindow.h rename to modules/xwindow/xwindow.h index e178ff8..cba35f2 100644 --- a/modules/xwindow.h +++ b/modules/xwindow/xwindow.h @@ -1,6 +1,6 @@ #pragma once -#include "../module.h" -#include "../particle.h" +#include "../../module.h" +#include "../../particle.h" struct module *module_xwindow(struct particle *label); From 6cb2f52328cca4db6331170e069973df7d189664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 11:28:20 +0100 Subject: [PATCH 02/31] config: conf_particle_from() -> conf_to_particle() --- config.c | 61 ++++++++++++++++----------------------------- config.h | 4 +++ modules/alsa/alsa.c | 17 ++++++++++++- modules/alsa/alsa.h | 6 +++-- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/config.c b/config.c index 3bc9c1b..066f714 100644 --- a/config.c +++ b/config.c @@ -179,9 +179,6 @@ particle_string_from_config(const struct yml_node *node, fg_color, left_margin, right_margin, on_click_template); } -static struct particle * particle_from_config( - const struct yml_node *node, const struct font *parent_font); - static struct particle * particle_list_from_config(const struct yml_node *node, const struct font *parent_font, @@ -207,7 +204,7 @@ particle_list_from_config(const struct yml_node *node, it.node != NULL; yml_list_next(&it), idx++) { - parts[idx] = particle_from_config(it.node, parent_font); + parts[idx] = conf_to_particle(it.node, parent_font); } return particle_list_new( @@ -233,11 +230,11 @@ particle_map_from_config(const struct yml_node *node, yml_dict_next(&it), idx++) { particle_map[idx].tag_value = yml_value_as_string(it.key); - particle_map[idx].particle = particle_from_config(it.value, parent_font); + particle_map[idx].particle = conf_to_particle(it.value, parent_font); } struct particle *default_particle = def != NULL - ? particle_from_config(def, parent_font) + ? conf_to_particle(def, parent_font) : NULL; return particle_map_new( @@ -262,7 +259,7 @@ particle_ramp_from_config(const struct yml_node *node, it.node != NULL; yml_list_next(&it), idx++) { - parts[idx] = particle_from_config(it.node, parent_font); + parts[idx] = conf_to_particle(it.node, parent_font); } return particle_ramp_new( @@ -287,11 +284,11 @@ particle_progress_bar_from_config(const struct yml_node *node, return particle_progress_bar_new( yml_value_as_string(tag), yml_value_as_int(length), - particle_from_config(start, parent_font), - particle_from_config(end, parent_font), - particle_from_config(fill, parent_font), - particle_from_config(empty, parent_font), - particle_from_config(indicator, parent_font), + conf_to_particle(start, parent_font), + conf_to_particle(end, parent_font), + conf_to_particle(fill, parent_font), + conf_to_particle(empty, parent_font), + conf_to_particle(indicator, parent_font), left_margin, right_margin, on_click_template); } @@ -307,14 +304,14 @@ particle_simple_list_from_config(const struct yml_node *node, it.node != NULL; yml_list_next(&it), idx++) { - parts[idx] = particle_from_config(it.node, parent_font); + parts[idx] = conf_to_particle(it.node, parent_font); } return particle_list_new(parts, count, 0, 2, 0, 0, NULL); } -static struct particle * -particle_from_config(const struct yml_node *node, const struct font *parent_font) +struct particle * +conf_to_particle(const struct yml_node *node, const struct font *parent_font) { if (yml_is_list(node)) return particle_simple_list_from_config(node, parent_font); @@ -369,7 +366,7 @@ static struct module * module_label_from_config(const struct yml_node *node, const struct font *parent_font) { const struct yml_node *c = yml_get_value(node, "content"); - return module_label(particle_from_config(c, parent_font)); + return module_label(conf_to_particle(c, parent_font)); } static struct module * @@ -380,7 +377,7 @@ module_clock_from_config(const struct yml_node *node, const struct font *parent_ const struct yml_node *time_format = yml_get_value(node, "time-format"); return module_clock( - particle_from_config(c, parent_font), + 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"); } @@ -389,7 +386,7 @@ static struct module * module_xwindow_from_config(const struct yml_node *node, const struct font *parent_font) { const struct yml_node *c = yml_get_value(node, "content"); - return module_xwindow(particle_from_config(c, parent_font)); + return module_xwindow(conf_to_particle(c, parent_font)); } static struct module * @@ -413,7 +410,7 @@ module_i3_from_config(const struct yml_node *node, const struct font *parent_fon yml_dict_next(&it), idx++) { workspaces[idx].name = yml_value_as_string(it.key); - workspaces[idx].content = particle_from_config(it.value, parent_font); + workspaces[idx].content = conf_to_particle(it.value, parent_font); } return module_i3(workspaces, yml_dict_length(c), left, right); @@ -429,7 +426,7 @@ module_battery_from_config(const struct yml_node *node, return module_battery( yml_value_as_string(name), - particle_from_config(c, parent_font), + conf_to_particle(c, parent_font), poll_interval != NULL ? yml_value_as_int(poll_interval) : 60); } @@ -438,7 +435,7 @@ module_xkb_from_config(const struct yml_node *node, const struct font *parent_font) { const struct yml_node *c = yml_get_value(node, "content"); - return module_xkb(particle_from_config(c, parent_font)); + return module_xkb(conf_to_particle(c, parent_font)); } static struct module * @@ -449,7 +446,7 @@ module_backlight_from_config(const struct yml_node *node, const struct yml_node *c = yml_get_value(node, "content"); return module_backlight( - yml_value_as_string(name), particle_from_config(c, parent_font)); + yml_value_as_string(name), conf_to_particle(c, parent_font)); } static struct module * @@ -463,7 +460,7 @@ module_mpd_from_config(const struct yml_node *node, return module_mpd( yml_value_as_string(host), port != NULL ? yml_value_as_int(port) : 0, - particle_from_config(c, parent_font)); + conf_to_particle(c, parent_font)); } static struct module * @@ -474,7 +471,7 @@ module_network_from_config(const struct yml_node *node, const struct yml_node *content = yml_get_value(node, "content"); return module_network( - yml_value_as_string(name), particle_from_config(content, parent_font)); + yml_value_as_string(name), conf_to_particle(content, parent_font)); } static struct module * @@ -492,21 +489,7 @@ module_removables_from_config(const struct yml_node *node, right_spacing != NULL ? yml_value_as_int(right_spacing) : 0; return module_removables( - particle_from_config(content, parent_font), left, right); -} - -static struct module * -module_alsa_from_config(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( - yml_value_as_string(card), - yml_value_as_string(mixer), - particle_from_config(content, parent_font)); + conf_to_particle(content, parent_font), left, right); } struct bar * diff --git a/config.h b/config.h index 422f782..accc424 100644 --- a/config.h +++ b/config.h @@ -3,5 +3,9 @@ #include "bar.h" #include "yml.h" #include "font.h" +#include "particle.h" struct bar *conf_to_bar(const struct yml_node *bar); + +struct particle * conf_to_particle( + const struct yml_node *node, const struct font *parent_font); diff --git a/modules/alsa/alsa.c b/modules/alsa/alsa.c index d4311ca..2e55ea9 100644 --- a/modules/alsa/alsa.c +++ b/modules/alsa/alsa.c @@ -9,6 +9,7 @@ #define LOG_ENABLE_DBG 0 #include "../../log.h" #include "../../bar.h" +#include "../../config.h" #include "../../tllist.h" struct private { @@ -249,7 +250,7 @@ run(struct module_run_context *ctx) return 0; } -struct module * +static struct module * module_alsa(const char *card, const char *mixer, struct particle *label) { struct private *priv = malloc(sizeof(*priv)); @@ -267,3 +268,17 @@ module_alsa(const char *card, const char *mixer, struct particle *label) mod->content = &content; return mod; } + +struct module * +module_alsa_from_config(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( + yml_value_as_string(card), + yml_value_as_string(mixer), + conf_to_particle(content, parent_font)); +} diff --git a/modules/alsa/alsa.h b/modules/alsa/alsa.h index 4c63775..6570895 100644 --- a/modules/alsa/alsa.h +++ b/modules/alsa/alsa.h @@ -1,7 +1,9 @@ #pragma once +#include "../../font.h" #include "../../module.h" #include "../../particle.h" +#include "../../yml.h" -struct module *module_alsa( - const char *card, const char *mixer, struct particle *label); +struct module *module_alsa_from_config( + const struct yml_node *node, const struct font *parent_font); From d44db1a6a8c71bf59709fa486d3a7f3362ade2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 11:46:26 +0100 Subject: [PATCH 03/31] config: verify: expose verification primitives --- config-verify.c | 207 +++++++++++++++++++++--------------------------- config-verify.h | 37 ++++++++- 2 files changed, 128 insertions(+), 116 deletions(-) diff --git a/config-verify.c b/config-verify.c index 4ac6c63..490bab1 100644 --- a/config-verify.c +++ b/config-verify.c @@ -1,4 +1,4 @@ -#include "config-verify.h" +#include "config.h" #include #include @@ -8,27 +8,6 @@ #include "log.h" #include "tllist.h" -typedef tll(const char *) keychain_t; - -struct attr_info { - const char *name; - bool required; - bool (*verify)(keychain_t *chain, const struct yml_node *node); -}; - -static keychain_t * -chain_push(keychain_t *chain, const char *key) -{ - tll_push_back(*chain, key); - return chain; -} - -static void -chain_pop(keychain_t *chain) -{ - tll_pop_back(*chain); -} - static const char * err_prefix(const keychain_t *chain, const struct yml_node *node) { @@ -46,8 +25,8 @@ err_prefix(const keychain_t *chain, const struct yml_node *node) return msg; } -static bool -verify_string(keychain_t *chain, const struct yml_node *node) +bool +conf_verify_string(keychain_t *chain, const struct yml_node *node) { const char *s = yml_value_as_string(node); if (s == NULL) { @@ -58,8 +37,8 @@ verify_string(keychain_t *chain, const struct yml_node *node) return true; } -static bool -verify_int(keychain_t *chain, const struct yml_node *node) +bool +conf_verify_int(keychain_t *chain, const struct yml_node *node) { if (yml_value_is_int(node)) return true; @@ -69,9 +48,9 @@ verify_int(keychain_t *chain, const struct yml_node *node) return false; } -static bool -verify_enum(keychain_t *chain, const struct yml_node *node, - const char *values[], size_t count) +bool +conf_verify_enum(keychain_t *chain, const struct yml_node *node, + const char *values[], size_t count) { const char *s = yml_value_as_string(node); if (s == NULL) { @@ -91,9 +70,9 @@ verify_enum(keychain_t *chain, const struct yml_node *node, return false; } -static bool -verify_dict(keychain_t *chain, const struct yml_node *node, - const struct attr_info info[], size_t count) +bool +conf_verify_dict(keychain_t *chain, const struct yml_node *node, + const struct attr_info info[], size_t count) { if (!yml_is_dict(node)) { LOG_ERR("%s: must be a dictionary", err_prefix(chain, node)); @@ -146,8 +125,8 @@ verify_dict(keychain_t *chain, const struct yml_node *node, return true; } -static bool -verify_color(keychain_t *chain, const struct yml_node *node) +bool +conf_verify_color(keychain_t *chain, const struct yml_node *node) { const char *s = yml_value_as_string(node); if (s == NULL) { @@ -168,14 +147,14 @@ verify_color(keychain_t *chain, const struct yml_node *node) } -static bool -verify_font(keychain_t *chain, const struct yml_node *node) +bool +conf_verify_font(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { - {"family", true, &verify_string}, + {"family", true, &conf_verify_string}, }; - return verify_dict(chain, node, attrs, sizeof(attrs) / sizeof(attrs[0])); + return conf_verify_dict(chain, node, attrs, sizeof(attrs) / sizeof(attrs[0])); } static bool verify_decoration(keychain_t *chain, const struct yml_node *node); @@ -227,12 +206,12 @@ verify_decoration(keychain_t *chain, const struct yml_node *node) } static const struct attr_info background[] = { - {"color", true, &verify_color}, + {"color", true, &conf_verify_color}, }; static const struct attr_info underline[] = { - {"size", true, &verify_int}, - {"color", true, &verify_color}, + {"size", true, &conf_verify_int}, + {"color", true, &conf_verify_color}, }; static const struct { @@ -248,7 +227,7 @@ verify_decoration(keychain_t *chain, const struct yml_node *node) if (strcmp(decos[i].name, deco_name) != 0) continue; - if (!verify_dict(chain_push(chain, deco_name), + if (!conf_verify_dict(chain_push(chain, deco_name), values, decos[i].attrs, decos[i].count)) { return false; @@ -263,8 +242,6 @@ verify_decoration(keychain_t *chain, const struct yml_node *node) return false; } -static bool verify_particle(keychain_t *chain, const struct yml_node *node); - static bool verify_list_items(keychain_t *chain, const struct yml_node *node) { @@ -274,7 +251,7 @@ verify_list_items(keychain_t *chain, const struct yml_node *node) it.node != NULL; yml_list_next(&it)) { - if (!verify_particle(chain, it.node)) + if (!conf_verify_particle(chain, it.node)) return false; } @@ -302,7 +279,7 @@ verify_map_values(keychain_t *chain, const struct yml_node *node) return false; } - if (!verify_particle(chain_push(chain, key), it.value)) + if (!conf_verify_particle(chain_push(chain, key), it.value)) return false; chain_pop(chain); @@ -312,7 +289,7 @@ verify_map_values(keychain_t *chain, const struct yml_node *node) } static bool -verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) +conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) { assert(yml_is_dict(node)); @@ -333,10 +310,10 @@ verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) } #define COMMON_ATTRS \ - {"margin", false, &verify_int}, \ - {"left-margin", false, &verify_int}, \ - {"right-margin", false, &verify_int}, \ - {"on-click", false, &verify_string}, + {"margin", false, &conf_verify_int}, \ + {"left-margin", false, &conf_verify_int}, \ + {"right-margin", false, &conf_verify_int}, \ + {"on-click", false, &conf_verify_string}, static const struct attr_info empty[] = { COMMON_ATTRS @@ -344,42 +321,42 @@ verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) static const struct attr_info list[] = { {"items", true, &verify_list_items}, - {"spacing", false, &verify_int}, - {"left-spacing", false, &verify_int}, - {"right-spacing", false, &verify_int}, + {"spacing", false, &conf_verify_int}, + {"left-spacing", false, &conf_verify_int}, + {"right-spacing", false, &conf_verify_int}, COMMON_ATTRS }; static const struct attr_info map[] = { - {"tag", true, &verify_string}, + {"tag", true, &conf_verify_string}, {"values", true, &verify_map_values}, - {"default", false, &verify_particle}, + {"default", false, &conf_verify_particle}, COMMON_ATTRS }; static const struct attr_info progress_bar[] = { - {"tag", true, &verify_string}, - {"length", true, &verify_int}, + {"tag", true, &conf_verify_string}, + {"length", true, &conf_verify_int}, /* TODO: make these optional? Default to empty */ - {"start", true, &verify_particle}, - {"end", true, &verify_particle}, - {"fill", true, &verify_particle}, - {"empty", true, &verify_particle}, - {"indicator", true, &verify_particle}, + {"start", true, &conf_verify_particle}, + {"end", true, &conf_verify_particle}, + {"fill", true, &conf_verify_particle}, + {"empty", true, &conf_verify_particle}, + {"indicator", true, &conf_verify_particle}, COMMON_ATTRS }; static const struct attr_info ramp[] = { - {"tag", true, &verify_string}, + {"tag", true, &conf_verify_string}, {"items", true, &verify_list_items}, COMMON_ATTRS }; static const struct attr_info string[] = { - {"text", true, &verify_string}, - {"max", false, &verify_int}, - {"font", false, &verify_font}, - {"foreground", false, &verify_color}, + {"text", true, &conf_verify_string}, + {"max", false, &conf_verify_int}, + {"font", false, &conf_verify_font}, + {"foreground", false, &conf_verify_color}, {"deco", false, &verify_decoration}, COMMON_ATTRS }; @@ -403,7 +380,7 @@ verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) if (strcmp(particles[i].name, particle_name) != 0) continue; - if (!verify_dict(chain_push(chain, particle_name), values, + if (!conf_verify_dict(chain_push(chain, particle_name), values, particles[i].attrs, particles[i].count)) { return false; @@ -418,11 +395,11 @@ verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) return false; } -static bool -verify_particle(keychain_t *chain, const struct yml_node *node) +bool +conf_verify_particle(keychain_t *chain, const struct yml_node *node) { if (yml_is_dict(node)) - return verify_particle_dictionary(chain, node); + return conf_verify_particle_dictionary(chain, node); else if (yml_is_list(node)) return verify_list_items(chain, node); else { @@ -453,7 +430,7 @@ verify_i3_content(keychain_t *chain, const struct yml_node *node) return false; } - if (!verify_particle(chain_push(chain, key), it.value)) + if (!conf_verify_particle(chain_push(chain, key), it.value)) return false; chain_pop(chain); @@ -482,73 +459,73 @@ verify_module(keychain_t *chain, const struct yml_node *node) } static const struct attr_info alsa[] = { - {"card", true, &verify_string}, - {"mixer", true, &verify_string}, - {"content", true, &verify_particle}, + {"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, &verify_string}, - {"content", true, &verify_particle}, + {"name", true, &conf_verify_string}, + {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, }; static const struct attr_info battery[] = { - {"name", true, &verify_string}, - {"poll-interval", false, &verify_int}, - {"content", true, &verify_particle}, + {"name", true, &conf_verify_string}, + {"poll-interval", false, &conf_verify_int}, + {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, }; static const struct attr_info clock[] = { - {"date-format", false, &verify_string}, - {"time-format", false, &verify_string}, - {"content", true, &verify_particle}, + {"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, &verify_particle}, + {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, }; static const struct attr_info mpd[] = { - {"host", true, &verify_string}, - {"port", false, &verify_int}, - {"content", true, &verify_particle}, + {"host", true, &conf_verify_string}, + {"port", false, &conf_verify_int}, + {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, }; static const struct attr_info i3[] = { - {"spacing", false, &verify_int}, - {"left-spacing", false, &verify_int}, - {"right-spacing", false, &verify_int}, + {"spacing", false, &conf_verify_int}, + {"left-spacing", false, &conf_verify_int}, + {"right-spacing", false, &conf_verify_int}, {"content", true, &verify_i3_content}, {"anchors", false, NULL}, }; static const struct attr_info network[] = { - {"name", true, &verify_string}, - {"content", true, &verify_particle}, + {"name", true, &conf_verify_string}, + {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, }; static const struct attr_info removables[] = { - {"spacing", false, &verify_int}, - {"left-spacing", false, &verify_int}, - {"right-spacing", false, &verify_int}, - {"content", true, &verify_particle}, + {"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[] = { - {"content", true, &verify_particle}, + {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, }; static const struct attr_info xwindow[] = { - {"content", true, &verify_particle}, + {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, }; @@ -574,7 +551,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) if (strcmp(modules[i].name, mod_name) != 0) continue; - if (!verify_dict(chain_push(chain, mod_name), values, + if (!conf_verify_dict(chain_push(chain, mod_name), values, modules[i].attrs, modules[i].count)) { return false; @@ -611,21 +588,21 @@ static bool verify_bar_border(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { - {"width", true, &verify_int}, - {"color", true, &verify_color}, + {"width", true, &conf_verify_int}, + {"color", true, &conf_verify_color}, }; - return verify_dict(chain, node, attrs, sizeof(attrs) / sizeof(attrs[0])); + return conf_verify_dict(chain, node, attrs, sizeof(attrs) / sizeof(attrs[0])); } static bool verify_bar_location(keychain_t *chain, const struct yml_node *node) { - return verify_enum(chain, node, (const char *[]){"top", "bottom"}, 2); + return conf_verify_enum(chain, node, (const char *[]){"top", "bottom"}, 2); } bool -config_verify_bar(const struct yml_node *bar) +conf_verify_bar(const struct yml_node *bar) { if (!yml_is_dict(bar)) { LOG_ERR("bar is not a dictionary"); @@ -636,27 +613,27 @@ config_verify_bar(const struct yml_node *bar) chain_push(&chain, "bar"); static const struct attr_info attrs[] = { - {"height", true, &verify_int}, + {"height", true, &conf_verify_int}, {"location", true, &verify_bar_location}, - {"background", true, &verify_color}, + {"background", true, &conf_verify_color}, - {"spacing", false, &verify_int}, - {"left-spacing", false, &verify_int}, - {"right-spacing", false, &verify_int}, + {"spacing", false, &conf_verify_int}, + {"left-spacing", false, &conf_verify_int}, + {"right-spacing", false, &conf_verify_int}, - {"margin", false, &verify_int}, - {"left_margin", false, &verify_int}, - {"right_margin", false, &verify_int}, + {"margin", false, &conf_verify_int}, + {"left_margin", false, &conf_verify_int}, + {"right_margin", false, &conf_verify_int}, {"border", false, &verify_bar_border}, - {"font", false, &verify_font}, + {"font", false, &conf_verify_font}, {"left", false, &verify_module_list}, {"center", false, &verify_module_list}, {"right", false, &verify_module_list}, }; - bool ret = verify_dict(&chain, bar, attrs, sizeof(attrs) / sizeof(attrs[0])); + bool ret = conf_verify_dict(&chain, bar, attrs, sizeof(attrs) / sizeof(attrs[0])); tll_free(chain); return ret; } diff --git a/config-verify.h b/config-verify.h index 92b3941..91132c6 100644 --- a/config-verify.h +++ b/config-verify.h @@ -1,5 +1,40 @@ #pragma once + #include + +#include "tllist.h" #include "yml.h" -bool config_verify_bar(const struct yml_node *bar); +typedef tll(const char *) keychain_t; + +struct attr_info { + const char *name; + bool required; + bool (*verify)(keychain_t *chain, const struct yml_node *node); +}; + +static inline keychain_t * +chain_push(keychain_t *chain, const char *key) +{ + tll_push_back(*chain, key); + return chain; +} + +static inline void +chain_pop(keychain_t *chain) +{ + tll_pop_back(*chain); +} + +bool conf_verify_string(keychain_t *chain, const struct yml_node *node); +bool conf_verify_int(keychain_t *chain, const struct yml_node *node); + +bool conf_verify_enum(keychain_t *chain, const struct yml_node *node, + const char *values[], size_t count); +bool conf_verify_dict(keychain_t *chain, const struct yml_node *node, + const struct attr_info info[], size_t count); + +bool conf_verify_color(keychain_t *chain, const struct yml_node *node); +bool conf_verify_font(keychain_t *chain, const struct yml_node *node); + +bool conf_verify_particle(keychain_t *chain, const struct yml_node *node); From 3c870f759aeb00c33ed359597edfdb0d22f24692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 11:47:01 +0100 Subject: [PATCH 04/31] config: verify: config_verify_bar() -> conf_verify_bar() --- config.c | 2 +- config.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 066f714..b2afafa 100644 --- a/config.c +++ b/config.c @@ -495,7 +495,7 @@ module_removables_from_config(const struct yml_node *node, struct bar * conf_to_bar(const struct yml_node *bar) { - if (!config_verify_bar(bar)) + if (!conf_verify_bar(bar)) return NULL; struct bar_config conf = {0}; diff --git a/config.h b/config.h index accc424..762e7fb 100644 --- a/config.h +++ b/config.h @@ -5,6 +5,7 @@ #include "font.h" #include "particle.h" +bool conf_verify_bar(const struct yml_node *bar); struct bar *conf_to_bar(const struct yml_node *bar); struct particle * conf_to_particle( From 4dd1a24af692f343a8087f910b3d073c6005d2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 11:47:30 +0100 Subject: [PATCH 05/31] config: sort includes, add comment --- config.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config.h b/config.h index 762e7fb..c659e0c 100644 --- a/config.h +++ b/config.h @@ -1,12 +1,16 @@ #pragma once #include "bar.h" -#include "yml.h" #include "font.h" #include "particle.h" +#include "yml.h" bool conf_verify_bar(const struct yml_node *bar); struct bar *conf_to_bar(const struct yml_node *bar); +/* + * Utility functions, for e.g. modules + */ + struct particle * conf_to_particle( const struct yml_node *node, const struct font *parent_font); From eaf061ee574096d70bd8d829659e2d340f06130d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 11:52:46 +0100 Subject: [PATCH 06/31] module: define a struct for module meta data * Function pointer; instantiates the module from a yml conf node * Its (top-level) configuration attributes --- module.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/module.h b/module.h index 012a2fd..450dcd6 100644 --- a/module.h +++ b/module.h @@ -3,12 +3,22 @@ #include #include +#include "config-verify.h" #include "particle.h" #include "tag.h" +#include "yml.h" struct bar; struct module; +struct module_info { + struct module *(*from_conf)(const struct yml_node *node, + const struct font *parent_font); + + size_t attr_count; /* TODO: remove, NULL-terminate attr list instead */ + const struct attr_info attrs[]; +}; + struct module_run_context { struct module *module; int ready_fd; From e536391df6f2eae5fb15a903564fc73e02de94a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 11:53:55 +0100 Subject: [PATCH 07/31] module/alsa: export module info through the new module_info struct type --- config-verify.c | 34 ++++++++++++++++++++++++++-------- config.c | 2 +- modules/alsa/alsa.c | 21 ++++++++++++++++----- modules/alsa/alsa.h | 7 +------ 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/config-verify.c b/config-verify.c index 490bab1..9d9af2f 100644 --- a/config-verify.c +++ b/config-verify.c @@ -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; diff --git a/config.c b/config.c index b2afafa..f712b18 100644 --- a/config.c +++ b/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); } diff --git a/modules/alsa/alsa.c b/modules/alsa/alsa.c index 2e55ea9..5a34346 100644 --- a/modules/alsa/alsa.c +++ b/modules/alsa/alsa.c @@ -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} + }, +}; diff --git a/modules/alsa/alsa.h b/modules/alsa/alsa.h index 6570895..a19c122 100644 --- a/modules/alsa/alsa.h +++ b/modules/alsa/alsa.h @@ -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; From 3d36735f883c817bf22826d25a7430519f446eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 11:58:37 +0100 Subject: [PATCH 08/31] module/backlight: export module info through the new module_info struct type --- config-verify.c | 9 ++------- config.c | 22 ++++++---------------- modules/backlight/backlight.c | 26 ++++++++++++++++++++++++-- modules/backlight/backlight.h | 4 +--- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/config-verify.c b/config-verify.c index 9d9af2f..91df71b 100644 --- a/config-verify.c +++ b/config-verify.c @@ -9,6 +9,7 @@ #include "tllist.h" #include "modules/alsa/alsa.h" +#include "modules/backlight/backlight.h" static const char * 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; } - 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[] = { {"name", true, &conf_verify_string}, {"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; } modules_v2[] = { {"alsa", &module_alsa}, + {"backlight", &module_backlight}, }; static const struct { @@ -537,7 +533,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"backlight", backlight, sizeof(backlight) / sizeof(backlight[0])}, {"battery", battery, sizeof(battery) / sizeof(battery[0])}, {"clock", clock, sizeof(clock) / sizeof(clock[0])}, {"i3", i3, sizeof(i3) / sizeof(i3[0])}, diff --git a/config.c b/config.c index f712b18..8169dc5 100644 --- a/config.c +++ b/config.c @@ -438,17 +438,6 @@ module_xkb_from_config(const struct yml_node *node, 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 * module_mpd_from_config(const struct yml_node *node, 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); 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); else if (strcmp(mod_name, "clock") == 0) 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); else if (strcmp(mod_name, "xkb") == 0) 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) 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) 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 assert(false); } diff --git a/modules/backlight/backlight.c b/modules/backlight/backlight.c index 4c6a7bb..1ba2334 100644 --- a/modules/backlight/backlight.c +++ b/modules/backlight/backlight.c @@ -15,6 +15,7 @@ #define LOG_MODULE "battery" #include "../../log.h" #include "../../bar.h" +#include "../../config.h" struct private { struct particle *label; @@ -198,8 +199,8 @@ run(struct module_run_context *ctx) return 0; } -struct module * -module_backlight(const char *device, struct particle *label) +static struct module * +backlight_new(const char *device, struct particle *label) { struct private *m = malloc(sizeof(*m)); m->label = label; @@ -214,3 +215,24 @@ module_backlight(const char *device, 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 *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}, + }, +}; diff --git a/modules/backlight/backlight.h b/modules/backlight/backlight.h index ab0b9b3..f390f2e 100644 --- a/modules/backlight/backlight.h +++ b/modules/backlight/backlight.h @@ -1,6 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_backlight(const char *device, struct particle *label); +extern const struct module_info module_backlight; From e24923e7cca33a9348164cbad5819f1cbb6775b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:02:41 +0100 Subject: [PATCH 09/31] module/battery: export module info through the new module_info struct type --- config-verify.c | 10 ++-------- config.c | 18 ++---------------- modules/battery/battery.c | 31 ++++++++++++++++++++++++++++--- modules/battery/battery.h | 5 +---- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/config-verify.c b/config-verify.c index 91df71b..a91fcdf 100644 --- a/config-verify.c +++ b/config-verify.c @@ -10,6 +10,7 @@ #include "modules/alsa/alsa.h" #include "modules/backlight/backlight.h" +#include "modules/battery/battery.h" static const char * err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -461,13 +462,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info battery[] = { - {"name", true, &conf_verify_string}, - {"poll-interval", false, &conf_verify_int}, - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info clock[] = { {"date-format", false, &conf_verify_string}, {"time-format", false, &conf_verify_string}, @@ -526,6 +520,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) } modules_v2[] = { {"alsa", &module_alsa}, {"backlight", &module_backlight}, + {"battery", &module_battery}, }; static const struct { @@ -533,7 +528,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"battery", battery, sizeof(battery) / sizeof(battery[0])}, {"clock", clock, sizeof(clock) / sizeof(clock[0])}, {"i3", i3, sizeof(i3) / sizeof(i3[0])}, {"label", label, sizeof(label) / sizeof(label[0])}, diff --git a/config.c b/config.c index 8169dc5..775d139 100644 --- a/config.c +++ b/config.c @@ -416,20 +416,6 @@ module_i3_from_config(const struct yml_node *node, const struct font *parent_fon return module_i3(workspaces, yml_dict_length(c), left, right); } -static struct module * -module_battery_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 *name = yml_get_value(node, "name"); - const struct yml_node *poll_interval = yml_get_value(node, "poll_interval"); - - return module_battery( - yml_value_as_string(name), - conf_to_particle(c, parent_font), - poll_interval != NULL ? yml_value_as_int(poll_interval) : 60); -} - static struct module * module_xkb_from_config(const struct yml_node *node, const struct font *parent_font) @@ -575,6 +561,8 @@ conf_to_bar(const struct yml_node *bar) 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, "battery") == 0) + mods[idx] = module_battery.from_conf(m.value, font); else if (strcmp(mod_name, "label") == 0) mods[idx] = module_label_from_config(m.value, font); @@ -584,8 +572,6 @@ conf_to_bar(const struct yml_node *bar) mods[idx] = module_xwindow_from_config(m.value, font); else if (strcmp(mod_name, "i3") == 0) mods[idx] = module_i3_from_config(m.value, font); - else if (strcmp(mod_name, "battery") == 0) - mods[idx] = module_battery_from_config(m.value, font); else if (strcmp(mod_name, "xkb") == 0) mods[idx] = module_xkb_from_config(m.value, font); else if (strcmp(mod_name, "mpd") == 0) diff --git a/modules/battery/battery.c b/modules/battery/battery.c index 2c3ba4f..e4442a1 100644 --- a/modules/battery/battery.c +++ b/modules/battery/battery.c @@ -16,6 +16,7 @@ #define LOG_MODULE "battery" #include "../../log.h" #include "../../bar.h" +#include "../../config.h" enum state { STATE_FULL, STATE_CHARGING, STATE_DISCHARGING }; @@ -326,9 +327,8 @@ out: return ret; } -struct module * -module_battery(const char *battery, struct particle *label, - int poll_interval_secs) +static struct module * +battery_new(const char *battery, struct particle *label, int poll_interval_secs) { struct private *m = malloc(sizeof(*m)); m->label = label; @@ -344,3 +344,28 @@ module_battery(const char *battery, 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 *name = yml_get_value(node, "name"); + const struct yml_node *poll_interval = yml_get_value(node, "poll_interval"); + + return battery_new( + yml_value_as_string(name), + conf_to_particle(c, parent_font), + poll_interval != NULL ? yml_value_as_int(poll_interval) : 60); +} + +const struct module_info module_battery = { + .from_conf = &from_conf, + .attr_count = 4, + .attrs = { + {"name", true, &conf_verify_string}, + {"poll-interval", false, &conf_verify_int}, + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/battery/battery.h b/modules/battery/battery.h index e025f3a..e8d89be 100644 --- a/modules/battery/battery.h +++ b/modules/battery/battery.h @@ -1,7 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_battery( - const char *battery, struct particle *label, int poll_interval_secs); +extern const struct module_info module_battery; From 550d4ad5345c8038ed69fa1eae5a6ffec6af1e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:05:39 +0100 Subject: [PATCH 10/31] module/clock: export module info through the new module_info struct type --- config-verify.c | 10 ++-------- config.c | 17 ++--------------- modules/clock/clock.c | 31 ++++++++++++++++++++++++++++--- modules/clock/clock.h | 5 +---- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/config-verify.c b/config-verify.c index a91fcdf..d1223fb 100644 --- a/config-verify.c +++ b/config-verify.c @@ -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])}, diff --git a/config.c b/config.c index 775d139..57a6931 100644 --- a/config.c +++ b/config.c @@ -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) diff --git a/modules/clock/clock.c b/modules/clock/clock.c index 8b8e692..1bd3c36 100644 --- a/modules/clock/clock.c +++ b/modules/clock/clock.c @@ -7,6 +7,7 @@ #include #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}, + }, +}; diff --git a/modules/clock/clock.h b/modules/clock/clock.h index 06c02f4..990ff64 100644 --- a/modules/clock/clock.h +++ b/modules/clock/clock.h @@ -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; From d2af5b2c84b5a165d23e2c86e78b70011899e59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:11:59 +0100 Subject: [PATCH 11/31] config: verify: break out err_prefix(), and rename --- config-verify.c | 53 ++++++++++++++++++++++++------------------------- config-verify.h | 4 ++++ 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/config-verify.c b/config-verify.c index d1223fb..5ed353f 100644 --- a/config-verify.c +++ b/config-verify.c @@ -13,8 +13,8 @@ #include "modules/battery/battery.h" #include "modules/clock/clock.h" -static const char * -err_prefix(const keychain_t *chain, const struct yml_node *node) +const char * +conf_err_prefix(const keychain_t *chain, const struct yml_node *node) { static char msg[4096]; int idx = 0; @@ -35,7 +35,7 @@ conf_verify_string(keychain_t *chain, const struct yml_node *node) { const char *s = yml_value_as_string(node); if (s == NULL) { - LOG_ERR("%s: value must be a string", err_prefix(chain, node)); + LOG_ERR("%s: value must be a string", conf_err_prefix(chain, node)); return false; } @@ -49,7 +49,7 @@ conf_verify_int(keychain_t *chain, const struct yml_node *node) return true; LOG_ERR("%s: value is not an integer: '%s'", - err_prefix(chain, node), yml_value_as_string(node)); + conf_err_prefix(chain, node), yml_value_as_string(node)); return false; } @@ -59,7 +59,7 @@ conf_verify_enum(keychain_t *chain, const struct yml_node *node, { const char *s = yml_value_as_string(node); if (s == NULL) { - LOG_ERR("%s: value must be a string", err_prefix(chain, node)); + LOG_ERR("%s: value must be a string", conf_err_prefix(chain, node)); return false; } @@ -68,7 +68,7 @@ conf_verify_enum(keychain_t *chain, const struct yml_node *node, return true; } - LOG_ERR("%s: value must be one of:", err_prefix(chain, node)); + LOG_ERR("%s: value must be one of:", conf_err_prefix(chain, node)); for (size_t i = 0; i < count; i++) LOG_ERR(" %s", values[i]); @@ -80,7 +80,7 @@ conf_verify_dict(keychain_t *chain, const struct yml_node *node, const struct attr_info info[], size_t count) { if (!yml_is_dict(node)) { - LOG_ERR("%s: must be a dictionary", err_prefix(chain, node)); + LOG_ERR("%s: must be a dictionary", conf_err_prefix(chain, node)); return false; } @@ -93,7 +93,7 @@ conf_verify_dict(keychain_t *chain, const struct yml_node *node, { const char *key = yml_value_as_string(it.key); if (key == NULL) { - LOG_ERR("%s: key must be a string", err_prefix(chain, it.key)); + LOG_ERR("%s: key must be a string", conf_err_prefix(chain, it.key)); return false; } @@ -107,7 +107,7 @@ conf_verify_dict(keychain_t *chain, const struct yml_node *node, } if (attr == NULL) { - LOG_ERR("%s: invalid key: %s", err_prefix(chain, it.key), key); + LOG_ERR("%s: invalid key: %s", conf_err_prefix(chain, it.key), key); return false; } @@ -123,7 +123,7 @@ conf_verify_dict(keychain_t *chain, const struct yml_node *node, if (!info[i].required || exists[i]) continue; - LOG_ERR("%s: missing required key: %s", err_prefix(chain, node), info[i].name); + LOG_ERR("%s: missing required key: %s", conf_err_prefix(chain, node), info[i].name); return false; } @@ -135,7 +135,7 @@ conf_verify_color(keychain_t *chain, const struct yml_node *node) { const char *s = yml_value_as_string(node); if (s == NULL) { - LOG_ERR("%s: value must be a string", err_prefix(chain, node)); + LOG_ERR("%s: value must be a string", conf_err_prefix(chain, node)); return false; } @@ -144,7 +144,7 @@ conf_verify_color(keychain_t *chain, const struct yml_node *node) if (strlen(s) != 8 || v != 4) { LOG_ERR("%s: value must be a color ('rrggbbaa', e.g ff00ffff)", - err_prefix(chain, node)); + conf_err_prefix(chain, node)); return false; } @@ -168,7 +168,7 @@ static bool verify_decoration_stack(keychain_t *chain, const struct yml_node *node) { if (!yml_is_list(node)) { - LOG_ERR("%s: must be a list of decorations", err_prefix(chain, node)); + LOG_ERR("%s: must be a list of decorations", conf_err_prefix(chain, node)); return false; } @@ -190,7 +190,7 @@ verify_decoration(keychain_t *chain, const struct yml_node *node) if (yml_dict_length(node) != 1) { LOG_ERR("%s: decoration must be a dictionary with a single key; " - "the name of the particle", err_prefix(chain, node)); + "the name of the particle", conf_err_prefix(chain, node)); return false; } @@ -200,7 +200,7 @@ verify_decoration(keychain_t *chain, const struct yml_node *node) const char *deco_name = yml_value_as_string(deco); if (deco_name == NULL) { - LOG_ERR("%s: decoration name must be a string", err_prefix(chain, deco)); + LOG_ERR("%s: decoration name must be a string", conf_err_prefix(chain, deco)); return false; } @@ -243,7 +243,7 @@ verify_decoration(keychain_t *chain, const struct yml_node *node) } LOG_ERR( - "%s: invalid decoration name: %s", err_prefix(chain, deco), deco_name); + "%s: invalid decoration name: %s", conf_err_prefix(chain, deco), deco_name); return false; } @@ -269,7 +269,7 @@ verify_map_values(keychain_t *chain, const struct yml_node *node) if (!yml_is_dict(node)) { LOG_ERR( "%s: must be a dictionary of workspace-name: particle mappings", - err_prefix(chain, node)); + conf_err_prefix(chain, node)); return false; } @@ -279,8 +279,7 @@ verify_map_values(keychain_t *chain, const struct yml_node *node) { const char *key = yml_value_as_string(it.key); if (key == NULL) { - LOG_ERR("%s: key must be a string (a i3 workspace name)", - err_prefix(chain, it.key)); + LOG_ERR("%s: key must be a string", conf_err_prefix(chain, it.key)); return false; } @@ -300,7 +299,7 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) if (yml_dict_length(node) != 1) { LOG_ERR("%s: particle must be a dictionary with a single key; " - "the name of the particle", err_prefix(chain, node)); + "the name of the particle", conf_err_prefix(chain, node)); return false; } @@ -310,7 +309,7 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) const char *particle_name = yml_value_as_string(particle); if (particle_name == NULL) { - LOG_ERR("%s: particle name must be a string", err_prefix(chain, particle)); + LOG_ERR("%s: particle name must be a string", conf_err_prefix(chain, particle)); return false; } @@ -396,7 +395,7 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node) } LOG_ERR( - "%s: invalid particle name: %s", err_prefix(chain, particle), particle_name); + "%s: invalid particle name: %s", conf_err_prefix(chain, particle), particle_name); return false; } @@ -409,7 +408,7 @@ conf_verify_particle(keychain_t *chain, const struct yml_node *node) return verify_list_items(chain, node); else { LOG_ERR("%s: particle must be either a dictionary or a list", - err_prefix(chain, node)); + conf_err_prefix(chain, node)); return false; } } @@ -449,7 +448,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) { if (!yml_is_dict(node) || yml_dict_length(node) != 1) { LOG_ERR("%s: module must be a dictionary with a single key; " - "the name of the module", err_prefix(chain, node)); + "the name of the module", conf_err_prefix(chain, node)); return false; } @@ -459,7 +458,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) const char *mod_name = yml_value_as_string(module); if (mod_name == NULL) { - LOG_ERR("%s: module name must be a string", err_prefix(chain, module)); + LOG_ERR("%s: module name must be a string", conf_err_prefix(chain, module)); return false; } @@ -562,7 +561,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) return true; } - LOG_ERR("%s: invalid module name: %s", err_prefix(chain, module), mod_name); + LOG_ERR("%s: invalid module name: %s", conf_err_prefix(chain, module), mod_name); return false; } @@ -570,7 +569,7 @@ static bool verify_module_list(keychain_t *chain, const struct yml_node *node) { if (!yml_is_list(node)) { - LOG_ERR("%s: must be a list of modules", err_prefix(chain, node)); + LOG_ERR("%s: must be a list of modules", conf_err_prefix(chain, node)); return false; } diff --git a/config-verify.h b/config-verify.h index 91132c6..a6f4660 100644 --- a/config-verify.h +++ b/config-verify.h @@ -26,6 +26,10 @@ chain_pop(keychain_t *chain) tll_pop_back(*chain); } +const char *conf_err_prefix( + const keychain_t *chain, const struct yml_node *node); + + bool conf_verify_string(keychain_t *chain, const struct yml_node *node); bool conf_verify_int(keychain_t *chain, const struct yml_node *node); From f3721d9d80af82a38a651375e33548633d6f7dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:12:14 +0100 Subject: [PATCH 12/31] module/i3: export module info through the new module_info struct type --- config-verify.c | 40 ++---------------------- config.c | 35 +++------------------ modules/i3/i3.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++-- modules/i3/i3.h | 12 +------ 4 files changed, 87 insertions(+), 83 deletions(-) diff --git a/config-verify.c b/config-verify.c index 5ed353f..aa4bd11 100644 --- a/config-verify.c +++ b/config-verify.c @@ -12,6 +12,7 @@ #include "modules/backlight/backlight.h" #include "modules/battery/battery.h" #include "modules/clock/clock.h" +#include "modules/i3/i3.h" const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -413,35 +414,6 @@ conf_verify_particle(keychain_t *chain, const struct yml_node *node) } } -static bool -verify_i3_content(keychain_t *chain, const struct yml_node *node) -{ - if (!yml_is_dict(node)) { - LOG_ERR( - "%s: must be a dictionary of workspace-name: particle mappings", - err_prefix(chain, node)); - return false; - } - - for (struct yml_dict_iter it = yml_dict_iter(node); - it.key != NULL; - yml_dict_next(&it)) - { - const char *key = yml_value_as_string(it.key); - if (key == NULL) { - LOG_ERR("%s: key must be a string (a i3 workspace name)", - err_prefix(chain, it.key)); - return false; - } - - if (!conf_verify_particle(chain_push(chain, key), it.value)) - return false; - - chain_pop(chain); - } - - return true; -} static bool verify_module(keychain_t *chain, const struct yml_node *node) @@ -474,14 +446,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"anchors", false, NULL}, }; - static const struct attr_info i3[] = { - {"spacing", false, &conf_verify_int}, - {"left-spacing", false, &conf_verify_int}, - {"right-spacing", false, &conf_verify_int}, - {"content", true, &verify_i3_content}, - {"anchors", false, NULL}, - }; - static const struct attr_info network[] = { {"name", true, &conf_verify_string}, {"content", true, &conf_verify_particle}, @@ -515,6 +479,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"backlight", &module_backlight}, {"battery", &module_battery}, {"clock", &module_clock}, + {"i3", &module_i3}, }; static const struct { @@ -522,7 +487,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"i3", i3, sizeof(i3) / sizeof(i3[0])}, {"label", label, sizeof(label) / sizeof(label[0])}, {"mpd", mpd, sizeof(mpd) / sizeof(mpd[0])}, {"network", network, sizeof(network) / sizeof(network[0])}, diff --git a/config.c b/config.c index 57a6931..7559384 100644 --- a/config.c +++ b/config.c @@ -376,33 +376,6 @@ module_xwindow_from_config(const struct yml_node *node, const struct font *paren return module_xwindow(conf_to_particle(c, parent_font)); } -static struct module * -module_i3_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 *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; - - struct i3_workspaces workspaces[yml_dict_length(c)]; - - size_t idx = 0; - for (struct yml_dict_iter it = yml_dict_iter(c); - it.key != NULL; - yml_dict_next(&it), idx++) - { - workspaces[idx].name = yml_value_as_string(it.key); - workspaces[idx].content = conf_to_particle(it.value, parent_font); - } - - return module_i3(workspaces, yml_dict_length(c), left, right); -} - static struct module * module_xkb_from_config(const struct yml_node *node, const struct font *parent_font) @@ -552,14 +525,14 @@ conf_to_bar(const struct yml_node *bar) 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, "i3") == 0) + mods[idx] = module_i3.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, "xwindow") == 0) mods[idx] = module_xwindow_from_config(m.value, font); - else if (strcmp(mod_name, "i3") == 0) - mods[idx] = module_i3_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); diff --git a/modules/i3/i3.c b/modules/i3/i3.c index d55eb50..a7fd3de 100644 --- a/modules/i3/i3.c +++ b/modules/i3/i3.c @@ -21,6 +21,7 @@ #define LOG_ENABLE_DBG 0 #include "../../log.h" #include "../../bar.h" +#include "../../config.h" #include "../../particles/dynlist.h" @@ -611,9 +612,15 @@ content(struct module *mod) particles, particle_count, m->left_spacing, m->right_spacing); } -struct module * -module_i3(struct i3_workspaces workspaces[], size_t workspace_count, - int left_spacing, int right_spacing) +/* Maps workspace name to a content particle. */ +struct i3_workspaces { + const char *name; + struct particle *content; +}; + +static struct module * +i3_new(struct i3_workspaces workspaces[], size_t workspace_count, + int left_spacing, int right_spacing) { struct private *m = malloc(sizeof(*m)); @@ -638,3 +645,73 @@ module_i3(struct i3_workspaces workspaces[], size_t workspace_count, 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 *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; + + struct i3_workspaces workspaces[yml_dict_length(c)]; + + size_t idx = 0; + for (struct yml_dict_iter it = yml_dict_iter(c); + it.key != NULL; + yml_dict_next(&it), idx++) + { + workspaces[idx].name = yml_value_as_string(it.key); + workspaces[idx].content = conf_to_particle(it.value, parent_font); + } + + return i3_new(workspaces, yml_dict_length(c), left, right); +} + +static bool +verify_content(keychain_t *chain, const struct yml_node *node) +{ + if (!yml_is_dict(node)) { + LOG_ERR( + "%s: must be a dictionary of workspace-name: particle mappings", + conf_err_prefix(chain, node)); + return false; + } + + for (struct yml_dict_iter it = yml_dict_iter(node); + it.key != NULL; + yml_dict_next(&it)) + { + const char *key = yml_value_as_string(it.key); + if (key == NULL) { + LOG_ERR("%s: key must be a string (a i3 workspace name)", + conf_err_prefix(chain, it.key)); + return false; + } + + if (!conf_verify_particle(chain_push(chain, key), it.value)) + return false; + + chain_pop(chain); + } + + return true; +} + +const struct module_info module_i3 = { + .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, &verify_content}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/i3/i3.h b/modules/i3/i3.h index 33b323b..de1c0ae 100644 --- a/modules/i3/i3.h +++ b/modules/i3/i3.h @@ -1,14 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -/* Maps workspace name to a content particle. */ -struct i3_workspaces { - const char *name; - struct particle *content; -}; - -struct module *module_i3( - struct i3_workspaces workspaces[], size_t workspace_count, - int left_spacing, int right_spacing); +extern const struct module_info module_i3; From fb9f07dcadb00c61d7bed91cdabe3aa72036fad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:48:42 +0100 Subject: [PATCH 13/31] module/label: export module info through the new module_info struct type --- config-verify.c | 8 ++------ config.c | 11 ++--------- modules/label/label.c | 23 +++++++++++++++++++++-- modules/label/label.h | 4 +--- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/config-verify.c b/config-verify.c index aa4bd11..6504b19 100644 --- a/config-verify.c +++ b/config-verify.c @@ -13,6 +13,7 @@ #include "modules/battery/battery.h" #include "modules/clock/clock.h" #include "modules/i3/i3.h" +#include "modules/label/label.h" const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -434,11 +435,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info label[] = { - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info mpd[] = { {"host", true, &conf_verify_string}, {"port", false, &conf_verify_int}, @@ -480,6 +476,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"battery", &module_battery}, {"clock", &module_clock}, {"i3", &module_i3}, + {"label", &module_label}, }; static const struct { @@ -487,7 +484,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"label", label, sizeof(label) / sizeof(label[0])}, {"mpd", mpd, sizeof(mpd) / sizeof(mpd[0])}, {"network", network, sizeof(network) / sizeof(network[0])}, {"removables", removables, sizeof(removables) / sizeof(removables[0])}, diff --git a/config.c b/config.c index 7559384..b7907cb 100644 --- a/config.c +++ b/config.c @@ -362,13 +362,6 @@ conf_to_particle(const struct yml_node *node, const struct font *parent_font) return ret; } -static struct module * -module_label_from_config(const struct yml_node *node, const struct font *parent_font) -{ - const struct yml_node *c = yml_get_value(node, "content"); - return module_label(conf_to_particle(c, parent_font)); -} - static struct module * module_xwindow_from_config(const struct yml_node *node, const struct font *parent_font) { @@ -527,9 +520,9 @@ conf_to_bar(const struct yml_node *bar) mods[idx] = module_clock.from_conf(m.value, font); else if (strcmp(mod_name, "i3") == 0) mods[idx] = module_i3.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_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) diff --git a/modules/label/label.c b/modules/label/label.c index 750082f..0533fa5 100644 --- a/modules/label/label.c +++ b/modules/label/label.c @@ -5,6 +5,8 @@ #include +#include "../../config.h" + struct private { struct particle *label; }; @@ -32,8 +34,8 @@ run(struct module_run_context *ctx) return 0; } -struct module * -module_label(struct particle *label) +static struct module * +label_new(struct particle *label) { struct private *m = malloc(sizeof(*m)); m->label = label; @@ -45,3 +47,20 @@ module_label(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"); + return label_new(conf_to_particle(c, parent_font)); +} + +const struct module_info module_label = { + .from_conf = &from_conf, + .attr_count = 2, + .attrs = { + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/label/label.h b/modules/label/label.h index 07a875e..b181d2d 100644 --- a/modules/label/label.h +++ b/modules/label/label.h @@ -1,6 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_label(struct particle *label); +extern const struct module_info module_label; From a16e2f5a538f978a882d012aee24616e5336008e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:52:16 +0100 Subject: [PATCH 14/31] module/mpd: export module info through the new module_info struct type --- config-verify.c | 11 +++-------- config.c | 23 +++++------------------ modules/mpd/mpd.c | 30 ++++++++++++++++++++++++++++-- modules/mpd/mpd.h | 7 +------ 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/config-verify.c b/config-verify.c index 6504b19..2bbef2d 100644 --- a/config-verify.c +++ b/config-verify.c @@ -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])}, diff --git a/config.c b/config.c index b7907cb..888ea5d 100644 --- a/config.c +++ b/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) diff --git a/modules/mpd/mpd.c b/modules/mpd/mpd.c index 13b3889..f52b7c7 100644 --- a/modules/mpd/mpd.c +++ b/modules/mpd/mpd.c @@ -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}, + }, +}; diff --git a/modules/mpd/mpd.h b/modules/mpd/mpd.h index e1c5183..57959e1 100644 --- a/modules/mpd/mpd.h +++ b/modules/mpd/mpd.h @@ -1,9 +1,4 @@ #pragma once - -#include - #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; From 697e613b2e28d5a225d346a46935615640f792c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:56:54 +0100 Subject: [PATCH 15/31] module/network: export module info through the new module_info struct type --- config-verify.c | 9 ++------- config.c | 15 ++------------- modules/network/network.c | 28 +++++++++++++++++++++++++--- modules/network/network.h | 4 +--- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/config-verify.c b/config-verify.c index 2bbef2d..169914a 100644 --- a/config-verify.c +++ b/config-verify.c @@ -16,6 +16,7 @@ #include "modules/label/label.h" #include "modules/label/label.h" #include "modules/mpd/mpd.h" +#include "modules/network/network.h" const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -437,12 +438,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info network[] = { - {"name", true, &conf_verify_string}, - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info removables[] = { {"spacing", false, &conf_verify_int}, {"left-spacing", false, &conf_verify_int}, @@ -473,6 +468,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"i3", &module_i3}, {"label", &module_label}, {"mpd", &module_mpd}, + {"network", &module_network}, }; static const struct { @@ -480,7 +476,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"network", network, sizeof(network) / sizeof(network[0])}, {"removables", removables, sizeof(removables) / sizeof(removables[0])}, {"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])}, {"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])}, diff --git a/config.c b/config.c index 888ea5d..fb25202 100644 --- a/config.c +++ b/config.c @@ -377,17 +377,6 @@ module_xkb_from_config(const struct yml_node *node, return module_xkb(conf_to_particle(c, parent_font)); } -static struct module * -module_network_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 *content = yml_get_value(node, "content"); - - return module_network( - yml_value_as_string(name), conf_to_particle(content, parent_font)); -} - static struct module * module_removables_from_config(const struct yml_node *node, const struct font *parent_font) @@ -510,14 +499,14 @@ conf_to_bar(const struct yml_node *bar) 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, "network") == 0) + mods[idx] = module_network.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) mods[idx] = module_xkb_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) mods[idx] = module_removables_from_config(m.value, font); else diff --git a/modules/network/network.c b/modules/network/network.c index e7da46d..273b688 100644 --- a/modules/network/network.c +++ b/modules/network/network.c @@ -17,8 +17,9 @@ #define LOG_MODULE "network" #define LOG_ENABLE_DBG 0 #include "../../log.h" -#include "../../module.h" #include "../../bar.h" +#include "../../config.h" +#include "../../module.h" #include "../../tllist.h" struct af_addr { @@ -511,8 +512,8 @@ run(struct module_run_context *ctx) return 0; } -struct module * -module_network(const char *iface, struct particle *label) +static struct module * +network_new(const char *iface, struct particle *label) { struct private *priv = malloc(sizeof(*priv)); priv->iface = strdup(iface); @@ -533,3 +534,24 @@ module_network(const char *iface, 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 *name = yml_get_value(node, "name"); + const struct yml_node *content = yml_get_value(node, "content"); + + return network_new( + yml_value_as_string(name), conf_to_particle(content, parent_font)); +} + +const struct module_info module_network = { + .from_conf = &from_conf, + .attr_count = 3, + .attrs = { + {"name", true, &conf_verify_string}, + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/network/network.h b/modules/network/network.h index 6c3fee7..2c7aa57 100644 --- a/modules/network/network.h +++ b/modules/network/network.h @@ -1,6 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_network(const char *iface, struct particle *label); +extern const struct module_info module_network; From 87640339e1e136e9fd9e951a20109ad4209b5544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 12:59:21 +0100 Subject: [PATCH 16/31] module/removables: export module info through the new module_info struct type --- config-verify.c | 11 ++-------- config.c | 22 ++------------------ modules/removables/removables.c | 37 ++++++++++++++++++++++++++++++--- modules/removables/removables.h | 5 +---- 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/config-verify.c b/config-verify.c index 169914a..9a0409a 100644 --- a/config-verify.c +++ b/config-verify.c @@ -17,6 +17,7 @@ #include "modules/label/label.h" #include "modules/mpd/mpd.h" #include "modules/network/network.h" +#include "modules/removables/removables.h" const char * 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; } - 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[] = { {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, @@ -469,6 +462,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"label", &module_label}, {"mpd", &module_mpd}, {"network", &module_network}, + {"removables", &module_removables}, }; static const struct { @@ -476,7 +470,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"removables", removables, sizeof(removables) / sizeof(removables[0])}, {"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])}, {"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])}, }; diff --git a/config.c b/config.c index fb25202..1d340ba 100644 --- a/config.c +++ b/config.c @@ -377,24 +377,6 @@ module_xkb_from_config(const struct yml_node *node, 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 * 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); else if (strcmp(mod_name, "network") == 0) 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) mods[idx] = module_xwindow_from_config(m.value, font); else if (strcmp(mod_name, "xkb") == 0) 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 assert(false); } diff --git a/modules/removables/removables.c b/modules/removables/removables.c index eab132f..0b23d07 100644 --- a/modules/removables/removables.c +++ b/modules/removables/removables.c @@ -18,8 +18,9 @@ #define LOG_ENABLE_DBG 0 #include "../../log.h" #include "../../bar.h" -#include "../../tllist.h" +#include "../../config.h" #include "../../particles/dynlist.h" +#include "../../tllist.h" typedef tll(char *) mount_point_list_t; @@ -544,8 +545,8 @@ run(struct module_run_context *ctx) return 0; } -struct module * -module_removables(struct particle *label, int left_spacing, int right_spacing) +static struct module * +removables_new(struct particle *label, int left_spacing, int right_spacing) { struct private *priv = malloc(sizeof(*priv)); priv->label = label; @@ -560,3 +561,33 @@ module_removables(struct particle *label, int left_spacing, int right_spacing) mod->content = &content; 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}, + }, +}; diff --git a/modules/removables/removables.h b/modules/removables/removables.h index 9d780fc..d5e96aa 100644 --- a/modules/removables/removables.h +++ b/modules/removables/removables.h @@ -1,7 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_removables( - struct particle *label, int left_spacing, int right_spacing); +extern const struct module_info module_removables; From 905f289659be8b430160441b06bc3dcdb65217c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 13:01:24 +0100 Subject: [PATCH 17/31] module/xkb: export module info through the new module_info struct type --- config-verify.c | 8 ++------ config.c | 12 ++---------- modules/xkb/xkb.c | 22 ++++++++++++++++++++-- modules/xkb/xkb.h | 3 +-- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/config-verify.c b/config-verify.c index 9a0409a..e20f142 100644 --- a/config-verify.c +++ b/config-verify.c @@ -18,6 +18,7 @@ #include "modules/mpd/mpd.h" #include "modules/network/network.h" #include "modules/removables/removables.h" +#include "modules/xkb/xkb.h" const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -439,11 +440,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info xkb[] = { - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - static const struct attr_info xwindow[] = { {"content", true, &conf_verify_particle}, {"anchors", false, NULL}, @@ -463,6 +459,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"mpd", &module_mpd}, {"network", &module_network}, {"removables", &module_removables}, + {"xkb", &module_xkb}, }; static const struct { @@ -470,7 +467,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"xkb", xkb, sizeof(xkb) / sizeof(xkb[0])}, {"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])}, }; diff --git a/config.c b/config.c index 1d340ba..6be88df 100644 --- a/config.c +++ b/config.c @@ -369,14 +369,6 @@ module_xwindow_from_config(const struct yml_node *node, const struct font *paren return module_xwindow(conf_to_particle(c, parent_font)); } -static struct module * -module_xkb_from_config(const struct yml_node *node, - const struct font *parent_font) -{ - const struct yml_node *c = yml_get_value(node, "content"); - return module_xkb(conf_to_particle(c, parent_font)); -} - struct bar * conf_to_bar(const struct yml_node *bar) { @@ -485,12 +477,12 @@ conf_to_bar(const struct yml_node *bar) 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, "xkb") == 0) + mods[idx] = module_xkb.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) - mods[idx] = module_xkb_from_config(m.value, font); else assert(false); } diff --git a/modules/xkb/xkb.c b/modules/xkb/xkb.c index 48d1854..5410e43 100644 --- a/modules/xkb/xkb.c +++ b/modules/xkb/xkb.c @@ -13,6 +13,7 @@ #define LOG_MODULE "xkb" #include "../../log.h" #include "../../bar.h" +#include "../../config.h" #include "../../xcb.h" struct layout { @@ -436,8 +437,8 @@ run(struct module_run_context *ctx) return ret; } -struct module * -module_xkb(struct particle *label) +static struct module * +xkb_new(struct particle *label) { struct private *m = malloc(sizeof(*m)); m->label = label; @@ -452,3 +453,20 @@ module_xkb(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"); + return xkb_new(conf_to_particle(c, parent_font)); +} + +const struct module_info module_xkb = { + .from_conf = &from_conf, + .attr_count = 2, + .attrs = { + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/xkb/xkb.h b/modules/xkb/xkb.h index c23129b..d38743e 100644 --- a/modules/xkb/xkb.h +++ b/modules/xkb/xkb.h @@ -1,5 +1,4 @@ #pragma once #include "../../module.h" -#include "../../particle.h" -struct module *module_xkb(struct particle *label); +extern const struct module_info module_xkb; From 6f9e48698eedb0b9432ce8214144d42413c117a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 13:03:41 +0100 Subject: [PATCH 18/31] module/xwindow: export module info through the new module_info struct type --- config-verify.c | 8 ++------ config.c | 11 +---------- modules/xwindow/xwindow.c | 22 ++++++++++++++++++++-- modules/xwindow/xwindow.h | 4 +--- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/config-verify.c b/config-verify.c index e20f142..fa5adc4 100644 --- a/config-verify.c +++ b/config-verify.c @@ -19,6 +19,7 @@ #include "modules/network/network.h" #include "modules/removables/removables.h" #include "modules/xkb/xkb.h" +#include "modules/xwindow/xwindow.h" const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) @@ -440,11 +441,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - static const struct attr_info xwindow[] = { - {"content", true, &conf_verify_particle}, - {"anchors", false, NULL}, - }; - /* TODO: this will dlopened later */ static const struct { const char *name; @@ -460,6 +456,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"network", &module_network}, {"removables", &module_removables}, {"xkb", &module_xkb}, + {"xwindow", &module_xwindow}, }; static const struct { @@ -467,7 +464,6 @@ verify_module(keychain_t *chain, const struct yml_node *node) const struct attr_info *attrs; size_t count; } modules[] = { - {"xwindow", xwindow, sizeof(xwindow) / sizeof(xwindow[0])}, }; for (size_t i = 0; i < sizeof(modules_v2) / sizeof(modules_v2[0]); i++) { diff --git a/config.c b/config.c index 6be88df..734d17a 100644 --- a/config.c +++ b/config.c @@ -362,13 +362,6 @@ conf_to_particle(const struct yml_node *node, const struct font *parent_font) return ret; } -static struct module * -module_xwindow_from_config(const struct yml_node *node, const struct font *parent_font) -{ - const struct yml_node *c = yml_get_value(node, "content"); - return module_xwindow(conf_to_particle(c, parent_font)); -} - struct bar * conf_to_bar(const struct yml_node *bar) { @@ -479,10 +472,8 @@ conf_to_bar(const struct yml_node *bar) mods[idx] = module_removables.from_conf(m.value, font); else if (strcmp(mod_name, "xkb") == 0) mods[idx] = module_xkb.from_conf(m.value, font); - - else if (strcmp(mod_name, "xwindow") == 0) - mods[idx] = module_xwindow_from_config(m.value, font); + mods[idx] = module_xwindow.from_conf(m.value, font); else assert(false); } diff --git a/modules/xwindow/xwindow.c b/modules/xwindow/xwindow.c index 515c0a0..d118b1e 100644 --- a/modules/xwindow/xwindow.c +++ b/modules/xwindow/xwindow.c @@ -17,6 +17,7 @@ #define LOG_MODULE "xkb" #include "../../log.h" #include "../../bar.h" +#include "../../config.h" #include "../../xcb.h" struct private { @@ -301,8 +302,8 @@ destroy(struct module *mod) module_default_destroy(mod); } -struct module * -module_xwindow(struct particle *label) +static struct module * +xwindow_new(struct particle *label) { struct private *m = calloc(1, sizeof(*m)); m->label = label; @@ -314,3 +315,20 @@ module_xwindow(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"); + return xwindow_new(conf_to_particle(c, parent_font)); +} + +const struct module_info module_xwindow = { + .from_conf = &from_conf, + .attr_count = 2, + .attrs = { + {"content", true, &conf_verify_particle}, + {"anchors", false, NULL}, + {NULL, false, NULL}, + }, +}; diff --git a/modules/xwindow/xwindow.h b/modules/xwindow/xwindow.h index cba35f2..0f67953 100644 --- a/modules/xwindow/xwindow.h +++ b/modules/xwindow/xwindow.h @@ -1,6 +1,4 @@ #pragma once - #include "../../module.h" -#include "../../particle.h" -struct module *module_xwindow(struct particle *label); +extern const struct module_info module_xwindow; From 650e15209140b1fd4bc1aa15b3d1b69244b68a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 13:04:42 +0100 Subject: [PATCH 19/31] config: verify: no old-style modules left --- config-verify.c | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/config-verify.c b/config-verify.c index fa5adc4..267b757 100644 --- a/config-verify.c +++ b/config-verify.c @@ -445,7 +445,7 @@ verify_module(keychain_t *chain, const struct yml_node *node) static const struct { const char *name; const struct module_info *info; - } modules_v2[] = { + } modules[] = { {"alsa", &module_alsa}, {"backlight", &module_backlight}, {"battery", &module_battery}, @@ -459,35 +459,14 @@ verify_module(keychain_t *chain, const struct yml_node *node) {"xwindow", &module_xwindow}, }; - static const struct { - const char *name; - const struct attr_info *attrs; - size_t count; - } modules[] = { - }; - - 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; - if (!conf_verify_dict(chain_push(chain, mod_name), values, - modules[i].attrs, modules[i].count)) + if (!conf_verify_dict(chain_push(chain, mod_name), + values, + modules[i].info->attrs, + modules[i].info->attr_count)) { return false; } From 731ab848e14e7158703677f493c585676ff8d903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 13:56:02 +0100 Subject: [PATCH 20/31] config: fix: attributes always use dash, not underscore --- config.c | 18 +++++++++--------- modules/battery/battery.c | 2 +- modules/i3/i3.c | 4 ++-- modules/removables/removables.c | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/config.c b/config.c index 734d17a..3d65197 100644 --- a/config.c +++ b/config.c @@ -188,8 +188,8 @@ particle_list_from_config(const struct yml_node *node, const struct yml_node *items = yml_get_value(node, "items"); 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"); + 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 = spacing != NULL ? yml_value_as_int(spacing) : _left_spacing != NULL ? yml_value_as_int(_left_spacing) : 0; @@ -320,9 +320,9 @@ conf_to_particle(const struct yml_node *node, const struct font *parent_font) const char *type = yml_value_as_string(pair.key); const struct yml_node *margin = yml_get_value(pair.value, "margin"); - const struct yml_node *left_margin = yml_get_value(pair.value, "left_margin"); - const struct yml_node *right_margin = yml_get_value(pair.value, "right_margin"); - const struct yml_node *on_click = yml_get_value(pair.value, "on_click"); + const struct yml_node *left_margin = yml_get_value(pair.value, "left-margin"); + const struct yml_node *right_margin = yml_get_value(pair.value, "right-margin"); + const struct yml_node *on_click = yml_get_value(pair.value, "on-click"); int left = margin != NULL ? yml_value_as_int(margin) : left_margin != NULL ? yml_value_as_int(left_margin) : 0; @@ -392,11 +392,11 @@ conf_to_bar(const struct yml_node *bar) if (spacing != NULL) conf.left_spacing = conf.right_spacing = yml_value_as_int(spacing); - const struct yml_node *left_spacing = yml_get_value(bar, "left_spacing"); + const struct yml_node *left_spacing = yml_get_value(bar, "left-spacing"); if (left_spacing != NULL) conf.left_spacing = yml_value_as_int(left_spacing); - const struct yml_node *right_spacing = yml_get_value(bar, "right_spacing"); + const struct yml_node *right_spacing = yml_get_value(bar, "right-spacing"); if (right_spacing != NULL) conf.right_spacing = yml_value_as_int(right_spacing); @@ -404,11 +404,11 @@ conf_to_bar(const struct yml_node *bar) if (margin != NULL) conf.left_margin = conf.right_margin = yml_value_as_int(margin); - const struct yml_node *left_margin = yml_get_value(bar, "left_margin"); + const struct yml_node *left_margin = yml_get_value(bar, "left-margin"); if (left_margin != NULL) conf.left_margin = yml_value_as_int(left_margin); - const struct yml_node *right_margin = yml_get_value(bar, "right_margin"); + const struct yml_node *right_margin = yml_get_value(bar, "right-margin"); if (right_margin != NULL) conf.right_margin = yml_value_as_int(right_margin); diff --git a/modules/battery/battery.c b/modules/battery/battery.c index e4442a1..98981c7 100644 --- a/modules/battery/battery.c +++ b/modules/battery/battery.c @@ -350,7 +350,7 @@ 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 *name = yml_get_value(node, "name"); - const struct yml_node *poll_interval = yml_get_value(node, "poll_interval"); + const struct yml_node *poll_interval = yml_get_value(node, "poll-interval"); return battery_new( yml_value_as_string(name), diff --git a/modules/i3/i3.c b/modules/i3/i3.c index a7fd3de..a805c79 100644 --- a/modules/i3/i3.c +++ b/modules/i3/i3.c @@ -651,8 +651,8 @@ 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 *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"); + 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; diff --git a/modules/removables/removables.c b/modules/removables/removables.c index 0b23d07..92e3155 100644 --- a/modules/removables/removables.c +++ b/modules/removables/removables.c @@ -567,8 +567,8 @@ 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"); + 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; From 64b77a0efc0cdb769042d5111698d16a777b1c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 19:03:49 +0100 Subject: [PATCH 21/31] config: dlopen() modules on-demand TODO: optimizations and proper cleanup * We currently reload the shared library for each *instance* of the module, and we do it twice; once when verifying, and once when instantiating. * The shared libraries are never dlclosed() --- CMakeLists.txt | 48 +++++----------- config-verify.c | 128 +++++++++++++++++++++++++++-------------- config.c | 53 ++++++----------- modules/CMakeLists.txt | 54 +++++++++++++++++ 4 files changed, 170 insertions(+), 113 deletions(-) create mode 100644 modules/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 140cb2a..17fc928 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.13) project(f00bar C) set(CMAKE_C_STANDARD_REQUIRED ON) @@ -19,11 +19,6 @@ pkg_check_modules(FONTCONFIG REQUIRED fontconfig) # Core pkg_check_modules(CAIRO REQUIRED cairo cairo-xcb cairo-ft) # Core pkg_check_modules(YAML REQUIRED yaml-0.1) # Core (configuration) -pkg_check_modules(XCB_XKB REQUIRED xcb-xkb) # Module/xkb -pkg_check_modules(JSON REQUIRED json-c) # Module/i3 -pkg_check_modules(UDEV REQUIRED libudev) # Module/battery -pkg_check_modules(MPD REQUIRED libmpdclient) # Module/mpd -pkg_check_modules(ALSA REQUIRED alsa) # Module/alsa add_executable(f00bar bar.c bar.h @@ -50,32 +45,19 @@ add_executable(f00bar particles/progress-bar.c particles/progress-bar.h particles/ramp.c particles/ramp.h particles/string.c particles/string.h - - modules/alsa/alsa.c modules/alsa/alsa.h - modules/backlight/backlight.c modules/backlight/backlight.h - modules/battery/battery.c modules/battery/battery.h - modules/clock/clock.c modules/clock/clock.h - modules/i3/i3.c modules/i3/i3.h - modules/label/label.c modules/label/label.h - modules/mpd/mpd.c modules/mpd/mpd.h - modules/network/network.c modules/network/network.h - modules/removables/removables.c modules/removables/removables.h - modules/xkb/xkb.c modules/xkb/xkb.h - modules/xwindow/xwindow.c modules/xwindow/xwindow.h ) +# TODO: directory global target_compile_definitions(f00bar PRIVATE _GNU_SOURCE) +# Make global symbols in f00bar visible to dlopen:ed plugins +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic") + target_compile_options(f00bar PRIVATE ${XCB_CFLAGS_OTHER} ${FONTCONFIG_CFLAGS_OTHER} ${CAIRO_CFLAGS_OTHER} ${YAML_CFLAGS_OTHER} - ${XCB_XKB_CFLAGS_OTHER} - ${JSON_CFLAGS_OTHER} - ${UDEV_CFLAGS_OTHER} - ${MPD_CFLAGS_OTHER} - ${ALSA_CFLAGS_OTHER} ) target_include_directories(f00bar PRIVATE @@ -83,22 +65,22 @@ target_include_directories(f00bar PRIVATE ${FONTCONFIG_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS} ${YAML_INCLUDE_DIRS} - ${XCB_XKB_INCLUDE_DIRS} - ${JSON_INCLUDE_DIRS} - ${UDEV_INCLUDE_DIRS} - ${MPD_INCLUDE_DIRS} - ${ALSA_INCLUDE_DIRS} ) target_link_libraries(f00bar ${CMAKE_THREAD_LIBS_INIT} + ${CMAKE_DL_LIBS} + ${XCB_LIBRARIES} ${FONTCONFIG_LIBRARIES} ${CAIRO_LIBRARIES} ${YAML_LIBRARIES} - ${XCB_XKB_LIBRARIES} - ${JSON_LIBRARIES} - ${UDEV_LIBRARIES} - ${MPD_LIBRARIES} - ${ALSA_LIBRARIES} ) + +add_library(module-sdk INTERFACE) +target_compile_definitions(module-sdk INTERFACE _GNU_SOURCE) +target_compile_options(module-sdk INTERFACE ${CAIRO_CFLAGS_OTHER}) +target_include_directories(module-sdk INTERFACE ${CAIRO_INCLUDE_DIRS}) +target_link_libraries(module-sdk INTERFACE ${CMAKE_THREAD_LIBS_INIT}) + +add_subdirectory(modules) diff --git a/config-verify.c b/config-verify.c index 267b757..9002ca1 100644 --- a/config-verify.c +++ b/config-verify.c @@ -3,24 +3,17 @@ #include #include +#include +#include +#include +#include +#include + #define LOG_MODULE "config:verify" #define LOG_ENABLE_DBG 0 #include "log.h" #include "tllist.h" -#include "modules/alsa/alsa.h" -#include "modules/backlight/backlight.h" -#include "modules/battery/battery.h" -#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" -#include "modules/network/network.h" -#include "modules/removables/removables.h" -#include "modules/xkb/xkb.h" -#include "modules/xwindow/xwindow.h" - const char * conf_err_prefix(const keychain_t *chain, const struct yml_node *node) { @@ -441,42 +434,46 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - /* TODO: this will dlopened later */ - static const struct { - const char *name; - const struct module_info *info; - } modules[] = { - {"alsa", &module_alsa}, - {"backlight", &module_backlight}, - {"battery", &module_battery}, - {"clock", &module_clock}, - {"i3", &module_i3}, - {"label", &module_label}, - {"mpd", &module_mpd}, - {"network", &module_network}, - {"removables", &module_removables}, - {"xkb", &module_xkb}, - {"xwindow", &module_xwindow}, - }; + char path[1024]; + snprintf(path, sizeof(path), "./modules/lib%s.so", mod_name); - for (size_t i = 0; i < sizeof(modules) / sizeof(modules[0]); i++) { - if (strcmp(modules[i].name, mod_name) != 0) - continue; + void *lib = dlopen(path, RTLD_LOCAL | RTLD_NOW | RTLD_NOLOAD); - if (!conf_verify_dict(chain_push(chain, mod_name), - values, - modules[i].info->attrs, - modules[i].info->attr_count)) - { - return false; - } + if (lib == NULL) + lib = dlopen(path, RTLD_LOCAL | RTLD_NOW); - chain_pop(chain); - return true; + if (lib == NULL) { + const char *dl_error = dlerror(); + if (dl_error != NULL) + LOG_ERR("%s: dlopen: %s", mod_name, dlerror()); + else + LOG_ERR("%s: invalid module name: %s", + conf_err_prefix(chain, module), mod_name); + + return false; } - LOG_ERR("%s: invalid module name: %s", conf_err_prefix(chain, module), mod_name); - return false; + char sym[1024]; + snprintf(sym, sizeof(sym), "module_%s", mod_name); + + dlerror(); /* Clear previous error */ + const struct module_info *info = dlsym(lib, sym); + + const char *dlsym_error = dlerror(); + if (dlsym_error != NULL) { + LOG_ERR("%s: dlsym: %s", mod_name, dlsym_error); + dlclose(lib); + return false; + } + + assert(info != NULL); + + if (!conf_verify_dict(chain_push(chain, mod_name), values, + info->attrs, info->attr_count)) + return false; + + chain_pop(chain); + return true; } static bool @@ -515,6 +512,45 @@ verify_bar_location(keychain_t *chain, const struct yml_node *node) return conf_verify_enum(chain, node, (const char *[]){"top", "bottom"}, 2); } +#if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG +static void +find_modules(void) +{ + int cwd = open(".", O_RDONLY); + assert(cwd != -1); + + int modules = openat(cwd, "modules", O_RDONLY); + assert(modules != -1); + + DIR *dir = fdopendir(modules); + assert(dir != NULL); + + for (struct dirent *e = readdir(dir); e != NULL; e = readdir(dir)) { + const size_t len = strlen(e->d_name); + + if (len <= 6) { + /* Need at least "libX.so" */ + continue; + } + + if (strncmp(e->d_name, "lib", 3) != 0) + continue; + + if (strcmp(&e->d_name[len - 3], ".so") != 0) + continue; + + char *name = malloc(len - 6 + 1); + memcpy(name, &e->d_name[3], len - 6); + name[len - 6] = '\0'; + + LOG_DBG("%s", name); + free(name); + } + + closedir(dir); +} +#endif + bool conf_verify_bar(const struct yml_node *bar) { @@ -523,6 +559,10 @@ conf_verify_bar(const struct yml_node *bar) return false; } +#if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG + find_modules(); +#endif + keychain_t chain = tll_init(); chain_push(&chain, "bar"); diff --git a/config.c b/config.c index 3d65197..a9ba245 100644 --- a/config.c +++ b/config.c @@ -5,6 +5,10 @@ #include #include + +#include + + #include "color.h" #include "decoration.h" @@ -21,18 +25,6 @@ #include "particles/string.h" #include "module.h" -#include "modules/alsa/alsa.h" -#include "modules/backlight/backlight.h" -#include "modules/battery/battery.h" -#include "modules/clock/clock.h" -#include "modules/i3/i3.h" -#include "modules/label/label.h" -#include "modules/mpd/mpd.h" -#include "modules/network/network.h" -#include "modules/removables/removables.h" -#include "modules/xkb/xkb.h" -#include "modules/xwindow/xwindow.h" - #include "config-verify.h" static uint8_t @@ -452,30 +444,19 @@ conf_to_bar(const struct yml_node *bar) struct yml_dict_iter m = yml_dict_iter(it.node); const char *mod_name = yml_value_as_string(m.key); - 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, "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, "i3") == 0) - 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, "network") == 0) - 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, "xkb") == 0) - mods[idx] = module_xkb.from_conf(m.value, font); - else if (strcmp(mod_name, "xwindow") == 0) - mods[idx] = module_xwindow.from_conf(m.value, font); - else - assert(false); + char path[1024]; + snprintf(path, sizeof(path), "./modules/lib%s.so", mod_name); + + void *lib = dlopen(path, RTLD_LOCAL | RTLD_NOW | RTLD_NOLOAD); + assert(lib != NULL); + + char sym[1024]; + snprintf(sym, sizeof(sym), "module_%s", mod_name); + + const struct module_info *info = dlsym(lib, sym); + assert(info != NULL); + + mods[idx] = info->from_conf(m.value, font); } if (i == 0) { diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt new file mode 100644 index 0000000..ffceaec --- /dev/null +++ b/modules/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 3.13) + +pkg_check_modules(ALSA REQUIRED alsa) +add_library(alsa MODULE alsa/alsa.c alsa/alsa.h) +target_compile_options(alsa PRIVATE ${ALSA_CFLAGS_OTHER}) +target_include_directories(alsa PRIVATE ${ALSA_INCLUDE_DIRS}) +target_link_libraries(alsa module-sdk ${ALSA_LIBRARIES}) + +pkg_check_modules(UDEV REQUIRED libudev) +add_library(backlight MODULE backlight/backlight.c backlight/backlight.h) +target_compile_options(backlight PRIVATE ${UDEV_CFLAGS_OTHER}) +target_include_directories(backlight PRIVATE ${UDEV_INCLUDE_DIRS}) +target_link_libraries(backlight module-sdk ${UDEV_LIBRARIES}) + +add_library(battery MODULE battery/battery.c battery/battery.h) +target_compile_options(battery PRIVATE ${UDEV_CFLAGS_OTHER}) +target_include_directories(battery PRIVATE ${UDEV_INCLUDE_DIRS}) +target_link_libraries(battery module-sdk ${UDEV_LIBRARIES}) + +add_library(clock MODULE clock/clock.c clock/clock.h) +target_link_libraries(clock module-sdk) + +pkg_check_modules(JSON REQUIRED json-c) +add_library(i3 MODULE i3/i3.c i3/i3.h) +target_compile_options(i3 PRIVATE ${JSON_CFLAGS_OTHER}) +target_include_directories(i3 PRIVATE ${JSON_INCLUDE_DIRS}) +target_link_libraries(i3 module-sdk ${JSON_LIBRARIES}) + + +add_library(label MODULE label/label.c label/label.h) +target_link_libraries(label module-sdk) + +pkg_check_modules(MPD REQUIRED libmpdclient) +add_library(mpd MODULE mpd/mpd.c mpd/mpd.h) +target_compile_options(mpd PRIVATE ${MPD_CFLAGS_OTHER}) +target_include_directories(mpd PRIVATE ${MPD_INCLUDE_DIRS}) +target_link_libraries(mpd module-sdk ${MPD_LIBRARIES}) + +add_library(network MODULE network/network.c network/network.h) +target_link_libraries(network module-sdk) + +add_library(removables MODULE removables/removables.c removables/removables.h) +target_compile_options(removables PRIVATE ${UDEV_CFLAGS_OTHER}) +target_include_directories(removables PRIVATE ${UDEV_INCLUDE_DIRS}) +target_link_libraries(removables module-sdk ${UDEV_LIBRARIES}) + +pkg_check_modules(XCB_XKB REQUIRED xcb-xkb) +add_library(xkb MODULE xkb/xkb.c xkb/xkb.h) +target_compile_options(xkb PRIVATE ${XCB_XKB_CFLAGS_OTHER}) +target_include_directories(xkb PRIVATE ${XCB_XKB_INCLUDE_DIRS}) +target_link_libraries(xkb module-sdk ${XCB_XKB_LIBRARIES}) + +add_library(xwindow MODULE xwindow/xwindow.c xwindow/xwindow.h) +target_link_libraries(xwindow module-sdk) From 962252467fde53594a2c2df1a21708c75c6741a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 19:38:06 +0100 Subject: [PATCH 22/31] plugins: only dlopen() each plugin once. dlcose() in destructor --- CMakeLists.txt | 1 + config-verify.c | 85 +++---------------------------------------------- config.c | 18 ++--------- plugin.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ plugin.h | 5 +++ 5 files changed, 95 insertions(+), 96 deletions(-) create mode 100644 plugin.c create mode 100644 plugin.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 17fc928..4f07ee9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ add_executable(f00bar main.c module.c module.h particle.c particle.h + plugin.c plugin.h tag.c tag.h xcb.c xcb.h yml.c yml.h diff --git a/config-verify.c b/config-verify.c index 9002ca1..6597b39 100644 --- a/config-verify.c +++ b/config-verify.c @@ -3,15 +3,10 @@ #include #include -#include -#include -#include -#include -#include - #define LOG_MODULE "config:verify" #define LOG_ENABLE_DBG 0 #include "log.h" +#include "plugin.h" #include "tllist.h" const char * @@ -434,40 +429,13 @@ verify_module(keychain_t *chain, const struct yml_node *node) return false; } - char path[1024]; - snprintf(path, sizeof(path), "./modules/lib%s.so", mod_name); - - void *lib = dlopen(path, RTLD_LOCAL | RTLD_NOW | RTLD_NOLOAD); - - if (lib == NULL) - lib = dlopen(path, RTLD_LOCAL | RTLD_NOW); - - if (lib == NULL) { - const char *dl_error = dlerror(); - if (dl_error != NULL) - LOG_ERR("%s: dlopen: %s", mod_name, dlerror()); - else - LOG_ERR("%s: invalid module name: %s", - conf_err_prefix(chain, module), mod_name); - + const struct module_info *info = plugin_load_module(mod_name); + if (info == NULL) { + LOG_ERR( + "%s: invalid module name: %s", conf_err_prefix(chain, node), mod_name); return false; } - char sym[1024]; - snprintf(sym, sizeof(sym), "module_%s", mod_name); - - dlerror(); /* Clear previous error */ - const struct module_info *info = dlsym(lib, sym); - - const char *dlsym_error = dlerror(); - if (dlsym_error != NULL) { - LOG_ERR("%s: dlsym: %s", mod_name, dlsym_error); - dlclose(lib); - return false; - } - - assert(info != NULL); - if (!conf_verify_dict(chain_push(chain, mod_name), values, info->attrs, info->attr_count)) return false; @@ -512,45 +480,6 @@ verify_bar_location(keychain_t *chain, const struct yml_node *node) return conf_verify_enum(chain, node, (const char *[]){"top", "bottom"}, 2); } -#if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG -static void -find_modules(void) -{ - int cwd = open(".", O_RDONLY); - assert(cwd != -1); - - int modules = openat(cwd, "modules", O_RDONLY); - assert(modules != -1); - - DIR *dir = fdopendir(modules); - assert(dir != NULL); - - for (struct dirent *e = readdir(dir); e != NULL; e = readdir(dir)) { - const size_t len = strlen(e->d_name); - - if (len <= 6) { - /* Need at least "libX.so" */ - continue; - } - - if (strncmp(e->d_name, "lib", 3) != 0) - continue; - - if (strcmp(&e->d_name[len - 3], ".so") != 0) - continue; - - char *name = malloc(len - 6 + 1); - memcpy(name, &e->d_name[3], len - 6); - name[len - 6] = '\0'; - - LOG_DBG("%s", name); - free(name); - } - - closedir(dir); -} -#endif - bool conf_verify_bar(const struct yml_node *bar) { @@ -559,10 +488,6 @@ conf_verify_bar(const struct yml_node *bar) return false; } -#if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG - find_modules(); -#endif - keychain_t chain = tll_init(); chain_push(&chain, "bar"); diff --git a/config.c b/config.c index a9ba245..e18660c 100644 --- a/config.c +++ b/config.c @@ -5,10 +5,6 @@ #include #include - -#include - - #include "color.h" #include "decoration.h" @@ -26,6 +22,7 @@ #include "module.h" #include "config-verify.h" +#include "plugin.h" static uint8_t hex_nibble(char hex) @@ -444,18 +441,7 @@ conf_to_bar(const struct yml_node *bar) struct yml_dict_iter m = yml_dict_iter(it.node); const char *mod_name = yml_value_as_string(m.key); - char path[1024]; - snprintf(path, sizeof(path), "./modules/lib%s.so", mod_name); - - void *lib = dlopen(path, RTLD_LOCAL | RTLD_NOW | RTLD_NOLOAD); - assert(lib != NULL); - - char sym[1024]; - snprintf(sym, sizeof(sym), "module_%s", mod_name); - - const struct module_info *info = dlsym(lib, sym); - assert(info != NULL); - + const struct module_info *info = plugin_load_module(mod_name); mods[idx] = info->from_conf(m.value, font); } diff --git a/plugin.c b/plugin.c new file mode 100644 index 0000000..439ec91 --- /dev/null +++ b/plugin.c @@ -0,0 +1,82 @@ +#include "plugin.h" + +#include +#include + +#define LOG_MODULE "plugin" +#define LOG_ENABLE_DBG 0 +#include "log.h" +#include "config.h" +#include "tllist.h" + +struct plugin { + char *name; + void *lib; +}; + +static tll(struct plugin) libs = tll_init(); + +static void __attribute__((destructor)) +fini(void) +{ + tll_foreach(libs, plug) { + dlerror(); + dlclose(plug->item.lib); + + const char *dl_error = dlerror(); + if (dl_error != NULL) + LOG_ERR("%s: dlclose(): %s", plug->item.name, dl_error); + + free(plug->item.name); + } + + tll_free(libs); +} + +const struct module_info * +plugin_load_module(const char *name) +{ + char path[128]; + snprintf(path, sizeof(path), "./modules/lib%s.so", name); + + void *lib = NULL; + + /* Have we already loaded it? */ + tll_foreach(libs, plug) { + if (strcmp(plug->item.name, name) == 0) { + lib = plug->item.lib; + LOG_DBG("%s already loaded: %p", name, lib); + break; + } + } + + if (lib == NULL) { + /* Not loaded - do it now */ + lib = dlopen(path, RTLD_LOCAL | RTLD_NOW); + LOG_DBG("%s: dlopened to %p", name, lib); + + if (lib == NULL) { + LOG_ERR("%s: dlopen: %s", name, dlerror()); + return NULL; + } + + tll_push_back(libs, ((struct plugin){strdup(name), lib})); + } + + /* TODO: use same name in all modules */ + char sym[128]; + snprintf(sym, sizeof(sym), "module_%s", name); + + /* TODO: cache symbol */ + dlerror(); /* Clear previous error */ + const struct module_info *info = dlsym(lib, sym); + + const char *dlsym_error = dlerror(); + if (dlsym_error != NULL) { + LOG_ERR("%s: dlsym: %s", name, dlsym_error); + return NULL; + } + + assert(info != NULL); + return info; +} diff --git a/plugin.h b/plugin.h new file mode 100644 index 0000000..6d829e2 --- /dev/null +++ b/plugin.h @@ -0,0 +1,5 @@ +#pragma once + +#include "module.h" + +const struct module_info *plugin_load_module(const char *name); From 45eb2b85f0e466331cb57ee5d126ccd953c578ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 19:44:24 +0100 Subject: [PATCH 23/31] plugin: cache module_info symbol as well --- plugin.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/plugin.c b/plugin.c index 439ec91..9b9e58c 100644 --- a/plugin.c +++ b/plugin.c @@ -12,6 +12,7 @@ struct plugin { char *name; void *lib; + const void *sym; }; static tll(struct plugin) libs = tll_init(); @@ -39,37 +40,33 @@ plugin_load_module(const char *name) char path[128]; snprintf(path, sizeof(path), "./modules/lib%s.so", name); - void *lib = NULL; - /* Have we already loaded it? */ tll_foreach(libs, plug) { if (strcmp(plug->item.name, name) == 0) { - lib = plug->item.lib; - LOG_DBG("%s already loaded: %p", name, lib); - break; + LOG_DBG("%s already loaded: %p", name, plug->item.lib); + assert(plug->item.sym != NULL); + return plug->item.sym; } } + /* Not loaded - do it now */ + void *lib = dlopen(path, RTLD_LOCAL | RTLD_NOW); + LOG_DBG("%s: dlopened to %p", name, lib); + if (lib == NULL) { - /* Not loaded - do it now */ - lib = dlopen(path, RTLD_LOCAL | RTLD_NOW); - LOG_DBG("%s: dlopened to %p", name, lib); - - if (lib == NULL) { - LOG_ERR("%s: dlopen: %s", name, dlerror()); - return NULL; - } - - tll_push_back(libs, ((struct plugin){strdup(name), lib})); + LOG_ERR("%s: dlopen: %s", name, dlerror()); + return NULL; } + tll_push_back(libs, ((struct plugin){strdup(name), lib})); + struct plugin *plug = &tll_back(libs); + /* TODO: use same name in all modules */ char sym[128]; snprintf(sym, sizeof(sym), "module_%s", name); - /* TODO: cache symbol */ dlerror(); /* Clear previous error */ - const struct module_info *info = dlsym(lib, sym); + plug->sym = dlsym(lib, sym); const char *dlsym_error = dlerror(); if (dlsym_error != NULL) { @@ -77,6 +74,6 @@ plugin_load_module(const char *name) return NULL; } - assert(info != NULL); - return info; + assert(plug->sym != NULL); + return plug->sym; } From 7f2501334d5fba1908c2d8bd46bafd0f5a7fc570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 20:34:43 +0100 Subject: [PATCH 24/31] modules: use the same name for the module_info in all modules --- modules/alsa/alsa.c | 2 +- modules/backlight/backlight.c | 2 +- modules/battery/battery.c | 2 +- modules/clock/clock.c | 2 +- modules/i3/i3.c | 2 +- modules/label/label.c | 2 +- modules/mpd/mpd.c | 2 +- modules/network/network.c | 2 +- modules/removables/removables.c | 2 +- modules/xkb/xkb.c | 2 +- modules/xwindow/xwindow.c | 2 +- plugin.c | 6 +----- 12 files changed, 12 insertions(+), 16 deletions(-) diff --git a/modules/alsa/alsa.c b/modules/alsa/alsa.c index 5a34346..856d7fe 100644 --- a/modules/alsa/alsa.c +++ b/modules/alsa/alsa.c @@ -282,7 +282,7 @@ from_conf(const struct yml_node *node, const struct font *parent_font) conf_to_particle(content, parent_font)); } -const struct module_info module_alsa = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 4, .attrs = { diff --git a/modules/backlight/backlight.c b/modules/backlight/backlight.c index 1ba2334..f8f9975 100644 --- a/modules/backlight/backlight.c +++ b/modules/backlight/backlight.c @@ -226,7 +226,7 @@ from_conf(const struct yml_node *node, const struct font *parent_font) yml_value_as_string(name), conf_to_particle(c, parent_font)); } -const struct module_info module_backlight = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 3, .attrs = { diff --git a/modules/battery/battery.c b/modules/battery/battery.c index 98981c7..69bb4ea 100644 --- a/modules/battery/battery.c +++ b/modules/battery/battery.c @@ -358,7 +358,7 @@ from_conf(const struct yml_node *node, const struct font *parent_font) poll_interval != NULL ? yml_value_as_int(poll_interval) : 60); } -const struct module_info module_battery = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 4, .attrs = { diff --git a/modules/clock/clock.c b/modules/clock/clock.c index 1bd3c36..74c1664 100644 --- a/modules/clock/clock.c +++ b/modules/clock/clock.c @@ -108,7 +108,7 @@ from_conf(const struct yml_node *node, const struct font *parent_font) time_format != NULL ? yml_value_as_string(time_format) : "%H:%M"); } -const struct module_info module_clock = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 4, .attrs = { diff --git a/modules/i3/i3.c b/modules/i3/i3.c index a805c79..f3f52c2 100644 --- a/modules/i3/i3.c +++ b/modules/i3/i3.c @@ -703,7 +703,7 @@ verify_content(keychain_t *chain, const struct yml_node *node) return true; } -const struct module_info module_i3 = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 5, .attrs = { diff --git a/modules/label/label.c b/modules/label/label.c index 0533fa5..3f97216 100644 --- a/modules/label/label.c +++ b/modules/label/label.c @@ -55,7 +55,7 @@ from_conf(const struct yml_node *node, const struct font *parent_font) return label_new(conf_to_particle(c, parent_font)); } -const struct module_info module_label = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 2, .attrs = { diff --git a/modules/mpd/mpd.c b/modules/mpd/mpd.c index f52b7c7..a17008d 100644 --- a/modules/mpd/mpd.c +++ b/modules/mpd/mpd.c @@ -493,7 +493,7 @@ from_conf(const struct yml_node *node, const struct font *parent_font) conf_to_particle(c, parent_font)); } -const struct module_info module_mpd = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 4, .attrs = { diff --git a/modules/network/network.c b/modules/network/network.c index 273b688..0444c70 100644 --- a/modules/network/network.c +++ b/modules/network/network.c @@ -545,7 +545,7 @@ from_conf(const struct yml_node *node, const struct font *parent_font) yml_value_as_string(name), conf_to_particle(content, parent_font)); } -const struct module_info module_network = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 3, .attrs = { diff --git a/modules/removables/removables.c b/modules/removables/removables.c index 92e3155..2b64707 100644 --- a/modules/removables/removables.c +++ b/modules/removables/removables.c @@ -579,7 +579,7 @@ from_conf(const struct yml_node *node, const struct font *parent_font) conf_to_particle(content, parent_font), left, right); } -const struct module_info module_removables = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 5, .attrs = { diff --git a/modules/xkb/xkb.c b/modules/xkb/xkb.c index 5410e43..b299a80 100644 --- a/modules/xkb/xkb.c +++ b/modules/xkb/xkb.c @@ -461,7 +461,7 @@ from_conf(const struct yml_node *node, const struct font *parent_font) return xkb_new(conf_to_particle(c, parent_font)); } -const struct module_info module_xkb = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 2, .attrs = { diff --git a/modules/xwindow/xwindow.c b/modules/xwindow/xwindow.c index d118b1e..4114e69 100644 --- a/modules/xwindow/xwindow.c +++ b/modules/xwindow/xwindow.c @@ -323,7 +323,7 @@ from_conf(const struct yml_node *node, const struct font *parent_font) return xwindow_new(conf_to_particle(c, parent_font)); } -const struct module_info module_xwindow = { +const struct module_info module_info = { .from_conf = &from_conf, .attr_count = 2, .attrs = { diff --git a/plugin.c b/plugin.c index 9b9e58c..8eb2781 100644 --- a/plugin.c +++ b/plugin.c @@ -61,12 +61,8 @@ plugin_load_module(const char *name) tll_push_back(libs, ((struct plugin){strdup(name), lib})); struct plugin *plug = &tll_back(libs); - /* TODO: use same name in all modules */ - char sym[128]; - snprintf(sym, sizeof(sym), "module_%s", name); - dlerror(); /* Clear previous error */ - plug->sym = dlsym(lib, sym); + plug->sym = dlsym(lib, "module_info"); const char *dlsym_error = dlerror(); if (dlsym_error != NULL) { From f7fd3058216c583a15bf6df1dd703db06eb65801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 21:07:48 +0100 Subject: [PATCH 25/31] build: install targets for f00bar binary + module plugins Module plugins are (still) built in /modules. When installing, f00bar binary is installed to /bin, and the module plugins to /lib/f00bar. For this to work, we now also set RPATH correctly. Since the installed module plugins end up in a different location then when building, different settings is required for BUILD_RPATH and INSTALL_RPATH. --- CMakeLists.txt | 5 +++++ modules/CMakeLists.txt | 16 ++++++++++++++++ plugin.c | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f07ee9..4b9ed27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,4 +84,9 @@ target_compile_options(module-sdk INTERFACE ${CAIRO_CFLAGS_OTHER}) target_include_directories(module-sdk INTERFACE ${CAIRO_INCLUDE_DIRS}) target_link_libraries(module-sdk INTERFACE ${CMAKE_THREAD_LIBS_INIT}) +set_property(TARGET f00bar PROPERTY INSTALL_RPATH \$ORIGIN/../lib/f00bar) +set_property(TARGET f00bar PROPERTY BUILD_RPATH \$ORIGIN/modules) + +install(TARGETS f00bar DESTINATION bin) + add_subdirectory(modules) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index ffceaec..285ff58 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -52,3 +52,19 @@ target_link_libraries(xkb module-sdk ${XCB_XKB_LIBRARIES}) add_library(xwindow MODULE xwindow/xwindow.c xwindow/xwindow.h) target_link_libraries(xwindow module-sdk) + +install( + TARGETS + alsa + backlight + battery + clock + i3 + label + mpd + network + removables + xkb + xwindow + + DESTINATION lib/f00bar) diff --git a/plugin.c b/plugin.c index 8eb2781..7edfc2f 100644 --- a/plugin.c +++ b/plugin.c @@ -38,7 +38,7 @@ const struct module_info * plugin_load_module(const char *name) { char path[128]; - snprintf(path, sizeof(path), "./modules/lib%s.so", name); + snprintf(path, sizeof(path), "lib%s.so", name); /* Have we already loaded it? */ tll_foreach(libs, plug) { From aa6ea602cab504db8072b55bdad8af3d98fbb0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 21:13:50 +0100 Subject: [PATCH 26/31] plugin: remove linked-list items as we --- plugin.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin.c b/plugin.c index 7edfc2f..3cc20db 100644 --- a/plugin.c +++ b/plugin.c @@ -29,9 +29,8 @@ fini(void) LOG_ERR("%s: dlclose(): %s", plug->item.name, dl_error); free(plug->item.name); + tll_remove(libs, plug); } - - tll_free(libs); } const struct module_info * From aa4fede3066beedfcef089893bae35e376d0e199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 21:16:13 +0100 Subject: [PATCH 27/31] plugin: use tll_free_and_free() to free the global plugin list --- plugin.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/plugin.c b/plugin.c index 3cc20db..5291250 100644 --- a/plugin.c +++ b/plugin.c @@ -17,20 +17,23 @@ struct plugin { static tll(struct plugin) libs = tll_init(); +static void +free_lib(struct plugin plug) +{ + dlerror(); + dlclose(plug.lib); + + const char *dl_error = dlerror(); + if (dl_error != NULL) + LOG_ERR("%s: dlclose(): %s", plug.name, dl_error); + + free(plug.name); +} + static void __attribute__((destructor)) fini(void) { - tll_foreach(libs, plug) { - dlerror(); - dlclose(plug->item.lib); - - const char *dl_error = dlerror(); - if (dl_error != NULL) - LOG_ERR("%s: dlclose(): %s", plug->item.name, dl_error); - - free(plug->item.name); - tll_remove(libs, plug); - } + tll_free_and_free(libs, free_lib); } const struct module_info * From 9fa37f0d980ed904330df9d256a11cc2a1f03140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 21:17:12 +0100 Subject: [PATCH 28/31] plugin: 'libs' -> 'plugins' --- plugin.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugin.c b/plugin.c index 5291250..7f59e55 100644 --- a/plugin.c +++ b/plugin.c @@ -15,10 +15,10 @@ struct plugin { const void *sym; }; -static tll(struct plugin) libs = tll_init(); +static tll(struct plugin) plugins = tll_init(); static void -free_lib(struct plugin plug) +free_plugin(struct plugin plug) { dlerror(); dlclose(plug.lib); @@ -33,7 +33,7 @@ free_lib(struct plugin plug) static void __attribute__((destructor)) fini(void) { - tll_free_and_free(libs, free_lib); + tll_free_and_free(plugins, free_plugin); } const struct module_info * @@ -43,7 +43,7 @@ plugin_load_module(const char *name) snprintf(path, sizeof(path), "lib%s.so", name); /* Have we already loaded it? */ - tll_foreach(libs, plug) { + tll_foreach(plugins, plug) { if (strcmp(plug->item.name, name) == 0) { LOG_DBG("%s already loaded: %p", name, plug->item.lib); assert(plug->item.sym != NULL); @@ -60,8 +60,8 @@ plugin_load_module(const char *name) return NULL; } - tll_push_back(libs, ((struct plugin){strdup(name), lib})); - struct plugin *plug = &tll_back(libs); + tll_push_back(plugins, ((struct plugin){strdup(name), lib})); + struct plugin *plug = &tll_back(plugins); dlerror(); /* Clear previous error */ plug->sym = dlsym(lib, "module_info"); From e7e7284cba2591ba9473035acd2edf32d3aadb5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 21:20:52 +0100 Subject: [PATCH 29/31] modules: remove header files --- modules/CMakeLists.txt | 22 +++++++++++----------- modules/alsa/alsa.c | 2 -- modules/alsa/alsa.h | 4 ---- modules/backlight/backlight.c | 2 -- modules/backlight/backlight.h | 4 ---- modules/battery/battery.c | 2 -- modules/battery/battery.h | 4 ---- modules/clock/clock.c | 1 - modules/clock/clock.h | 4 ---- modules/i3/i3.c | 2 -- modules/i3/i3.h | 4 ---- modules/label/label.c | 2 -- modules/label/label.h | 4 ---- modules/mpd/mpd.c | 2 -- modules/mpd/mpd.h | 4 ---- modules/network/network.c | 2 -- modules/network/network.h | 4 ---- modules/removables/removables.c | 2 -- modules/removables/removables.h | 4 ---- modules/xkb/xkb.c | 2 -- modules/xkb/xkb.h | 4 ---- modules/xwindow/xwindow.c | 2 -- modules/xwindow/xwindow.h | 4 ---- 23 files changed, 11 insertions(+), 76 deletions(-) delete mode 100644 modules/alsa/alsa.h delete mode 100644 modules/backlight/backlight.h delete mode 100644 modules/battery/battery.h delete mode 100644 modules/clock/clock.h delete mode 100644 modules/i3/i3.h delete mode 100644 modules/label/label.h delete mode 100644 modules/mpd/mpd.h delete mode 100644 modules/network/network.h delete mode 100644 modules/removables/removables.h delete mode 100644 modules/xkb/xkb.h delete mode 100644 modules/xwindow/xwindow.h diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 285ff58..9df5a96 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,56 +1,56 @@ cmake_minimum_required(VERSION 3.13) pkg_check_modules(ALSA REQUIRED alsa) -add_library(alsa MODULE alsa/alsa.c alsa/alsa.h) +add_library(alsa MODULE alsa/alsa.c) target_compile_options(alsa PRIVATE ${ALSA_CFLAGS_OTHER}) target_include_directories(alsa PRIVATE ${ALSA_INCLUDE_DIRS}) target_link_libraries(alsa module-sdk ${ALSA_LIBRARIES}) pkg_check_modules(UDEV REQUIRED libudev) -add_library(backlight MODULE backlight/backlight.c backlight/backlight.h) +add_library(backlight MODULE backlight/backlight.c) target_compile_options(backlight PRIVATE ${UDEV_CFLAGS_OTHER}) target_include_directories(backlight PRIVATE ${UDEV_INCLUDE_DIRS}) target_link_libraries(backlight module-sdk ${UDEV_LIBRARIES}) -add_library(battery MODULE battery/battery.c battery/battery.h) +add_library(battery MODULE battery/battery.c) target_compile_options(battery PRIVATE ${UDEV_CFLAGS_OTHER}) target_include_directories(battery PRIVATE ${UDEV_INCLUDE_DIRS}) target_link_libraries(battery module-sdk ${UDEV_LIBRARIES}) -add_library(clock MODULE clock/clock.c clock/clock.h) +add_library(clock MODULE clock/clock.c) target_link_libraries(clock module-sdk) pkg_check_modules(JSON REQUIRED json-c) -add_library(i3 MODULE i3/i3.c i3/i3.h) +add_library(i3 MODULE i3/i3.c) target_compile_options(i3 PRIVATE ${JSON_CFLAGS_OTHER}) target_include_directories(i3 PRIVATE ${JSON_INCLUDE_DIRS}) target_link_libraries(i3 module-sdk ${JSON_LIBRARIES}) -add_library(label MODULE label/label.c label/label.h) +add_library(label MODULE label/label.c) target_link_libraries(label module-sdk) pkg_check_modules(MPD REQUIRED libmpdclient) -add_library(mpd MODULE mpd/mpd.c mpd/mpd.h) +add_library(mpd MODULE mpd/mpd.c) target_compile_options(mpd PRIVATE ${MPD_CFLAGS_OTHER}) target_include_directories(mpd PRIVATE ${MPD_INCLUDE_DIRS}) target_link_libraries(mpd module-sdk ${MPD_LIBRARIES}) -add_library(network MODULE network/network.c network/network.h) +add_library(network MODULE network/network.c) target_link_libraries(network module-sdk) -add_library(removables MODULE removables/removables.c removables/removables.h) +add_library(removables MODULE removables/removables.c) target_compile_options(removables PRIVATE ${UDEV_CFLAGS_OTHER}) target_include_directories(removables PRIVATE ${UDEV_INCLUDE_DIRS}) target_link_libraries(removables module-sdk ${UDEV_LIBRARIES}) pkg_check_modules(XCB_XKB REQUIRED xcb-xkb) -add_library(xkb MODULE xkb/xkb.c xkb/xkb.h) +add_library(xkb MODULE xkb/xkb.c) target_compile_options(xkb PRIVATE ${XCB_XKB_CFLAGS_OTHER}) target_include_directories(xkb PRIVATE ${XCB_XKB_INCLUDE_DIRS}) target_link_libraries(xkb module-sdk ${XCB_XKB_LIBRARIES}) -add_library(xwindow MODULE xwindow/xwindow.c xwindow/xwindow.h) +add_library(xwindow MODULE xwindow/xwindow.c) target_link_libraries(xwindow module-sdk) install( diff --git a/modules/alsa/alsa.c b/modules/alsa/alsa.c index 856d7fe..bb4be50 100644 --- a/modules/alsa/alsa.c +++ b/modules/alsa/alsa.c @@ -1,5 +1,3 @@ -#include "alsa.h" - #include #include diff --git a/modules/alsa/alsa.h b/modules/alsa/alsa.h deleted file mode 100644 index a19c122..0000000 --- a/modules/alsa/alsa.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_alsa; diff --git a/modules/backlight/backlight.c b/modules/backlight/backlight.c index f8f9975..420fd2b 100644 --- a/modules/backlight/backlight.c +++ b/modules/backlight/backlight.c @@ -1,5 +1,3 @@ -#include "backlight.h" - #include #include #include diff --git a/modules/backlight/backlight.h b/modules/backlight/backlight.h deleted file mode 100644 index f390f2e..0000000 --- a/modules/backlight/backlight.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_backlight; diff --git a/modules/battery/battery.c b/modules/battery/battery.c index 69bb4ea..172041a 100644 --- a/modules/battery/battery.c +++ b/modules/battery/battery.c @@ -1,5 +1,3 @@ -#include "battery.h" - #include #include #include diff --git a/modules/battery/battery.h b/modules/battery/battery.h deleted file mode 100644 index e8d89be..0000000 --- a/modules/battery/battery.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_battery; diff --git a/modules/clock/clock.c b/modules/clock/clock.c index 74c1664..eda4b32 100644 --- a/modules/clock/clock.c +++ b/modules/clock/clock.c @@ -1,4 +1,3 @@ -#include "clock.h" #include #include #include diff --git a/modules/clock/clock.h b/modules/clock/clock.h deleted file mode 100644 index 990ff64..0000000 --- a/modules/clock/clock.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_clock; diff --git a/modules/i3/i3.c b/modules/i3/i3.c index f3f52c2..9e1234d 100644 --- a/modules/i3/i3.c +++ b/modules/i3/i3.c @@ -1,5 +1,3 @@ -#include "i3.h" - #include #include #include diff --git a/modules/i3/i3.h b/modules/i3/i3.h deleted file mode 100644 index de1c0ae..0000000 --- a/modules/i3/i3.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_i3; diff --git a/modules/label/label.c b/modules/label/label.c index 3f97216..d23f031 100644 --- a/modules/label/label.c +++ b/modules/label/label.c @@ -1,5 +1,3 @@ -#include "label.h" - #include #include diff --git a/modules/label/label.h b/modules/label/label.h deleted file mode 100644 index b181d2d..0000000 --- a/modules/label/label.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_label; diff --git a/modules/mpd/mpd.c b/modules/mpd/mpd.c index a17008d..01076ed 100644 --- a/modules/mpd/mpd.c +++ b/modules/mpd/mpd.c @@ -1,5 +1,3 @@ -#include "mpd.h" - #include #include #include diff --git a/modules/mpd/mpd.h b/modules/mpd/mpd.h deleted file mode 100644 index 57959e1..0000000 --- a/modules/mpd/mpd.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_mpd; diff --git a/modules/network/network.c b/modules/network/network.c index 0444c70..88f2c86 100644 --- a/modules/network/network.c +++ b/modules/network/network.c @@ -1,5 +1,3 @@ -#include "network.h" - #include #include #include diff --git a/modules/network/network.h b/modules/network/network.h deleted file mode 100644 index 2c7aa57..0000000 --- a/modules/network/network.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_network; diff --git a/modules/removables/removables.c b/modules/removables/removables.c index 2b64707..e040aaf 100644 --- a/modules/removables/removables.c +++ b/modules/removables/removables.c @@ -1,5 +1,3 @@ -#include "removables.h" - #include #include #include diff --git a/modules/removables/removables.h b/modules/removables/removables.h deleted file mode 100644 index d5e96aa..0000000 --- a/modules/removables/removables.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_removables; diff --git a/modules/xkb/xkb.c b/modules/xkb/xkb.c index b299a80..eea3c55 100644 --- a/modules/xkb/xkb.c +++ b/modules/xkb/xkb.c @@ -1,5 +1,3 @@ -#include "xkb.h" - #include #include #include diff --git a/modules/xkb/xkb.h b/modules/xkb/xkb.h deleted file mode 100644 index d38743e..0000000 --- a/modules/xkb/xkb.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_xkb; diff --git a/modules/xwindow/xwindow.c b/modules/xwindow/xwindow.c index 4114e69..1208ed7 100644 --- a/modules/xwindow/xwindow.c +++ b/modules/xwindow/xwindow.c @@ -1,5 +1,3 @@ -#include "xwindow.h" - #include #include #include diff --git a/modules/xwindow/xwindow.h b/modules/xwindow/xwindow.h deleted file mode 100644 index 0f67953..0000000 --- a/modules/xwindow/xwindow.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../../module.h" - -extern const struct module_info module_xwindow; From 42104db1ca759fc02379b66435b849255ae4788b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 21:24:20 +0100 Subject: [PATCH 30/31] modules: move files back to a common directory (again) --- modules/CMakeLists.txt | 22 +++++++++++----------- modules/{alsa => }/alsa.c | 8 ++++---- modules/{backlight => }/backlight.c | 6 +++--- modules/{battery => }/battery.c | 6 +++--- modules/{clock => }/clock.c | 4 ++-- modules/{i3 => }/i3.c | 8 ++++---- modules/{label => }/label.c | 2 +- modules/{mpd => }/mpd.c | 6 +++--- modules/{network => }/network.c | 10 +++++----- modules/{removables => }/removables.c | 10 +++++----- modules/{xkb => }/xkb.c | 8 ++++---- modules/{xwindow => }/xwindow.c | 8 ++++---- 12 files changed, 49 insertions(+), 49 deletions(-) rename modules/{alsa => }/alsa.c (98%) rename modules/{backlight => }/backlight.c (98%) rename modules/{battery => }/battery.c (99%) rename modules/{clock => }/clock.c (98%) rename modules/{i3 => }/i3.c (99%) rename modules/{label => }/label.c (97%) rename modules/{mpd => }/mpd.c (99%) rename modules/{network => }/network.c (99%) rename modules/{removables => }/removables.c (99%) rename modules/{xkb => }/xkb.c (99%) rename modules/{xwindow => }/xwindow.c (98%) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 9df5a96..ff55cc4 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,56 +1,56 @@ cmake_minimum_required(VERSION 3.13) pkg_check_modules(ALSA REQUIRED alsa) -add_library(alsa MODULE alsa/alsa.c) +add_library(alsa MODULE alsa.c) target_compile_options(alsa PRIVATE ${ALSA_CFLAGS_OTHER}) target_include_directories(alsa PRIVATE ${ALSA_INCLUDE_DIRS}) target_link_libraries(alsa module-sdk ${ALSA_LIBRARIES}) pkg_check_modules(UDEV REQUIRED libudev) -add_library(backlight MODULE backlight/backlight.c) +add_library(backlight MODULE backlight.c) target_compile_options(backlight PRIVATE ${UDEV_CFLAGS_OTHER}) target_include_directories(backlight PRIVATE ${UDEV_INCLUDE_DIRS}) target_link_libraries(backlight module-sdk ${UDEV_LIBRARIES}) -add_library(battery MODULE battery/battery.c) +add_library(battery MODULE battery.c) target_compile_options(battery PRIVATE ${UDEV_CFLAGS_OTHER}) target_include_directories(battery PRIVATE ${UDEV_INCLUDE_DIRS}) target_link_libraries(battery module-sdk ${UDEV_LIBRARIES}) -add_library(clock MODULE clock/clock.c) +add_library(clock MODULE clock.c) target_link_libraries(clock module-sdk) pkg_check_modules(JSON REQUIRED json-c) -add_library(i3 MODULE i3/i3.c) +add_library(i3 MODULE i3.c) target_compile_options(i3 PRIVATE ${JSON_CFLAGS_OTHER}) target_include_directories(i3 PRIVATE ${JSON_INCLUDE_DIRS}) target_link_libraries(i3 module-sdk ${JSON_LIBRARIES}) -add_library(label MODULE label/label.c) +add_library(label MODULE label.c) target_link_libraries(label module-sdk) pkg_check_modules(MPD REQUIRED libmpdclient) -add_library(mpd MODULE mpd/mpd.c) +add_library(mpd MODULE mpd.c) target_compile_options(mpd PRIVATE ${MPD_CFLAGS_OTHER}) target_include_directories(mpd PRIVATE ${MPD_INCLUDE_DIRS}) target_link_libraries(mpd module-sdk ${MPD_LIBRARIES}) -add_library(network MODULE network/network.c) +add_library(network MODULE network.c) target_link_libraries(network module-sdk) -add_library(removables MODULE removables/removables.c) +add_library(removables MODULE removables.c) target_compile_options(removables PRIVATE ${UDEV_CFLAGS_OTHER}) target_include_directories(removables PRIVATE ${UDEV_INCLUDE_DIRS}) target_link_libraries(removables module-sdk ${UDEV_LIBRARIES}) pkg_check_modules(XCB_XKB REQUIRED xcb-xkb) -add_library(xkb MODULE xkb/xkb.c) +add_library(xkb MODULE xkb.c) target_compile_options(xkb PRIVATE ${XCB_XKB_CFLAGS_OTHER}) target_include_directories(xkb PRIVATE ${XCB_XKB_INCLUDE_DIRS}) target_link_libraries(xkb module-sdk ${XCB_XKB_LIBRARIES}) -add_library(xwindow MODULE xwindow/xwindow.c) +add_library(xwindow MODULE xwindow.c) target_link_libraries(xwindow module-sdk) install( diff --git a/modules/alsa/alsa.c b/modules/alsa.c similarity index 98% rename from modules/alsa/alsa.c rename to modules/alsa.c index bb4be50..968f777 100644 --- a/modules/alsa/alsa.c +++ b/modules/alsa.c @@ -5,10 +5,10 @@ #define LOG_MODULE "alsa" #define LOG_ENABLE_DBG 0 -#include "../../log.h" -#include "../../bar.h" -#include "../../config.h" -#include "../../tllist.h" +#include "../log.h" +#include "../bar.h" +#include "../config.h" +#include "../tllist.h" struct private { char *card; diff --git a/modules/backlight/backlight.c b/modules/backlight.c similarity index 98% rename from modules/backlight/backlight.c rename to modules/backlight.c index 420fd2b..8c06851 100644 --- a/modules/backlight/backlight.c +++ b/modules/backlight.c @@ -11,9 +11,9 @@ #include #define LOG_MODULE "battery" -#include "../../log.h" -#include "../../bar.h" -#include "../../config.h" +#include "../log.h" +#include "../bar.h" +#include "../config.h" struct private { struct particle *label; diff --git a/modules/battery/battery.c b/modules/battery.c similarity index 99% rename from modules/battery/battery.c rename to modules/battery.c index 172041a..3c42a16 100644 --- a/modules/battery/battery.c +++ b/modules/battery.c @@ -12,9 +12,9 @@ #include #define LOG_MODULE "battery" -#include "../../log.h" -#include "../../bar.h" -#include "../../config.h" +#include "../log.h" +#include "../bar.h" +#include "../config.h" enum state { STATE_FULL, STATE_CHARGING, STATE_DISCHARGING }; diff --git a/modules/clock/clock.c b/modules/clock.c similarity index 98% rename from modules/clock/clock.c rename to modules/clock.c index eda4b32..6a9841e 100644 --- a/modules/clock/clock.c +++ b/modules/clock.c @@ -5,8 +5,8 @@ #include -#include "../../bar.h" -#include "../../config.h" +#include "../bar.h" +#include "../config.h" struct private { struct particle *label; diff --git a/modules/i3/i3.c b/modules/i3.c similarity index 99% rename from modules/i3/i3.c rename to modules/i3.c index 9e1234d..9b6bb2d 100644 --- a/modules/i3/i3.c +++ b/modules/i3.c @@ -17,11 +17,11 @@ #define LOG_MODULE "i3" #define LOG_ENABLE_DBG 0 -#include "../../log.h" -#include "../../bar.h" -#include "../../config.h" +#include "../log.h" +#include "../bar.h" +#include "../config.h" -#include "../../particles/dynlist.h" +#include "../particles/dynlist.h" struct ws_content { char *name; diff --git a/modules/label/label.c b/modules/label.c similarity index 97% rename from modules/label/label.c rename to modules/label.c index d23f031..ab7b2d6 100644 --- a/modules/label/label.c +++ b/modules/label.c @@ -3,7 +3,7 @@ #include -#include "../../config.h" +#include "../config.h" struct private { struct particle *label; diff --git a/modules/mpd/mpd.c b/modules/mpd.c similarity index 99% rename from modules/mpd/mpd.c rename to modules/mpd.c index 01076ed..c833e5d 100644 --- a/modules/mpd/mpd.c +++ b/modules/mpd.c @@ -14,9 +14,9 @@ #define LOG_MODULE "mpd" #define LOG_ENABLE_DBG 0 -#include "../../log.h" -#include "../../bar.h" -#include "../../config.h" +#include "../log.h" +#include "../bar.h" +#include "../config.h" enum state { STATE_OFFLINE = 1000, diff --git a/modules/network/network.c b/modules/network.c similarity index 99% rename from modules/network/network.c rename to modules/network.c index 88f2c86..598a3eb 100644 --- a/modules/network/network.c +++ b/modules/network.c @@ -14,11 +14,11 @@ #define LOG_MODULE "network" #define LOG_ENABLE_DBG 0 -#include "../../log.h" -#include "../../bar.h" -#include "../../config.h" -#include "../../module.h" -#include "../../tllist.h" +#include "../log.h" +#include "../bar.h" +#include "../config.h" +#include "../module.h" +#include "../tllist.h" struct af_addr { int family; diff --git a/modules/removables/removables.c b/modules/removables.c similarity index 99% rename from modules/removables/removables.c rename to modules/removables.c index e040aaf..caa6100 100644 --- a/modules/removables/removables.c +++ b/modules/removables.c @@ -14,11 +14,11 @@ #define LOG_MODULE "removables" #define LOG_ENABLE_DBG 0 -#include "../../log.h" -#include "../../bar.h" -#include "../../config.h" -#include "../../particles/dynlist.h" -#include "../../tllist.h" +#include "../log.h" +#include "../bar.h" +#include "../config.h" +#include "../particles/dynlist.h" +#include "../tllist.h" typedef tll(char *) mount_point_list_t; diff --git a/modules/xkb/xkb.c b/modules/xkb.c similarity index 99% rename from modules/xkb/xkb.c rename to modules/xkb.c index eea3c55..3b1d2d7 100644 --- a/modules/xkb/xkb.c +++ b/modules/xkb.c @@ -9,10 +9,10 @@ #include #define LOG_MODULE "xkb" -#include "../../log.h" -#include "../../bar.h" -#include "../../config.h" -#include "../../xcb.h" +#include "../log.h" +#include "../bar.h" +#include "../config.h" +#include "../xcb.h" struct layout { char *name; diff --git a/modules/xwindow/xwindow.c b/modules/xwindow.c similarity index 98% rename from modules/xwindow/xwindow.c rename to modules/xwindow.c index 1208ed7..167d1fa 100644 --- a/modules/xwindow/xwindow.c +++ b/modules/xwindow.c @@ -13,10 +13,10 @@ #include #define LOG_MODULE "xkb" -#include "../../log.h" -#include "../../bar.h" -#include "../../config.h" -#include "../../xcb.h" +#include "../log.h" +#include "../bar.h" +#include "../config.h" +#include "../xcb.h" struct private { /* Accessed from bar thread only */ From dea5055e373992b1033c2c1fc357d72fb57ec39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 12 Jan 2019 22:23:49 +0100 Subject: [PATCH 31/31] cmake: cleanup --- modules/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index ff55cc4..9ea7116 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -26,7 +26,6 @@ target_compile_options(i3 PRIVATE ${JSON_CFLAGS_OTHER}) target_include_directories(i3 PRIVATE ${JSON_INCLUDE_DIRS}) target_link_libraries(i3 module-sdk ${JSON_LIBRARIES}) - add_library(label MODULE label.c) target_link_libraries(label module-sdk)