From 36d0203dc92a6fa8fdd5b2d83027ecd1b10e9045 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Tue, 6 Sep 2022 23:44:38 +0800 Subject: [PATCH] cpu_temperature: support format_down With this, users are able to create portable config by, for example, two cpu_temperature for coretemp and k10temp with format_down="". --- i3status.c | 2 ++ include/i3status.h | 1 + man/i3status.man | 3 ++- src/print_cpu_temperature.c | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/i3status.c b/i3status.c index 88fb90e0..a38cc9b3 100644 --- a/i3status.c +++ b/i3status.c @@ -406,6 +406,7 @@ int main(int argc, char *argv[]) { cfg_opt_t temp_opts[] = { CFG_STR("format", "%degrees C", CFGF_NONE), CFG_STR("format_above_threshold", NULL, CFGF_NONE), + CFG_STR("format_down", "can't read temp", CFGF_NONE), CFG_STR("path", NULL, CFGF_NONE), CFG_INT("max_threshold", 75, CFGF_NONE), CFG_CUSTOM_ALIGN_OPT, @@ -907,6 +908,7 @@ int main(int argc, char *argv[]) { .path = cfg_getstr(sec, "path"), .format = cfg_getstr(sec, "format"), .format_above_threshold = cfg_getstr(sec, "format_above_threshold"), + .format_down = cfg_getstr(sec, "format_down"), .max_threshold = cfg_getint(sec, "max_threshold"), }; print_cpu_temperature_info(&ctx); diff --git a/include/i3status.h b/include/i3status.h index fe44780b..2d80920d 100644 --- a/include/i3status.h +++ b/include/i3status.h @@ -354,6 +354,7 @@ typedef struct { const char *path; const char *format; const char *format_above_threshold; + const char *format_down; int max_threshold; } cpu_temperature_ctx_t; diff --git a/man/i3status.man b/man/i3status.man index 36e1a6e7..7980f1e6 100644 --- a/man/i3status.man +++ b/man/i3status.man @@ -421,7 +421,8 @@ Gets the temperature of the given thermal zone. It is possible to define a +max_threshold+ that will color the temperature red in case the specified thermal zone is getting too hot. Defaults to 75 degrees C. The output format when above +max_threshold+ can be customized with -+format_above_threshold+. ++format_above_threshold+. There also is an option +format_down+. You can hide +the output with +format_down=""+. *Example order*: +cpu_temperature 0+ diff --git a/src/print_cpu_temperature.c b/src/print_cpu_temperature.c index 9c9bbf0e..82e8488e 100644 --- a/src/print_cpu_temperature.c +++ b/src/print_cpu_temperature.c @@ -272,6 +272,6 @@ void print_cpu_temperature_info(cpu_temperature_ctx_t *ctx) { free(thermal_zone); #endif - OUTPUT_FULL_TEXT("can't read temp"); + OUTPUT_FULL_TEXT(ctx->format_down); (void)fputs("i3status: Cannot read temperature. Verify that you have a thermal zone in /sys/class/thermal or disable the cpu_temperature module in your i3status config.\n", stderr); }