summaryrefslogtreecommitdiff
path: root/slstatus.c
diff options
context:
space:
mode:
authorAaron Marcher <info@nulltime.net>2016-09-13 22:03:36 +0200
committerAaron Marcher (drkhsh) <info@nulltime.net>2016-09-13 22:03:36 +0200
commitf13104156f20c0e394297c56550ff8a948ff1c1a (patch)
treef5f8866f5b7171391cae60ded1f5a47e769af742 /slstatus.c
parent7aad78bd95cb265306f1ab81844c7bcd66054068 (diff)
battery_state() function added
Diffstat (limited to 'slstatus.c')
-rw-r--r--slstatus.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/slstatus.c b/slstatus.c
index fa91cce..1d46674 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -40,6 +40,7 @@ struct arg {
static char *smprintf(const char *, ...);
static char *battery_perc(const char *);
+static char *battery_state(const char *);
static char *cpu_perc(void);
static char *datetime(const char *);
static char *disk_free(const char *);
@@ -114,6 +115,37 @@ battery_perc(const char *battery)
}
static char *
+battery_state(const char *battery)
+{
+ char *state = malloc(sizeof(char)*12);
+ FILE *fp;
+
+ if (!state) {
+ warn("Failed to get battery state.");
+ return smprintf(UNKNOWN_STR);
+ }
+
+
+ ccat(3, "/sys/class/power_supply/", battery, "/status");
+ fp = fopen(concat, "r");
+ if (fp == NULL) {
+ warn("Error opening battery file: %s", concat);
+ return smprintf(UNKNOWN_STR);
+ }
+ fscanf(fp, "%s", state);
+ fclose(fp);
+
+ if (strcmp(state, "Charging") == 0)
+ return smprintf("+");
+ else if (strcmp(state, "Discharging") == 0)
+ return smprintf("-");
+ else if (strcmp(state, "Full") == 0)
+ return smprintf("=");
+ else
+ return smprintf("?");
+}
+
+static char *
cpu_perc(void)
{
int perc;