diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a95f16..e42b0fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ * YAML parsing error messages being replaced with a generic _“unknown error”_. * Memory leak when a YAML parsing error was encountered. +* clock: update every second when necessary + (https://codeberg.org/dnkl/yambar/issues/12). ### Security diff --git a/modules/clock.c b/modules/clock.c index 2ff4f28..6c0cb56 100644 --- a/modules/clock.c +++ b/modules/clock.c @@ -7,6 +7,7 @@ #include #define LOG_MODULE "clock" +#define LOG_ENABLE_DBG 0 #include "../log.h" #include "../bar/bar.h" #include "../config.h" @@ -129,8 +130,32 @@ clock_new(struct particle *label, const char *date_format, const char *time_form m->label = label; m->date_format = strdup(date_format); m->time_format = strdup(time_format); + + static const char *const seconds_formatters[] = { + "%c", + "%s", + "%S", + "%T", + "%r", + "%X", + }; + m->update_granularity = UPDATE_GRANULARITY_MINUTES; + for (size_t i = 0; + i < sizeof(seconds_formatters) / sizeof(seconds_formatters[0]); + i++) + { + if (strstr(time_format, seconds_formatters[i]) != NULL) { + m->update_granularity = UPDATE_GRANULARITY_SECONDS; + break; + } + } + + LOG_DBG("using %s update granularity", + (m->update_granularity == UPDATE_GRANULARITY_MINUTES + ? "minutes" : "seconds")); + struct module *mod = module_common_new(); mod->private = m; mod->run = &run;