diff --git a/modules/backlight/backlight.c b/modules/backlight/backlight.c index c0aa04a..6943b14 100644 --- a/modules/backlight/backlight.c +++ b/modules/backlight/backlight.c @@ -44,8 +44,9 @@ content(struct module *mod) mtx_lock(&mod->lock); struct tag_set tags = { .tags = (struct tag *[]){ - tag_new_int_range("brightness", m->current_brightness, 0, m->max_brightness), - tag_new_int("max_brightness", m->max_brightness), + tag_new_int_range(mod, "brightness", m->current_brightness, + 0, m->max_brightness), + tag_new_int(mod, "max_brightness", m->max_brightness), }, .count = 2, }; diff --git a/modules/battery/battery.c b/modules/battery/battery.c index 091b5b6..8becd2e 100644 --- a/modules/battery/battery.c +++ b/modules/battery/battery.c @@ -79,16 +79,16 @@ content(struct module *mod) struct tag_set tags = { .tags = (struct tag *[]){ - tag_new_string("name", m->battery), - tag_new_string("manufacturer", m->manufacturer), - tag_new_string("model", m->model), - tag_new_string("state", + tag_new_string(mod, "name", m->battery), + tag_new_string(mod, "manufacturer", m->manufacturer), + tag_new_string(mod, "model", m->model), + tag_new_string(mod, "state", m->state == STATE_FULL ? "full" : m->state == STATE_CHARGING ? "charging" : m->state == STATE_DISCHARGING ? "discharging" : "unknown"), - tag_new_int_range("capacity", m->capacity, 0, 100), - tag_new_string("estimate", estimate), + tag_new_int_range(mod, "capacity", m->capacity, 0, 100), + tag_new_string(mod, "estimate", estimate), }, .count = 6, }; diff --git a/modules/clock/clock.c b/modules/clock/clock.c index 3a05bf4..4d4bf52 100644 --- a/modules/clock/clock.c +++ b/modules/clock/clock.c @@ -34,8 +34,8 @@ content(struct module *mod) strftime(date_str, sizeof(date_str), "%e %b", tm); struct tag_set tags = { - .tags = (struct tag *[]){tag_new_string("time", time_str), - tag_new_string("date", date_str)}, + .tags = (struct tag *[]){tag_new_string(mod, "time", time_str), + tag_new_string(mod, "date", date_str)}, .count = 2, }; diff --git a/modules/i3/i3.c b/modules/i3/i3.c index 76c10df..775c765 100644 --- a/modules/i3/i3.c +++ b/modules/i3/i3.c @@ -559,11 +559,11 @@ content(struct module *mod) struct tag_set tags = { .tags = (struct tag *[]){ - tag_new_string("name", ws->name), - tag_new_bool("visible", ws->visible), - tag_new_bool("focused", ws->focused), - tag_new_bool("urgent", ws->urgent), - tag_new_string("state", state), + tag_new_string(mod, "name", ws->name), + tag_new_bool(mod, "visible", ws->visible), + tag_new_bool(mod, "focused", ws->focused), + tag_new_bool(mod, "urgent", ws->urgent), + tag_new_string(mod, "state", state), }, .count = 5, }; diff --git a/modules/mpd/mpd.c b/modules/mpd/mpd.c index 8af93c6..c058410 100644 --- a/modules/mpd/mpd.c +++ b/modules/mpd/mpd.c @@ -88,13 +88,13 @@ content(struct module *mod) struct tag_set tags = { .tags = (struct tag *[]){ - tag_new_string("state", state_str), - tag_new_string("album", m->album), - tag_new_string("artist", m->artist), - tag_new_string("title", m->title), - tag_new_string("pos", pos), - tag_new_string("end", end), - tag_new_int("duration", m->duration), + tag_new_string(mod, "state", state_str), + tag_new_string(mod, "album", m->album), + tag_new_string(mod, "artist", m->artist), + tag_new_string(mod, "title", m->title), + tag_new_string(mod, "pos", pos), + tag_new_string(mod, "end", end), + tag_new_int(mod, "duration", m->duration), tag_new_int_realtime( "elapsed", m->elapsed, 0, m->duration, m->state == STATE_PLAY ? TAG_REALTIME_SECONDS : TAG_REALTIME_NONE), diff --git a/modules/xkb/xkb.c b/modules/xkb/xkb.c index 7274493..ea35b9c 100644 --- a/modules/xkb/xkb.c +++ b/modules/xkb/xkb.c @@ -58,8 +58,8 @@ content(struct module *mod) struct tag_set tags = { .tags = (struct tag *[]){ - tag_new_string("name", m->layouts.layouts[m->current].name), - tag_new_string("symbol", m->layouts.layouts[m->current].symbol)}, + tag_new_string(mod, "name", m->layouts.layouts[m->current].name), + tag_new_string(mod, "symbol", m->layouts.layouts[m->current].symbol)}, .count = 2, }; diff --git a/modules/xwindow/xwindow.c b/modules/xwindow/xwindow.c index 400f07f..62707e8 100644 --- a/modules/xwindow/xwindow.c +++ b/modules/xwindow/xwindow.c @@ -272,8 +272,9 @@ content(struct module *mod) mtx_lock(&mod->lock); struct tag_set tags = { .tags = (struct tag *[]){ - tag_new_string("application", m->application ? m->application : ""), - tag_new_string("title", m->title ? m->title : "")}, + tag_new_string(mod, "application", m->application), + tag_new_string(mod, "title", m->title), + }, .count = 2, }; mtx_unlock(&mod->lock); diff --git a/tag.c b/tag.c index da24395..deee1bb 100644 --- a/tag.c +++ b/tag.c @@ -4,6 +4,8 @@ #include #include +#include "module.h" + struct private { char *name; union { @@ -204,20 +206,21 @@ string_as_float(const struct tag *tag) } struct tag * -tag_new_int(const char *name, long value) +tag_new_int(struct module *owner, const char *name, long value) { - return tag_new_int_range(name, value, value, value); + return tag_new_int_range(owner, name, value, value, value); } struct tag * -tag_new_int_range(const char *name, long value, long min, long max) +tag_new_int_range(struct module *owner, const char *name, long value, + long min, long max) { - return tag_new_int_realtime(name, value, min, max, TAG_REALTIME_NONE); + return tag_new_int_realtime(owner, name, value, min, max, TAG_REALTIME_NONE); } struct tag * -tag_new_int_realtime(const char *name, long value, long min, long max, - enum tag_realtime_unit unit) +tag_new_int_realtime(struct module *owner, const char *name, long value, + long min, long max, enum tag_realtime_unit unit) { struct private *priv = malloc(sizeof(*priv)); priv->name = strdup(name); @@ -228,11 +231,13 @@ tag_new_int_realtime(const char *name, long value, long min, long max, struct tag *tag = malloc(sizeof(*tag)); tag->private = priv; + tag->owner = owner; tag->destroy = &destroy_int_and_float; tag->name = &tag_name; tag->min = &int_min; tag->max = &int_max; tag->realtime = &int_realtime; + tag->refresh_in = &int_refresh_in; tag->as_string = &int_as_string; tag->as_int = &int_as_int; tag->as_bool = &int_as_bool; @@ -241,7 +246,7 @@ tag_new_int_realtime(const char *name, long value, long min, long max, } struct tag * -tag_new_bool(const char *name, bool value) +tag_new_bool(struct module *owner, const char *name, bool value) { struct private *priv = malloc(sizeof(*priv)); priv->name = strdup(name); @@ -249,6 +254,7 @@ tag_new_bool(const char *name, bool value) struct tag *tag = malloc(sizeof(*tag)); tag->private = priv; + tag->owner = owner; tag->destroy = &destroy_int_and_float; tag->name = &tag_name; tag->min = &unimpl_min_max; @@ -262,7 +268,7 @@ tag_new_bool(const char *name, bool value) } struct tag * -tag_new_float(const char *name, double value) +tag_new_float(struct module *owner, const char *name, double value) { struct private *priv = malloc(sizeof(*priv)); priv->name = strdup(name); @@ -270,6 +276,7 @@ tag_new_float(const char *name, double value) struct tag *tag = malloc(sizeof(*tag)); tag->private = priv; + tag->owner = owner; tag->destroy = &destroy_int_and_float; tag->name = &tag_name; tag->min = &unimpl_min_max; @@ -283,7 +290,7 @@ tag_new_float(const char *name, double value) } struct tag * -tag_new_string(const char *name, const char *value) +tag_new_string(struct module *owner, const char *name, const char *value) { struct private *priv = malloc(sizeof(*priv)); priv->name = strdup(name); @@ -291,6 +298,7 @@ tag_new_string(const char *name, const char *value) struct tag *tag = malloc(sizeof(*tag)); tag->private = priv; + tag->owner = owner; tag->destroy = &destroy_string; tag->name = &tag_name; tag->min = &unimpl_min_max; diff --git a/tag.h b/tag.h index 7f22535..cdd4cff 100644 --- a/tag.h +++ b/tag.h @@ -9,8 +9,11 @@ enum tag_realtime_unit { TAG_REALTIME_SECONDS }; +struct module; + struct tag { void *private; + struct module *owner; void (*destroy)(struct tag *tag); const char *(*name)(const struct tag *tag); @@ -29,13 +32,16 @@ struct tag_set { size_t count; }; -struct tag *tag_new_int(const char *name, long value); -struct tag *tag_new_int_range(const char *name, long value, long min, long max); -struct tag *tag_new_int_realtime(const char *name, long value, long min, - long max, enum tag_realtime_unit unit); -struct tag *tag_new_bool(const char *name, bool value); -struct tag *tag_new_float(const char *name, double value); -struct tag *tag_new_string(const char *name, const char *value); +struct tag *tag_new_int(struct module *owner, const char *name, long value); +struct tag *tag_new_int_range( + struct module *owner, const char *name, long value, long min, long max); +struct tag *tag_new_int_realtime( + struct module *owner, const char *name, long value, long min, + long max, enum tag_realtime_unit unit); +struct tag *tag_new_bool(struct module *owner, const char *name, bool value); +struct tag *tag_new_float(struct module *owner, const char *name, double value); +struct tag *tag_new_string( + struct module *owner, const char *name, const char *value); const struct tag *tag_for_name(const struct tag_set *set, const char *name); void tag_set_destroy(struct tag_set *set);