Compare commits

...

9 Commits

Author SHA1 Message Date
Przemek Grondek
9ea61f6907 Add brightness 2022-07-25 23:05:07 +02:00
Przemek Grondek
763cfb7384 Change battery status 2022-07-25 22:39:33 +02:00
Przemek Grondek
cb3381f687 Change time info 2022-07-25 22:13:45 +02:00
Przemek Grondek
21453eabac Change load to one value 2022-07-25 22:11:24 +02:00
Przemek Grondek
07b5fa2967 Update status
add emoji
 short date
 remove redundant temperature
2022-07-25 22:02:04 +02:00
Przemek Grondek
211f12c0c1 Temperature control
fix sensors
 add third sensor
2022-07-15 18:05:01 +02:00
Przemek Grondek
90517af01b Add gitignore 2022-07-15 17:59:46 +02:00
Przemek Grondek
18a87dcd51 Fix too many arguments 2022-07-15 17:58:53 +02:00
Przemek Grondek
cb203250c5 Add battery 2022-07-15 17:56:55 +02:00
2 changed files with 54 additions and 17 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
dwmstatus
*.o

View File

@ -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);