]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_battery_info.c
use stdbool instead of (int)1 and (int)0 directly
[i3/i3status] / src / print_battery_info.c
index 68785403c953322a31825456020c6b21ec9c34cd..1545609ea5cdd25b0757a35635d9ebfb7c67c603 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "i3status.h"
 
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #endif
@@ -157,6 +157,8 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
                                 && seconds_remaining < 60 * low_threshold) {
                                 START_COLOR("color_bad");
                                 colorful_output = true;
+                        } else {
+                            colorful_output = false;
                         }
                 }
 
@@ -172,11 +174,19 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
 
                 (void)snprintf(consumptionbuf, sizeof(consumptionbuf), "%1.2fW",
                         ((float)present_rate / 1000.0 / 1000.0));
-
-                if (colorful_output)
-                    END_COLOR;
+        } else {
+                /* On some systems, present_rate may not exist. Still, make sure
+                 * we colorize the output if threshold_type is set to percentage
+                 * (since we don't have any information on remaining time). */
+                if (status == CS_DISCHARGING && low_threshold > 0) {
+                        if (strncmp(threshold_type, "percentage", strlen(threshold_type)) == 0
+                                && percentage_remaining < low_threshold) {
+                                START_COLOR("color_bad");
+                                colorful_output = true;
+                        }
+                }
         }
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
         int state;
         int sysctl_rslt;
         size_t sysctl_size = sizeof(sysctl_rslt);
@@ -323,5 +333,8 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
                 }
         }
 
+        if (colorful_output)
+                END_COLOR;
+
         OUTPUT_FULL_TEXT(buffer);
 }