Change battery status
This commit is contained in:
parent
cb3381f687
commit
763cfb7384
15
dwmstatus.c
15
dwmstatus.c
@ -116,8 +116,9 @@ readfile(char *base, char *file)
|
|||||||
char *
|
char *
|
||||||
getbattery(char *base)
|
getbattery(char *base)
|
||||||
{
|
{
|
||||||
char *co, status;
|
char *co;
|
||||||
int descap, remcap;
|
char *status;
|
||||||
|
int descap, remcap;
|
||||||
|
|
||||||
descap = -1;
|
descap = -1;
|
||||||
remcap = -1;
|
remcap = -1;
|
||||||
@ -151,17 +152,17 @@ getbattery(char *base)
|
|||||||
|
|
||||||
co = readfile(base, "status");
|
co = readfile(base, "status");
|
||||||
if (!strncmp(co, "Discharging", 11)) {
|
if (!strncmp(co, "Discharging", 11)) {
|
||||||
status = '-';
|
status = "🔋";
|
||||||
} else if(!strncmp(co, "Charging", 8)) {
|
} else if(!strncmp(co, "Charging", 8)) {
|
||||||
status = '+';
|
status = "🔌";
|
||||||
} else {
|
} else {
|
||||||
status = '?';
|
status = "🔋?";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remcap < 0 || descap < 0)
|
if (remcap < 0 || descap < 0)
|
||||||
return smprintf("invalid");
|
return smprintf("invalid");
|
||||||
|
|
||||||
return smprintf("%.0f%%%c", ((float)remcap / (float)descap) * 100, status);
|
return smprintf("%s %.0f%%", status, ((float)remcap / (float)descap) * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
@ -195,7 +196,7 @@ main(void)
|
|||||||
t0 = gettemperature("/sys/class//hwmon/hwmon1", "temp1_input");
|
t0 = gettemperature("/sys/class//hwmon/hwmon1", "temp1_input");
|
||||||
bat = getbattery("/sys/class/power_supply/BAT0");
|
bat = getbattery("/sys/class/power_supply/BAT0");
|
||||||
|
|
||||||
status = smprintf("🔋 %s 🌡 %s 📈 %s 📅 %s",
|
status = smprintf("%s 🌡 %s 📈 %s 📅 %s",
|
||||||
bat, t0, avgs, tmbln);
|
bat, t0, avgs, tmbln);
|
||||||
setstatus(status);
|
setstatus(status);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user