Compare commits
9 Commits
1145ff4c4e
...
9ea61f6907
Author | SHA1 | Date | |
---|---|---|---|
|
9ea61f6907 | ||
|
763cfb7384 | ||
|
cb3381f687 | ||
|
21453eabac | ||
|
07b5fa2967 | ||
|
211f12c0c1 | ||
|
90517af01b | ||
|
18a87dcd51 | ||
|
cb203250c5 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
dwmstatus
|
||||
*.o
|
69
dwmstatus.c
69
dwmstatus.c
@ -19,7 +19,7 @@
|
||||
|
||||
char *tzargentina = "America/Buenos_Aires";
|
||||
char *tzutc = "UTC";
|
||||
char *tzberlin = "Europe/Berlin";
|
||||
char *tzwarsaw = "Europe/Warsaw";
|
||||
|
||||
static Display *dpy;
|
||||
|
||||
@ -86,10 +86,10 @@ loadavg(void)
|
||||
{
|
||||
double avgs[3];
|
||||
|
||||
if (getloadavg(avgs, 3) < 0)
|
||||
if (getloadavg(avgs, 1) < 0)
|
||||
return smprintf("");
|
||||
|
||||
return smprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]);
|
||||
return smprintf("%.2f", avgs[0]);
|
||||
}
|
||||
|
||||
char *
|
||||
@ -116,8 +116,9 @@ readfile(char *base, char *file)
|
||||
char *
|
||||
getbattery(char *base)
|
||||
{
|
||||
char *co, status;
|
||||
int descap, remcap;
|
||||
char *co;
|
||||
char *status;
|
||||
int descap, remcap;
|
||||
|
||||
descap = -1;
|
||||
remcap = -1;
|
||||
@ -151,17 +152,47 @@ getbattery(char *base)
|
||||
|
||||
co = readfile(base, "status");
|
||||
if (!strncmp(co, "Discharging", 11)) {
|
||||
status = '-';
|
||||
status = "🔋";
|
||||
} else if(!strncmp(co, "Charging", 8)) {
|
||||
status = '+';
|
||||
status = "🔌";
|
||||
} else {
|
||||
status = '?';
|
||||
status = "🔋?";
|
||||
}
|
||||
|
||||
if (remcap < 0 || descap < 0)
|
||||
return smprintf("invalid");
|
||||
|
||||
return smprintf("%.0f%%%c", ((float)remcap / (float)descap) * 100, status);
|
||||
return smprintf("%s %.0f%%", status, ((float)remcap / (float)descap) * 100);
|
||||
}
|
||||
|
||||
char *
|
||||
getBrightness(char *base) {
|
||||
char *co;
|
||||
int brightness, max_brightness;
|
||||
char *status;
|
||||
|
||||
co = readfile(base, "brightness");
|
||||
if (co == NULL)
|
||||
return smprintf("");
|
||||
|
||||
sscanf(co, "%d", &brightness);
|
||||
free(co);
|
||||
|
||||
co = readfile(base, "max_brightness");
|
||||
if (co == NULL)
|
||||
return smprintf("");
|
||||
sscanf(co, "%d", &max_brightness);
|
||||
free(co);
|
||||
|
||||
int percentage = (((float)brightness / (float)max_brightness) * 100);
|
||||
|
||||
if(percentage < 50) {
|
||||
status = "🔅";
|
||||
} else {
|
||||
status = "☀";
|
||||
}
|
||||
|
||||
return smprintf("%s %d%% ", status, percentage);
|
||||
}
|
||||
|
||||
char *
|
||||
@ -181,28 +212,32 @@ main(void)
|
||||
char *status;
|
||||
char *avgs;
|
||||
char *tmbln;
|
||||
char *t0, *t1;
|
||||
char *t0;
|
||||
char *bat;
|
||||
char *brightness;
|
||||
|
||||
if (!(dpy = XOpenDisplay(NULL))) {
|
||||
fprintf(stderr, "dwmstatus: cannot open display.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 🖱
|
||||
for (;;sleep(60)) {
|
||||
avgs = loadavg();
|
||||
tmbln = mktimes("%a %d %b %H:%M %Z %Y", tzberlin);
|
||||
t0 = gettemperature("/sys/class//hwmon/hwmon0", "temp1_input");
|
||||
t1 = gettemperature("/sys/class//hwmon/hwmon2", "temp1_input");
|
||||
tmbln = mktimes("%H:%M %d.%m.%Y", tzwarsaw);
|
||||
t0 = gettemperature("/sys/class//hwmon/hwmon1", "temp1_input");
|
||||
bat = getbattery("/sys/class/power_supply/BAT0");
|
||||
brightness = getBrightness("/sys/class/backlight/amdgpu_bl0");
|
||||
|
||||
status = smprintf("Temp: %s, %s | Load: %s | %s %s",
|
||||
t0, t1, avgs, tmbln);
|
||||
status = smprintf("%s %s🌡 %s 📈 %s 📅 %s",
|
||||
bat, brightness, t0, avgs, tmbln);
|
||||
setstatus(status);
|
||||
|
||||
free(t0);
|
||||
free(t1);
|
||||
free(bat);
|
||||
free(avgs);
|
||||
free(tmbln);
|
||||
free(status);
|
||||
free(brightness);
|
||||
}
|
||||
|
||||
XCloseDisplay(dpy);
|
||||
|
Loading…
Reference in New Issue
Block a user