]> git.sur5r.net Git - i3/i3status/commitdiff
Display details also when battery is loaded
authorMichael Stapelberg <michael+git@stapelberg.de>
Sun, 25 Jan 2009 19:08:57 +0000 (20:08 +0100)
committerMichael Stapelberg <michael+git@stapelberg.de>
Sun, 25 Jan 2009 19:08:57 +0000 (20:08 +0100)
wmiistatus.c

index be3418053aadf75d8e9b64de9d7058e0f0997ee5..9568821a68f26a575a9c5b85a9260a9b22b64d82 100644 (file)
@@ -151,7 +151,6 @@ static void setup(void) {
                snprintf(pathbuf, sizeof(pathbuf), "%s%s", order[ORDER_RUN], run_watches[i]);
                create_file(pathbuf);
        }
                snprintf(pathbuf, sizeof(pathbuf), "%s%s", order[ORDER_RUN], run_watches[i]);
                create_file(pathbuf);
        }
-
 }
 
 /*
 }
 
 /*
@@ -188,14 +187,15 @@ static void write_error_to_statusbar(const char *message) {
  *
  */
 void die(const char *fmt, ...) {
  *
  */
 void die(const char *fmt, ...) {
-       char buffer[512];
-       va_list ap;
-       va_start(ap, fmt);
-       (void)vsnprintf(buffer, sizeof(buffer), fmt, ap);
-       va_end(ap);
+       if (wmii_path != NULL) {
+               char buffer[512];
+               va_list ap;
+               va_start(ap, fmt);
+               (void)vsnprintf(buffer, sizeof(buffer), fmt, ap);
+               va_end(ap);
 
 
-       if (wmii_path != NULL)
                write_error_to_statusbar(buffer);
                write_error_to_statusbar(buffer);
+       }
        exit(EXIT_FAILURE);
 }
 
        exit(EXIT_FAILURE);
 }
 
@@ -256,17 +256,13 @@ static char *get_battery_info() {
        (void)close(fd);
 
        if ((full_design != -1) && (remaining != -1) && (present_rate != -1)) {
        (void)close(fd);
 
        if ((full_design != -1) && (remaining != -1) && (present_rate != -1)) {
-               float remaining_time, perc;
+               float remaining_time;
                int seconds, hours, minutes;
                if (status == CS_CHARGING)
                        remaining_time = ((float)full_design - (float)remaining) / (float)present_rate;
                else if (status == CS_DISCHARGING)
                        remaining_time = ((float)remaining / (float)present_rate);
                int seconds, hours, minutes;
                if (status == CS_CHARGING)
                        remaining_time = ((float)full_design - (float)remaining) / (float)present_rate;
                else if (status == CS_DISCHARGING)
                        remaining_time = ((float)remaining / (float)present_rate);
-               else {
-                       (void)snprintf(part, sizeof(part), "FULL");
-                       return part;
-               }
-               perc = ((float)remaining / (float)full_design);
+               else remaining_time = 0;
 
                seconds = (int)(remaining_time * 3600.0);
                hours = seconds / 3600;
 
                seconds = (int)(remaining_time * 3600.0);
                hours = seconds / 3600;
@@ -275,8 +271,10 @@ static char *get_battery_info() {
                seconds -= (minutes * 60);
 
                (void)snprintf(part, sizeof(part), "%s %.02f%% %02d:%02d:%02d",
                seconds -= (minutes * 60);
 
                (void)snprintf(part, sizeof(part), "%s %.02f%% %02d:%02d:%02d",
-                       (status == CS_CHARGING? "CHR" : "BAT"),
-                       (perc * 100), hours, minutes, seconds);
+                       (status == CS_CHARGING ? "CHR" :
+                        (status == CS_DISCHARGING ? "BAT" : "FULL")),
+                       (((float)remaining / (float)full_design) * 100),
+                       hours, minutes, seconds);
        }
        return part;
 }
        }
        return part;
 }