]> git.sur5r.net Git - i3/i3status/commitdiff
Add hide_seconds option
authorIakov Davydov <davydov@xkcd.ru>
Wed, 5 Feb 2014 10:12:47 +0000 (11:12 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 8 Feb 2014 19:36:59 +0000 (20:36 +0100)
fixes: #1134

i3status.c
include/i3status.h
man/i3status.man
src/print_battery_info.c

index b35937016e1a8290ec9394921ebcd296bb21fac5..09379e69b7405b9eddbf5a510660f6fcadd6f337 100644 (file)
@@ -246,6 +246,7 @@ int main(int argc, char *argv[]) {
                 CFG_STR("threshold_type", "time", CFGF_NONE),
                 CFG_BOOL("last_full_capacity", false, CFGF_NONE),
                 CFG_BOOL("integer_battery_capacity", false, CFGF_NONE),
+                CFG_BOOL("hide_seconds", false, CFGF_NONE),
                 CFG_CUSTOM_COLOR_OPTS,
                 CFG_END()
         };
@@ -480,7 +481,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_getstr(sec, "format_down"), cfg_getint(sec, "low_threshold"), cfg_getstr(sec, "threshold_type"), cfg_getbool(sec, "last_full_capacity"), cfg_getbool(sec, "integer_battery_capacity"));
+                                print_battery_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getstr(sec, "format_down"), cfg_getint(sec, "low_threshold"), cfg_getstr(sec, "threshold_type"), cfg_getbool(sec, "last_full_capacity"), cfg_getbool(sec, "integer_battery_capacity"), cfg_getbool(sec, "hide_seconds"));
                                 SEC_CLOSE_MAP;
                         }
 
index 5ab310baccd0e4d901ebe1ebd02fa94a348fcffa..e1246b90c01e54ef343e8c5f8b3ebba107729d51 100644 (file)
@@ -146,7 +146,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, const char *prefix_type);
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity);
+void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds);
 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 c36694a49ee59abab033969595acfd4105e81dc6..614e22ce91a6573ab72a714b51abfb76ad0ac7f4 100644 (file)
@@ -251,7 +251,8 @@ estimated to be empty. If you want to use the last full capacity instead of the
 design capacity (when using the design capacity, it may happen that your
 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+.
++last_full_capacity = true+. You can hide seconds in the remaining time and
+empty time estimations by setting +hide_seconds = true+.
 
 If you want the battery percentage to be shown without decimals, add
 +integer_battery_capacity = true+.
index 03bacdf98dde58188797b11b3f9f708f20971ef1..bd3ff5c63de754928a2c255a8fde0fc01954c49a 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, const char *format_down, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity) {
+void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds) {
         time_t empty_time;
         struct tm *empty_tm;
         char buf[1024];
@@ -166,15 +166,23 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
                         }
                 }
 
-                (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d",
-                        max(hours, 0), max(minutes, 0), max(seconds, 0));
+                if (hide_seconds)
+                        (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d",
+                                max(hours, 0), max(minutes, 0));
+                else
+                        (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d",
+                                max(hours, 0), max(minutes, 0), max(seconds, 0));
 
                 empty_time = time(NULL);
                 empty_time += seconds_remaining;
                 empty_tm = localtime(&empty_time);
 
-                (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d:%02d",
-                        max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0));
+                if (hide_seconds)
+                        (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d",
+                                max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0));
+                else
+                        (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d:%02d",
+                                max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0));
 
                 (void)snprintf(consumptionbuf, sizeof(consumptionbuf), "%1.2fW",
                         ((float)present_rate / 1000.0 / 1000.0));