Customize status bar

This commit is contained in:
ekzyis 2024-04-21 09:38:43 +02:00
parent 81cdc8f4a2
commit 46f35713b6
1 changed files with 26 additions and 21 deletions

View File

@ -135,7 +135,7 @@ getbattery(char *base)
co = readfile(base, "charge_full_design");
if (co == NULL) {
co = readfile(base, "energy_full_design");
co = readfile(base, "energy_full");
if (co == NULL)
return smprintf("");
}
@ -156,17 +156,23 @@ getbattery(char *base)
status = '-';
} else if(!strncmp(co, "Charging", 8)) {
status = '+';
} else if(!strncmp(co, "Full", 4)) {
status = ' ';
} else {
status = '?';
}
status = '?';
}
if (remcap < 0 || descap < 0)
return smprintf("invalid");
if (status == ' ') {
return smprintf("%.0f%%", ((float)remcap / (float)descap) * 100);
}
return smprintf("%.0f%%%c", ((float)remcap / (float)descap) * 100, status);
}
char *
int
gettemperature(char *base, char *sensor)
{
char *co;
@ -174,7 +180,8 @@ gettemperature(char *base, char *sensor)
co = readfile(base, sensor);
if (co == NULL)
return smprintf("");
return smprintf("%02.0f°C", atof(co) / 1000);
return atof(co) / 1000;
// return smprintf("%02.0f°C", atof(co) / 1000);
}
char *
@ -207,8 +214,8 @@ main(void)
char *tmar;
char *tmutc;
char *tmbln;
char *t0;
char *t1;
int t0;
int t1;
char *kbmap;
char *surfs;
@ -220,27 +227,25 @@ main(void)
for (;;sleep(30)) {
avgs = loadavg();
bat = getbattery("/sys/class/power_supply/BAT0");
tmar = mktimes("%H:%M", tzargentina);
tmutc = mktimes("%H:%M", tzutc);
tmbln = mktimes("KW %W %a %d %b %H:%M %Z %Y", tzberlin);
kbmap = execscript("setxkbmap -query | grep layout | cut -d':' -f 2- | tr -d ' '");
surfs = execscript("surf-status");
// tmar = mktimes("%H:%M", tzargentina);
// tmutc = mktimes("%H:%M", tzutc);
tmbln = mktimes("%a %d %b %H:%M %Z %Y", tzberlin);
// kbmap = execscript("setxkbmap -query | grep layout | cut -d':' -f 2- | tr -d ' '");
// surfs = execscript("surf-status");
t0 = gettemperature("/sys/devices/virtual/thermal/thermal_zone0", "temp");
t1 = gettemperature("/sys/devices/virtual/thermal/thermal_zone1", "temp");
status = smprintf("S:%s K:%s T:%s|%s L:%s B:%s A:%s U:%s %s",
surfs, kbmap, t0, t1, avgs, bat, tmar, tmutc,
tmbln);
status = smprintf("| T%d°C | L%s | B%s | %s |", t0 > t1 ? t0 : t1, avgs, bat, tmbln);
setstatus(status);
free(surfs);
free(kbmap);
free(t0);
free(t1);
// free(surfs);
// free(kbmap);
// free(t0);
// free(t1);
free(avgs);
free(bat);
free(tmar);
free(tmutc);
// free(tmar);
// free(tmutc);
free(tmbln);
free(status);
}