dotfiles

My beautiful configs and dotfiles managed by Nix' home-manager
Log | Files | Refs | README | LICENSE

slstatus-battery-remaining.diff (890B)


      1 diff --git a/components/battery.c b/components/battery.c
      2 index 1c753f9..942e8a1 100644
      3 --- a/components/battery.c
      4 +++ b/components/battery.c
      5 @@ -111,6 +111,17 @@
      6  
      7  		return "";
      8  	}
      9 +
     10 +  int battery_discharge(const char *bat) {
     11 +    char path[PATH_MAX], state[12];
     12 +
     13 +    if (esnprintf(path, sizeof(path), POWER_SUPPLY_STATUS, bat) < 0)
     14 +      return NULL;
     15 +    if (pscanf(path, "%12[a-zA-Z ]", state) != 1)
     16 +      return NULL;
     17 +
     18 +    return !strcmp(state, "Discharging");
     19 +  }
     20  #elif defined(__OpenBSD__)
     21  	#include <fcntl.h>
     22  	#include <machine/apmvar.h>
     23 diff --git a/slstatus.h b/slstatus.h
     24 index 8ef5874..dacfd98 100644
     25 --- a/slstatus.h
     26 +++ b/slstatus.h
     27 @@ -4,6 +4,7 @@
     28  const char *battery_perc(const char *);
     29  const char *battery_remaining(const char *);
     30  const char *battery_state(const char *);
     31 +int battery_discharge(const char *);
     32  
     33  /* cat */
     34  const char *cat(const char *path);