From 3471ff39f865a450444774237c435bceaaac1c01 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 26 Nov 2011 18:26:38 +0000 Subject: [PATCH] battery: implement "path" option for batteries with non-standard paths --- i3status.c | 3 ++- include/i3status.h | 2 +- man/i3status.man | 5 +++++ src/print_battery_info.c | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/i3status.c b/i3status.c index 523ba7e..9f04850 100644 --- a/i3status.c +++ b/i3status.c @@ -209,6 +209,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_BOOL("last_full_capacity", false, CFGF_NONE), CFG_END() }; @@ -371,7 +372,7 @@ int main(int argc, char *argv[]) { print_eth_info(title, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down")); CASE_SEC_TITLE("battery") - print_battery_info(atoi(title), cfg_getstr(sec, "format"), cfg_getbool(sec, "last_full_capacity")); + print_battery_info(atoi(title), cfg_getstr(sec, "path"), cfg_getstr(sec, "format"), cfg_getbool(sec, "last_full_capacity")); CASE_SEC_TITLE("run_watch") print_run_watch(title, cfg_getstr(sec, "pidfile"), cfg_getstr(sec, "format")); diff --git a/include/i3status.h b/include/i3status.h index 125ca55..a54208f 100644 --- a/include/i3status.h +++ b/include/i3status.h @@ -64,7 +64,7 @@ char *auto_detect_format(); void print_ipv6_info(const char *format_up, const char *format_down); void print_disk_info(const char *path, const char *format); -void print_battery_info(int number, const char *format, bool last_full_capacity); +void print_battery_info(int number, const char *path, const char *format, bool last_full_capacity); void print_time(const char *format, struct tm *current_tm); void print_ddate(const char *format, struct tm *current_tm); const char *get_ip_addr(); diff --git a/man/i3status.man b/man/i3status.man index 0666230..a15de86 100644 --- a/man/i3status.man +++ b/man/i3status.man @@ -75,6 +75,7 @@ ethernet eth0 { battery 0 { format = "%status %percentage %remaining" + path = "/sys/class/power_supply/BAT%d/uevent" } run_watch DHCP { @@ -193,6 +194,10 @@ 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+. +If your battery is represented in a non-standard path in /sys, be sure to +modify the "path" property accordingly. The first occurence of %d gets replaced +with the battery number, but you can just hard-code a path as well. + *Example order*: +battery 0+ *Example format*: +%status %remaining+ diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 36de3c8..6ee8989 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -17,7 +17,7 @@ * worn off your battery is. * */ -void print_battery_info(int number, const char *format, bool last_full_capacity) { +void print_battery_info(int number, const char *path, const char *format, bool last_full_capacity) { time_t empty_time; struct tm *empty_tm; char buf[1024]; @@ -38,7 +38,7 @@ void print_battery_info(int number, const char *format, bool last_full_capacity) #if defined(LINUX) static char batpath[512]; - sprintf(batpath, "/sys/class/power_supply/BAT%d/uevent", number); + sprintf(batpath, path, number); if (!slurp(batpath, buf, sizeof(buf))) { printf("No battery"); return; -- 2.39.5