diff --git a/i3status.c b/i3status.c index 1e8ba58..17fddd7 100644 --- a/i3status.c +++ b/i3status.c @@ -754,7 +754,16 @@ int main(int argc, char *argv[]) { CASE_SEC_TITLE("run_watch") { SEC_OPEN_MAP("run_watch"); - print_run_watch(json_gen, buffer, title, cfg_getstr(sec, "pidfile"), cfg_getstr(sec, "format"), cfg_getstr(sec, "format_down")); + run_watch_ctx_t ctx = { + .json_gen = json_gen, + .buf = buffer, + .buflen = sizeof(buffer), + .title = title, + .pidfile = cfg_getstr(sec, "pidfile"), + .format = cfg_getstr(sec, "format"), + .format_down = cfg_getstr(sec, "format_down"), + }; + print_run_watch(&ctx); SEC_CLOSE_MAP; } diff --git a/include/i3status.h b/include/i3status.h index 2a19938..2da17b3 100644 --- a/include/i3status.h +++ b/include/i3status.h @@ -286,7 +286,18 @@ typedef struct { void print_wireless_info(wireless_info_ctx_t *ctx); -void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format, const char *format_down); +typedef struct { + yajl_gen json_gen; + char *buf; + const size_t buflen; + const char *title; + const char *pidfile; + const char *format; + const char *format_down; +} run_watch_ctx_t; + +void print_run_watch(run_watch_ctx_t *ctx); + void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format, const char *format_down); void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, const char *format_above_threshold, int); void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const char *format_above_threshold, const char *format_above_degraded_threshold, const char *path, const float max_threshold, const float degraded_threshold); diff --git a/src/print_run_watch.c b/src/print_run_watch.c index ccc7206..de58019 100644 --- a/src/print_run_watch.c +++ b/src/print_run_watch.c @@ -9,18 +9,19 @@ #define STRING_SIZE 5 -void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format, const char *format_down) { - bool running = process_runs(pidfile); +void print_run_watch(run_watch_ctx_t *ctx) { + bool running = process_runs(ctx->pidfile); const char *walk; - char *outwalk = buffer; + char *outwalk = ctx->buf; +#define json_gen ctx->json_gen - if (running || format_down == NULL) { - walk = format; + if (running || ctx->format_down == NULL) { + walk = ctx->format; } else { - walk = format_down; + walk = ctx->format_down; } - INSTANCE(pidfile); + INSTANCE(ctx->pidfile); START_COLOR((running ? "color_good" : "color_bad")); @@ -28,13 +29,12 @@ void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const c snprintf(string_status, STRING_SIZE, "%s", (running ? "yes" : "no")); placeholder_t placeholders[] = { - {.name = "%title", .value = title}, + {.name = "%title", .value = ctx->title}, {.name = "%status", .value = string_status}}; const size_t num = sizeof(placeholders) / sizeof(placeholder_t); - buffer = format_placeholders(walk, &placeholders[0], num); - + char *formatted = format_placeholders(walk, &placeholders[0], num); + OUTPUT_FORMATTED; END_COLOR; - OUTPUT_FULL_TEXT(buffer); - free(buffer); + OUTPUT_FULL_TEXT(ctx->buf); }