From ed2b8c48746165b7ed3ab2078d49d3b2b7b74d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 20 Jun 2021 21:15:24 +0200 Subject: [PATCH] modules: implement description() --- modules/alsa.c | 10 ++++++++++ modules/backlight.c | 7 +++++++ modules/battery.c | 10 ++++++++++ modules/clock.c | 8 ++++++++ modules/i3.c | 7 +++++++ modules/label.c | 7 +++++++ modules/mpd.c | 7 +++++++ modules/network.c | 11 +++++++++++ modules/removables.c | 7 +++++++ modules/river.c | 7 +++++++ modules/script.c | 14 ++++++++++++++ modules/sway-xkb.c | 7 +++++++ modules/xkb.c | 7 +++++++ modules/xwindow.c | 7 +++++++ 14 files changed, 116 insertions(+) diff --git a/modules/alsa.c b/modules/alsa.c index 9e410df..3b71a25 100644 --- a/modules/alsa.c +++ b/modules/alsa.c @@ -39,6 +39,15 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + static char desc[32]; + struct private *m = mod->private; + snprintf(desc, sizeof(desc), "alsa(%s)", m->card); + return desc; +} + static struct exposable * content(struct module *mod) { @@ -287,6 +296,7 @@ alsa_new(const char *card, const char *mixer, struct particle *label) mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/backlight.c b/modules/backlight.c index 053a998..e7bca2e 100644 --- a/modules/backlight.c +++ b/modules/backlight.c @@ -38,6 +38,12 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + return "backlight"; +} + static struct exposable * content(struct module *mod) { @@ -216,6 +222,7 @@ backlight_new(const char *device, struct particle *label) mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/battery.c b/modules/battery.c index f5cc0f8..4a55141 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -57,6 +57,15 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + static char desc[32]; + struct private *m = mod->private; + snprintf(desc, sizeof(desc), "bat(%s)", m->battery); + return desc; +} + static struct exposable * content(struct module *mod) { @@ -462,6 +471,7 @@ battery_new(const char *battery, struct particle *label, int poll_interval_secs) mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/clock.c b/modules/clock.c index e9f1694..b0db44e 100644 --- a/modules/clock.c +++ b/modules/clock.c @@ -35,6 +35,12 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + return "clock"; +} + static struct exposable * content(struct module *mod) { @@ -60,6 +66,7 @@ content(struct module *mod) return exposable; } +#include static int run(struct module *mod) { @@ -161,6 +168,7 @@ clock_new(struct particle *label, const char *date_format, const char *time_form mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/i3.c b/modules/i3.c index e2f58de..5aa3d3b 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -608,6 +608,12 @@ ws_content_for_name(struct private *m, const char *name) return NULL; } +static const char * +description(struct module *mod) +{ + return "i3/sway"; +} + static struct exposable * content(struct module *mod) { @@ -710,6 +716,7 @@ i3_new(struct i3_workspaces workspaces[], size_t workspace_count, mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/label.c b/modules/label.c index a29b6bd..01fce76 100644 --- a/modules/label.c +++ b/modules/label.c @@ -21,6 +21,12 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + return "label"; +} + static struct exposable * content(struct module *mod) { @@ -45,6 +51,7 @@ label_new(struct particle *label) mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/mpd.c b/modules/mpd.c index a501f76..bebd401 100644 --- a/modules/mpd.c +++ b/modules/mpd.c @@ -83,6 +83,12 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + return "mpd"; +} + static uint64_t timespec_diff_milli_seconds(const struct timespec *a, const struct timespec *b) { @@ -588,6 +594,7 @@ mpd_new(const char *host, uint16_t port, struct particle *label) mod->destroy = &destroy; mod->content = &content; mod->refresh_in = &refresh_in; + mod->description = &description; return mod; } diff --git a/modules/network.c b/modules/network.c index 51839bf..c6b32af 100644 --- a/modules/network.c +++ b/modules/network.c @@ -66,6 +66,16 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + static char desc[32]; + struct private *m = mod->private; + + snprintf(desc, sizeof(desc), "net(%s)", m->iface); + return desc; +} + static struct exposable * content(struct module *mod) { @@ -526,6 +536,7 @@ network_new(const char *iface, struct particle *label) mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/removables.c b/modules/removables.c index 498824b..4446f3d 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -97,6 +97,12 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + return "removables"; +} + static struct exposable * content(struct module *mod) { @@ -596,6 +602,7 @@ removables_new(struct particle *label, int left_spacing, int right_spacing, mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/river.c b/modules/river.c index b6e3db1..95ed8d3 100644 --- a/modules/river.c +++ b/modules/river.c @@ -65,6 +65,12 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + return "river"; +} + static struct exposable * content(struct module *mod) { @@ -645,6 +651,7 @@ river_new(struct particle *template, struct particle *title) mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; m->mod = mod; return mod; } diff --git a/modules/script.c b/modules/script.c index a938f7d..a034910 100644 --- a/modules/script.c +++ b/modules/script.c @@ -56,6 +56,19 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + static char desc[32]; + struct private *m = mod->private; + + char *path = strdup(m->path); + snprintf(desc, sizeof(desc), "script(%s)", basename(path)); + + free(path); + return desc; +} + static struct exposable * content(struct module *mod) { @@ -569,6 +582,7 @@ script_new(const char *path, size_t argc, const char *const argv[static argc], mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/sway-xkb.c b/modules/sway-xkb.c index d6960d9..295b976 100644 --- a/modules/sway-xkb.c +++ b/modules/sway-xkb.c @@ -52,6 +52,12 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + return "sway-xkb"; +} + static struct exposable * content(struct module *mod) { @@ -307,6 +313,7 @@ sway_xkb_new(struct particle *template, const char *identifiers[], mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/xkb.c b/modules/xkb.c index 16cc864..5c2c1f9 100644 --- a/modules/xkb.c +++ b/modules/xkb.c @@ -72,6 +72,12 @@ destroy(struct module *mod) module_default_destroy(mod); } +static const char * +description(struct module *mod) +{ + return "xkb"; +} + static struct exposable * content(struct module *mod) { @@ -650,6 +656,7 @@ xkb_new(struct particle *label) mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; } diff --git a/modules/xwindow.c b/modules/xwindow.c index ad856a4..3c8655e 100644 --- a/modules/xwindow.c +++ b/modules/xwindow.c @@ -36,6 +36,12 @@ struct private { xcb_window_t active_win; }; +static const char * +description(struct module *mod) +{ + return "xwindow"; +} + static void update_active_window(struct private *m) { @@ -332,6 +338,7 @@ xwindow_new(struct particle *label) mod->run = &run; mod->destroy = &destroy; mod->content = &content; + mod->description = &description; return mod; }