Added option to show battery capacity without decimals
Patch status: rejected
Patch by Julien Lequertier
To apply this patch, use:
curl http://cr.i3wm.org/patch/39/raw.patch | git am
b/i3status.c
16 |
@@ -234,6 +234,7 @@ int main(int argc, char *argv[]) { |
17 |
CFG_INT("low_threshold", 30, CFGF_NONE), |
18 |
CFG_STR("threshold_type", "time", CFGF_NONE), |
19 |
CFG_BOOL("last_full_capacity", false, CFGF_NONE), |
20 |
+ CFG_BOOL("integer_battery_capacity", false, CFGF_NONE), |
21 |
CFG_CUSTOM_COLOR_OPTS, |
22 |
CFG_END() |
23 |
}; |
24 |
@@ -441,7 +442,7 @@ int main(int argc, char *argv[]) { |
25 |
|
26 |
CASE_SEC_TITLE("battery") { |
27 |
SEC_OPEN_MAP("battery"); |
28 |
- print_battery_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getint(sec, "low_threshold"), cfg_getstr(sec, "threshold_type"), cfg_getbool(sec, "last_full_capacity")); |
29 |
+ print_battery_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getint(sec, "low_threshold"), cfg_getstr(sec, "threshold_type"), cfg_getbool(sec, "last_full_capacity"), cfg_getbool(sec, "integer_battery_capacity")); |
30 |
SEC_CLOSE_MAP; |
31 |
} |
32 |
|
b/include/i3status.h
37 |
@@ -139,7 +139,7 @@ char *auto_detect_format(); |
38 |
|
39 |
void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down); |
40 |
void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format); |
41 |
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity); |
42 |
+void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity); |
43 |
void print_time(yajl_gen json_gen, char *buffer, const char *format, struct tm *current_tm); |
44 |
void print_ddate(yajl_gen json_gen, char *buffer, const char *format, struct tm *current_tm); |
45 |
const char *get_ip_addr(); |
b/man/i3status.man
50 |
@@ -210,6 +210,9 @@ battery is at 23% when fully charged because it’s old. In general, I want to |
51 |
see it this way, because it tells me how worn off my battery is.), just specify |
52 |
+last_full_capacity = true+. |
53 |
|
54 |
+If you want the battery percentage to be shown without decimals, add |
55 |
++integer_battery_capacity = true+. |
56 |
+ |
57 |
If your battery is represented in a non-standard path in /sys, be sure to |
58 |
modify the "path" property accordingly. The first occurence of %d gets replaced |
59 |
with the battery number, but you can just hard-code a path as well. |
b/src/print_battery_info.c
64 |
@@ -30,7 +30,7 @@ |
65 |
* worn off your battery is. |
66 |
* |
67 |
*/ |
68 |
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity) { |
69 |
+void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity) { |
70 |
time_t empty_time; |
71 |
struct tm *empty_tm; |
72 |
char buf[1024]; |
73 |
@@ -130,7 +130,11 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
74 |
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status)); |
75 |
|
76 |
float percentage_remaining = (((float)remaining / (float)full_design) * 100); |
77 |
- (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining); |
78 |
+ if (integer_battery_capacity) { |
79 |
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%%", percentage_remaining); |
80 |
+ } else { |
81 |
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining); |
82 |
+ } |
83 |
|
84 |
if (present_rate > 0) { |
85 |
float remaining_time; |
86 |
@@ -229,7 +233,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
87 |
hours = minutes / 60; |
88 |
minutes -= (hours * 60); |
89 |
(void)snprintf(remainingbuf, sizeof(remainingbuf), "%02dh%02d", |
90 |
- max(hours, 0), max(minutes, 0)); |
91 |
+ max(hours, 0), max(minutes, 0)); |
92 |
} |
93 |
#elif defined(__OpenBSD__) |
94 |
/* |