Updated battery info to display colors depending on state
Patch status: needinfo
Patch by alfonzo1955
To apply this patch, use:
curl http://cr.i3wm.org/patch/679/raw.patch | git am
b/src/print_battery_info.c
13 |
@@ -172,10 +172,15 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
14 |
START_COLOR("color_bad"); |
15 |
colorful_output = true; |
16 |
} else { |
17 |
- colorful_output = false; |
18 |
+ START_COLOR("color_degraded"); |
19 |
+ colorful_output = true; |
20 |
} |
21 |
+ } else if (status == CS_CHARGING) { |
22 |
+ START_COLOR("color_good"); |
23 |
+ colorful_output = true; |
24 |
} |
25 |
|
26 |
+ |
27 |
if (hide_seconds) |
28 |
(void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d", |
29 |
max(hours, 0), max(minutes, 0)); |
30 |
@@ -205,7 +210,13 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
31 |
&& percentage_remaining < low_threshold) { |
32 |
START_COLOR("color_bad"); |
33 |
colorful_output = true; |
34 |
+ } else { |
35 |
+ START_COLOR("color_degraded"); |
36 |
+ colorful_output = true; |
37 |
} |
38 |
+ } else if (status == CS_CHARGING) { |
39 |
+ START_COLOR("color_good"); |
40 |
+ colorful_output = true; |
41 |
} |
42 |
} |
43 |
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
44 |
@@ -260,7 +271,14 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
45 |
&& remaining < (u_int) low_threshold) { |
46 |
START_COLOR("color_bad"); |
47 |
colorful_output = true; |
48 |
- } |
49 |
+ } else { |
50 |
+ START_COLOR("color_degraded"); |
51 |
+ colorful_output = true; |
52 |
+ } |
53 |
+ |
54 |
+ } else { |
55 |
+ START_COLOR("color_good"); |
56 |
+ colorful_output = true; |
57 |
} |
58 |
#elif defined(__OpenBSD__) |
59 |
/* |
60 |
@@ -314,8 +332,14 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
61 |
&& apm_info.minutes_left < (u_int) low_threshold) { |
62 |
START_COLOR("color_bad"); |
63 |
colorful_output = true; |
64 |
- } |
65 |
- } |
66 |
+ } else { |
67 |
+ START_COLOR("color_degraded"); |
68 |
+ colorful_output = true; |
69 |
+ } |
70 |
+ } else if (status == CS_CHARGING) { |
71 |
+ START_COLOR("color_good"); |
72 |
+ colorful_output = true; |
73 |
+ } |
74 |
|
75 |
/* Can't give a meaningful value for remaining minutes if we're charging. */ |
76 |
if (status != CS_CHARGING) { |
77 |
@@ -517,8 +541,14 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
78 |
&& (((float)remaining / (float)full_design) * 100) < low_threshold) { |
79 |
START_COLOR("color_bad"); |
80 |
colorful_output = true; |
81 |
- } |
82 |
- } |
83 |
+ } else { |
84 |
+ START_COLOR("color_degraded"); |
85 |
+ colorful_output = true; |
86 |
+ } |
87 |
+ } else if (status == CS_CHARGING) { |
88 |
+ START_COLOR("color_good"); |
89 |
+ colorful_output = true; |
90 |
+ } |
91 |
|
92 |
if (is_full) |
93 |
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(CS_FULL)); |
94 |
@@ -559,7 +589,11 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
95 |
&& ((float) seconds_remaining / 60.0) < (u_int) low_threshold) { |
96 |
START_COLOR("color_bad"); |
97 |
colorful_output = true; |
98 |
- } |
99 |
+ } else { |
100 |
+ START_COLOR("color_degraded"); |
101 |
+ colorful_output = true; |
102 |
+ } |
103 |
+ |
104 |
} |
105 |
} else { |
106 |
if (hide_seconds) |
107 |
@@ -568,6 +602,8 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
108 |
else |
109 |
(void)snprintf(remainingbuf, sizeof(remainingbuf), "(%02d:%02d:%02d until full)", |
110 |
max(hours, 0), max(minutes, 0), max(seconds, 0)); |
111 |
+ START_COLOR("color_good"); |
112 |
+ colorful_output = true; |
113 |
} |
114 |
|
115 |
empty_time = time(NULL); |