]> git.sur5r.net Git - i3/i3status/commitdiff
battery: implement "path" option for batteries with non-standard paths
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 26 Nov 2011 18:26:38 +0000 (18:26 +0000)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 26 Nov 2011 18:26:38 +0000 (18:26 +0000)
i3status.c
include/i3status.h
man/i3status.man
src/print_battery_info.c

index 523ba7ebd10d174e87edd6bd9bb3426890184820..9f04850513b9a5a3d5420aa811f04de328c413b0 100644 (file)
@@ -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"));
index 125ca557f97850b9e3aff84210af4aa87d793ff7..a54208f86bfb2ed039117a1de999aa5bda8f0c2a 100644 (file)
@@ -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();
index 0666230a87d145f9338a9d23cba563a5227a6511..a15de86cb328fbef045d0934816b09364e3e3d0d 100644 (file)
@@ -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+
index 36de3c842021d9805f902fe21ecbc02810c56720..6ee89896cfed8c0e226e7a9bb77dcc2e19bc354d 100644 (file)
@@ -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;