From: Michael Stapelberg Date: Sun, 25 Jan 2009 19:08:57 +0000 (+0100) Subject: Display details also when battery is loaded X-Git-Tag: 1.0~27 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7fe3b0657b8b05db93969e30a1c835aa701e0e92;p=i3%2Fi3status Display details also when battery is loaded --- diff --git a/wmiistatus.c b/wmiistatus.c index be34180..9568821 100644 --- a/wmiistatus.c +++ b/wmiistatus.c @@ -151,7 +151,6 @@ static void setup(void) { 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, ...) { - 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); + } exit(EXIT_FAILURE); } @@ -256,17 +256,13 @@ static char *get_battery_info() { (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); - 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; @@ -275,8 +271,10 @@ static char *get_battery_info() { 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; }