Add hide_seconds option
Patch status: needinfo
Patch by Iakov Davydov
To apply this patch, use:
curl http://cr.i3wm.org/patch/403/raw.patch | git am
b/i3status.c
16 |
@@ -246,6 +246,7 @@ int main(int argc, char *argv[]) { |
17 |
CFG_STR("threshold_type", "time", CFGF_NONE), |
18 |
CFG_BOOL("last_full_capacity", false, CFGF_NONE), |
19 |
CFG_BOOL("integer_battery_capacity", false, CFGF_NONE), |
20 |
+ CFG_BOOL("hide_seconds", false, CFGF_NONE), |
21 |
CFG_CUSTOM_COLOR_OPTS, |
22 |
CFG_END() |
23 |
}; |
24 |
@@ -480,7 +481,7 @@ int main(int argc, char *argv[]) { |
25 |
|
26 |
CASE_SEC_TITLE("battery") { |
27 |
SEC_OPEN_MAP("battery"); |
28 |
- 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")); |
29 |
+ 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")); |
30 |
SEC_CLOSE_MAP; |
31 |
} |
32 |
|
b/include/i3status.h
37 |
@@ -146,7 +146,7 @@ void set_timezone(const char *tz); |
38 |
|
39 |
void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down); |
40 |
void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *prefix_type); |
41 |
-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); |
42 |
+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); |
43 |
void print_time(yajl_gen json_gen, char *buffer, const char *format, const char *tz, time_t t); |
44 |
void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t); |
45 |
const char *get_ip_addr(); |
b/man/i3status.man
50 |
@@ -251,7 +251,8 @@ estimated to be empty. If you want to use the last full capacity instead of the |
51 |
design capacity (when using the design capacity, it may happen that your |
52 |
battery is at 23% when fully charged because it’s old. In general, I want to |
53 |
see it this way, because it tells me how worn off my battery is.), just specify |
54 |
-+last_full_capacity = true+. |
55 |
++last_full_capacity = true+. You can hide seconds in the remaining time and |
56 |
+empty time estimations by setting +hide_seconds = true+. |
57 |
|
58 |
If you want the battery percentage to be shown without decimals, add |
59 |
+integer_battery_capacity = true+. |
b/src/print_battery_info.c
64 |
@@ -30,7 +30,7 @@ |
65 |
* worn off your battery is. |
66 |
* |
67 |
*/ |
68 |
-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) { |
69 |
+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) { |
70 |
time_t empty_time; |
71 |
struct tm *empty_tm; |
72 |
char buf[1024]; |
73 |
@@ -166,15 +166,23 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char |
74 |
} |
75 |
} |
76 |
|
77 |
- (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d", |
78 |
- max(hours, 0), max(minutes, 0), max(seconds, 0)); |
79 |
+ if (!hide_seconds) |
80 |
+ (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d", |
81 |
+ max(hours, 0), max(minutes, 0), max(seconds, 0)); |
82 |
+ else |
83 |
+ (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d", |
84 |
+ max(hours, 0), max(minutes, 0)); |
85 |
|
86 |
empty_time = time(NULL); |
87 |
empty_time += seconds_remaining; |
88 |
empty_tm = localtime(&empty_time); |
89 |
|
90 |
- (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d:%02d", |
91 |
- max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0)); |
92 |
+ if (!hide_seconds) |
93 |
+ (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d:%02d", |
94 |
+ max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0), max(empty_tm->tm_sec, 0)); |
95 |
+ else |
96 |
+ (void)snprintf(emptytimebuf, sizeof(emptytimebuf), "%02d:%02d", |
97 |
+ max(empty_tm->tm_hour, 0), max(empty_tm->tm_min, 0)); |
98 |
|
99 |
(void)snprintf(consumptionbuf, sizeof(consumptionbuf), "%1.2fW", |
100 |
((float)present_rate / 1000.0 / 1000.0)); |