]> git.sur5r.net Git - i3/i3status/commitdiff
add good, degraded and bad colors per module
authorMarcelo Cerri <mhcerri@gmail.com>
Thu, 18 Oct 2012 20:55:41 +0000 (17:55 -0300)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 24 Oct 2012 16:59:46 +0000 (18:59 +0200)
This commit adds support for color_good, color_degraded and color_bad
directives per module section in the config file.

i3status.c
include/i3status.h
man/i3status.man

index 5d3153cea5c97731ba5f61436e34ee0ec1df21db..0037fbc7856f0bc1b90c030ed107dffaa5b6055f 100644 (file)
 
 #define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); }
 
 
 #define exit_if_null(pointer, ...) { if (pointer == NULL) die(__VA_ARGS__); }
 
+#define CFG_COLOR_OPTS(good, degraded, bad) \
+    CFG_STR("color_good", good, CFGF_NONE), \
+    CFG_STR("color_degraded", degraded, CFGF_NONE), \
+    CFG_STR("color_bad", bad, CFGF_NONE)
+
+#define CFG_CUSTOM_COLOR_OPTS CFG_COLOR_OPTS(NULL, NULL, NULL)
+
 /* socket file descriptor for general purposes */
 int general_socket;
 
 /* socket file descriptor for general purposes */
 int general_socket;
 
-cfg_t *cfg, *cfg_general;
+cfg_t *cfg, *cfg_general, *cfg_section;
 
 /*
  * Exit upon SIGPIPE because when we have nowhere to write to, gathering
 
 /*
  * Exit upon SIGPIPE because when we have nowhere to write to, gathering
@@ -179,35 +186,37 @@ int main(int argc, char *argv[]) {
         cfg_opt_t general_opts[] = {
                 CFG_STR("output_format", "auto", CFGF_NONE),
                 CFG_BOOL("colors", 1, CFGF_NONE),
         cfg_opt_t general_opts[] = {
                 CFG_STR("output_format", "auto", CFGF_NONE),
                 CFG_BOOL("colors", 1, CFGF_NONE),
-                CFG_STR("color_good", "#00FF00", CFGF_NONE),
-                CFG_STR("color_degraded", "#FFFF00", CFGF_NONE),
-                CFG_STR("color_bad", "#FF0000", CFGF_NONE),
                 CFG_STR("color_separator", "#333333", CFGF_NONE),
                 CFG_INT("interval", 1, CFGF_NONE),
                 CFG_STR("color_separator", "#333333", CFGF_NONE),
                 CFG_INT("interval", 1, CFGF_NONE),
+                CFG_COLOR_OPTS("#00FF00", "#FFFF00", "#FF0000"),
                 CFG_END()
         };
 
         cfg_opt_t run_watch_opts[] = {
                 CFG_STR("pidfile", NULL, CFGF_NONE),
                 CFG_STR("format", "%title: %status", CFGF_NONE),
                 CFG_END()
         };
 
         cfg_opt_t run_watch_opts[] = {
                 CFG_STR("pidfile", NULL, CFGF_NONE),
                 CFG_STR("format", "%title: %status", CFGF_NONE),
+                CFG_CUSTOM_COLOR_OPTS,
                 CFG_END()
         };
 
         cfg_opt_t wireless_opts[] = {
                 CFG_STR("format_up", "W: (%quality at %essid, %bitrate) %ip", CFGF_NONE),
                 CFG_STR("format_down", "W: down", CFGF_NONE),
                 CFG_END()
         };
 
         cfg_opt_t wireless_opts[] = {
                 CFG_STR("format_up", "W: (%quality at %essid, %bitrate) %ip", CFGF_NONE),
                 CFG_STR("format_down", "W: down", CFGF_NONE),
+                CFG_CUSTOM_COLOR_OPTS,
                 CFG_END()
         };
 
         cfg_opt_t ethernet_opts[] = {
                 CFG_STR("format_up", "E: %ip (%speed)", CFGF_NONE),
                 CFG_STR("format_down", "E: down", CFGF_NONE),
                 CFG_END()
         };
 
         cfg_opt_t ethernet_opts[] = {
                 CFG_STR("format_up", "E: %ip (%speed)", CFGF_NONE),
                 CFG_STR("format_down", "E: down", CFGF_NONE),
+                CFG_CUSTOM_COLOR_OPTS,
                 CFG_END()
         };
 
         cfg_opt_t ipv6_opts[] = {
                 CFG_STR("format_up", "%ip", CFGF_NONE),
                 CFG_STR("format_down", "no IPv6", CFGF_NONE),
                 CFG_END()
         };
 
         cfg_opt_t ipv6_opts[] = {
                 CFG_STR("format_up", "%ip", CFGF_NONE),
                 CFG_STR("format_down", "no IPv6", CFGF_NONE),
+                CFG_CUSTOM_COLOR_OPTS,
                 CFG_END()
         };
 
                 CFG_END()
         };
 
@@ -257,6 +266,7 @@ int main(int argc, char *argv[]) {
                 CFG_STR("device", "default", CFGF_NONE),
                 CFG_STR("mixer", "Master", CFGF_NONE),
                 CFG_INT("mixer_idx", 0, CFGF_NONE),
                 CFG_STR("device", "default", CFGF_NONE),
                 CFG_STR("mixer", "Master", CFGF_NONE),
                 CFG_INT("mixer_idx", 0, CFGF_NONE),
+                CFG_CUSTOM_COLOR_OPTS,
                 CFG_END()
         };
 
                 CFG_END()
         };
 
@@ -275,6 +285,7 @@ int main(int argc, char *argv[]) {
                 CFG_SEC("ddate", ddate_opts, CFGF_NONE),
                 CFG_SEC("load", load_opts, CFGF_NONE),
                 CFG_SEC("cpu_usage", usage_opts, CFGF_NONE),
                 CFG_SEC("ddate", ddate_opts, CFGF_NONE),
                 CFG_SEC("load", load_opts, CFGF_NONE),
                 CFG_SEC("cpu_usage", usage_opts, CFGF_NONE),
+                CFG_CUSTOM_COLOR_OPTS,
                 CFG_END()
         };
 
                 CFG_END()
         };
 
index fc984f8c9ac9a13d8936e21179c955b63289fc2d..559df9e2cdd213c44afdc6ae13d74eecff213fff 100644 (file)
@@ -45,13 +45,13 @@ enum { O_DZEN2, O_XMOBAR, O_I3BAR, O_NONE } output_format;
 
 #define CASE_SEC(name) \
         if (BEGINS_WITH(current, name)) \
 
 #define CASE_SEC(name) \
         if (BEGINS_WITH(current, name)) \
-                with(cfg_t *, sec, cfg_getsec(cfg, name)) \
+                with(cfg_t *, sec, cfg_section = cfg_getsec(cfg, name)) \
                         if (sec != NULL)
 
 #define CASE_SEC_TITLE(name) \
         if (BEGINS_WITH(current, name)) \
                 with(const char *, title, current + strlen(name) + 1) \
                         if (sec != NULL)
 
 #define CASE_SEC_TITLE(name) \
         if (BEGINS_WITH(current, name)) \
                 with(const char *, title, current + strlen(name) + 1) \
-                        with(cfg_t *, sec, cfg_gettsec(cfg, name, title)) \
+                        with(cfg_t *, sec, cfg_section = cfg_gettsec(cfg, name, title)) \
                                 if (sec != NULL)
 
 /* Macro which any plugin can use to output the full_text part (when the output
                                 if (sec != NULL)
 
 /* Macro which any plugin can use to output the full_text part (when the output
@@ -88,7 +88,11 @@ enum { O_DZEN2, O_XMOBAR, O_I3BAR, O_NONE } output_format;
 #define START_COLOR(colorstr) \
        do { \
                if (cfg_getbool(cfg_general, "colors")) { \
 #define START_COLOR(colorstr) \
        do { \
                if (cfg_getbool(cfg_general, "colors")) { \
-                       const char *_val = cfg_getstr(cfg_general, colorstr); \
+                       const char *_val = NULL; \
+                       if (cfg_section) \
+                               _val = cfg_getstr(cfg_section, colorstr); \
+                       if (!_val) \
+                               _val = cfg_getstr(cfg_general, colorstr); \
                        if (output_format == O_I3BAR) { \
                                yajl_gen_string(json_gen, (const unsigned char *)"color", strlen("color")); \
                                yajl_gen_string(json_gen, (const unsigned char *)_val, strlen(_val)); \
                        if (output_format == O_I3BAR) { \
                                yajl_gen_string(json_gen, (const unsigned char *)"color", strlen("color")); \
                                yajl_gen_string(json_gen, (const unsigned char *)_val, strlen(_val)); \
@@ -147,6 +151,6 @@ bool process_runs(const char *path);
 /* socket file descriptor for general purposes */
 extern int general_socket;
 
 /* socket file descriptor for general purposes */
 extern int general_socket;
 
-extern cfg_t *cfg, *cfg_general;
+extern cfg_t *cfg, *cfg_general, *cfg_section;
 
 #endif
 
 #endif
index 0d98f8f8ba4750750008352f31d139d9bb364e4d..c14d8d2457ab97bf6d94a17ccf05433438d15492 100644 (file)
@@ -143,6 +143,11 @@ none::
 Does not use any color codes. Separates values by the pipe symbol. This should
 be used with i3bar and can be used for custom scripts.
 
 Does not use any color codes. Separates values by the pipe symbol. This should
 be used with i3bar and can be used for custom scripts.
 
+It's also possible to use the color_good, color_degraded, color_bad directives
+to define specific colors per module. If one of these directives is defined
+in a module section its value will override the value defined in the general
+section just for this module.
+
 === IPv6
 
 This module gets the IPv6 address used for outgoing connections (that is, the
 === IPv6
 
 This module gets the IPv6 address used for outgoing connections (that is, the