]> git.sur5r.net Git - i3/i3status/commitdiff
Added option to show battery capacity without decimals
authorJulien Lequertier <git@avrelaun.com>
Sun, 10 Feb 2013 16:59:37 +0000 (17:59 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Thu, 14 Feb 2013 18:35:15 +0000 (19:35 +0100)
i3status.c
include/i3status.h
man/i3status.man
src/print_battery_info.c

index c1f6039b51c02c074cdd911a4f263ce345ceba77..3fe3f477b88036044512837fec8db945749212ab 100644 (file)
@@ -234,6 +234,7 @@ int main(int argc, char *argv[]) {
                 CFG_INT("low_threshold", 30, CFGF_NONE),
                 CFG_STR("threshold_type", "time", CFGF_NONE),
                 CFG_BOOL("last_full_capacity", false, CFGF_NONE),
+                CFG_BOOL("integer_battery_capacity", false, CFGF_NONE),
                 CFG_CUSTOM_COLOR_OPTS,
                 CFG_END()
         };
@@ -441,7 +442,7 @@ int main(int argc, char *argv[]) {
 
                         CASE_SEC_TITLE("battery") {
                                 SEC_OPEN_MAP("battery");
-                                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"));
+                                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"));
                                 SEC_CLOSE_MAP;
                         }
 
index f24fec5b21a31a03fa0efddab99b42288308aa5c..de8373f3c3a2c5df6c22c53426cbeff1bb620c24 100644 (file)
@@ -142,7 +142,7 @@ void set_timezone(const char *tz);
 
 void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down);
 void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format);
-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);
+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);
 void print_time(yajl_gen json_gen, char *buffer, const char *format, const char *tz, time_t t);
 void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t);
 const char *get_ip_addr();
index d7803638aac91aeaabc47b1e6dbaa0ed739c40d7..0f8099169acf1359db60daa48c6a2195e065ec81 100644 (file)
@@ -216,6 +216,9 @@ battery is at 23% when fully charged because it’s old. In general, I want to
 see it this way, because it tells me how worn off my battery is.), just specify
 +last_full_capacity = true+.
 
+If you want the battery percentage to be shown without decimals, add
++integer_battery_capacity = true+.
+
 If your battery is represented in a non-standard path in /sys, be sure to
 modify the "path" property accordingly. The first occurence of %d gets replaced
 with the battery number, but you can just hard-code a path as well.
index 1545609ea5cdd25b0757a35635d9ebfb7c67c603..d4b091b2e7b4b1f8187969bc87508be39af2299c 100644 (file)
@@ -30,7 +30,7 @@
  * worn off your battery is.
  *
  */
-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) {
+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) {
         time_t empty_time;
         struct tm *empty_tm;
         char buf[1024];
@@ -130,7 +130,11 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
         (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
 
         float percentage_remaining = (((float)remaining / (float)full_design) * 100);
-        (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining);
+        if (integer_battery_capacity) {
+                (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%%", percentage_remaining);
+        } else {
+                (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining);
+        }
 
         if (present_rate > 0) {
                 float remaining_time;