summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--i3status.c3
-rw-r--r--include/i3status.h2
-rw-r--r--man/i3status.man3
-rw-r--r--src/print_battery_info.c7
4 files changed, 12 insertions, 3 deletions
diff --git a/i3status.c b/i3status.c
index 15c58da..e812893 100644
--- a/i3status.c
+++ b/i3status.c
@@ -214,6 +214,7 @@ int main(int argc, char *argv[]) {
cfg_opt_t battery_opts[] = {
CFG_STR("format", "%status %percentage %remaining", CFGF_NONE),
CFG_STR("path", "/sys/class/power_supply/BAT%d/uevent", CFGF_NONE),
+ CFG_INT("threshold", 10, CFGF_NONE),
CFG_BOOL("last_full_capacity", false, CFGF_NONE),
CFG_END()
};
@@ -413,7 +414,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_getbool(sec, "last_full_capacity"));
+ print_battery_info(json_gen, buffer, atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getint(sec, "threshold"), cfg_getbool(sec, "last_full_capacity"));
SEC_CLOSE_MAP;
}
diff --git a/include/i3status.h b/include/i3status.h
index a6d5fc6..eb19d52 100644
--- a/include/i3status.h
+++ b/include/i3status.h
@@ -137,7 +137,7 @@ char *auto_detect_format();
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);
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, bool last_full_capacity);
+void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int threshold, bool last_full_capacity);
void print_time(yajl_gen json_gen, char *buffer, const char *format, struct tm *current_tm);
void print_ddate(yajl_gen json_gen, char *buffer, const char *format, struct tm *current_tm);
const char *get_ip_addr();
diff --git a/man/i3status.man b/man/i3status.man
index 195b648..7f88750 100644
--- a/man/i3status.man
+++ b/man/i3status.man
@@ -72,6 +72,7 @@ ethernet eth0 {
battery 0 {
format = "%status %percentage %remaining %emptytime"
path = "/sys/class/power_supply/BAT%d/uevent"
+ threshold = 10
}
run_watch DHCP {
@@ -207,6 +208,8 @@ with the battery number, but you can just hard-code a path as well.
*Example format*: +%status %remaining (%emptytime)+
+*Example threshold*: +threshold 10+
+
=== CPU-Temperature
Gets the temperature of the given thermal zone.
diff --git a/src/print_battery_info.c b/src/print_battery_info.c
index 1c000e1..cc7c5fe 100644
--- a/src/print_battery_info.c
+++ b/src/print_battery_info.c
@@ -26,7 +26,7 @@
* worn off your battery is.
*
*/
-void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, bool last_full_capacity) {
+void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int threshold, bool last_full_capacity) {
time_t empty_time;
struct tm *empty_tm;
char buf[1024];
@@ -120,6 +120,9 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
minutes = seconds / 60;
seconds -= (minutes * 60);
+ if (threshold > 0 && seconds_remaining < 60 * threshold)
+ START_COLOR("color_bad");
+
(void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d:%02d",
max(hours, 0), max(minutes, 0), max(seconds, 0));
@@ -129,6 +132,8 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
(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));
+
+ END_COLOR;
}
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
int state;