Added option to show battery capacity without decimals
Patch status: merged
Patch by Julien Lequertier
To apply this patch, use:
curl http://cr.i3wm.org/patch/43/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 |
@@ -142,7 +142,7 @@ void set_timezone(const char *tz); |
| 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, const char *tz, time_t t); |
| 44 |
void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t); |
| 45 |
const char *get_ip_addr(); |
b/man/i3status.man
| 50 |
@@ -216,6 +216,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; |