]> git.sur5r.net Git - i3/i3status/commitdiff
battery: split up %remaining into %percentage and %remaining (Thanks shatter)
authorMichael Stapelberg <michael@stapelberg.de>
Fri, 16 Oct 2009 20:21:05 +0000 (22:21 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Fri, 16 Oct 2009 20:21:05 +0000 (22:21 +0200)
i3status.c
i3status.conf
man/i3status.man
src/print_battery_info.c

index c9ded2f9b2043df71cb9a37bd5778a26fe352fb1..67b86ddbf5e17ddcf06475a02d552276b9bece29 100644 (file)
@@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {
         };
 
         cfg_opt_t battery_opts[] = {
-                CFG_STR("format", "%status %remaining", CFGF_NONE),
+                CFG_STR("format", "%status %percentage %remaining", CFGF_NONE),
                 CFG_BOOL("last_full_capacity", false, CFGF_NONE),
                 CFG_END()
         };
index 2c5f276d50aa5425958dcad6c23bbf9f9b98ae03..1e120cf6ac34b1b9a624e489c61c97df7ffb3add 100644 (file)
@@ -26,7 +26,7 @@ ethernet eth0 {
 }
 
 battery 0 {
-        format = "%status %remaining"
+        format = "%status %percentage %remaining"
 }
 
 run_watch DHCP {
index eb16bf6434628fa1affead33204da0e0c01fe5b5..cf3e2b2c9ae3af973fac7f59ac34862b2ba3b29e 100644 (file)
@@ -66,7 +66,7 @@ ethernet eth0 {
 }
 
 battery 0 {
-        format = "%status %remaining"
+        format = "%status %percentage %remaining"
 }
 
 run_watch DHCP {
index c4b15b1864abba806c09f013855bcffc32e87a1d..aec6deec9c5aeaafbdaafb2906842f14dbecd68d 100644 (file)
@@ -19,6 +19,7 @@
 void print_battery_info(int number, const char *format, bool last_full_capacity) {
         char buf[1024];
         char statusbuf[16];
+        char percentagebuf[16];
         char remainingbuf[256];
         const char *walk, *last;
         int full_design = -1,
@@ -27,6 +28,7 @@ void print_battery_info(int number, const char *format, bool last_full_capacity)
         charging_status_t status = CS_DISCHARGING;
 
         memset(statusbuf, '\0', sizeof(statusbuf));
+        memset(percentagebuf, '\0', sizeof(percentagebuf));
         memset(remainingbuf, '\0', sizeof(remainingbuf));
 
 #if defined(LINUX)
@@ -78,6 +80,9 @@ void print_battery_info(int number, const char *format, bool last_full_capacity)
                         (status == CS_CHARGING ? "CHR" :
                          (status == CS_DISCHARGING ? "BAT" : "FULL")));
 
+        (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%",
+                       (((float)remaining / (float)full_design) * 100));
+
         if (present_rate > 0) {
                 float remaining_time;
                 int seconds, hours, minutes;
@@ -93,11 +98,8 @@ void print_battery_info(int number, const char *format, bool last_full_capacity)
                 minutes = seconds / 60;
                 seconds -= (minutes * 60);
 
-                (void)snprintf(remainingbuf, sizeof(remainingbuf), "%.02f%% %02d:%02d:%02d",
-                        (((float)remaining / (float)full_design) * 100),
+                (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d",
                         max(hours, 0), max(minutes, 0), max(seconds, 0));
-        } else {
-                (void)snprintf(remainingbuf, sizeof(remainingbuf), "%.02f%%", (((float)remaining / (float)full_design) * 100));
         }
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
         int state;
@@ -135,17 +137,16 @@ void print_battery_info(int number, const char *format, bool last_full_capacity)
                         (status == CS_CHARGING ? "CHR" :
                          (status == CS_DISCHARGING ? "BAT" : "FULL")));
 
+        (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%%",
+                       present_rate);
+
         if (state == 1) {
                 int hours, minutes;
                 minutes = remaining;
                 hours = minutes / 60;
                 minutes -= (hours * 60);
-                (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d%% %02dh%02d",
-                               present_rate,
+                (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02dh%02d",
                                max(hours, 0), max(minutes, 0));
-        } else {
-                (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d%%",
-                               present_rate);
         }
 #endif
 
@@ -158,6 +159,9 @@ void print_battery_info(int number, const char *format, bool last_full_capacity)
                 if (strncmp(walk+1, "status", strlen("status")) == 0) {
                         printf("%s", statusbuf);
                         walk += strlen("status");
+                } else if (strncmp(walk+1, "percentage", strlen("percentage")) == 0) {
+                        printf("%s", percentagebuf);
+                        walk += strlen("percentage");
                 } else if (strncmp(walk+1, "remaining", strlen("remaining")) == 0) {
                         printf("%s", remainingbuf);
                         walk += strlen("remaining");