diff --git a/dwmstatus.c b/dwmstatus.c index 7ace1f5..e185bf2 100644 --- a/dwmstatus.c +++ b/dwmstatus.c @@ -206,38 +206,54 @@ gettemperature(char *base, char *sensor) return smprintf("%02.0f°C", atof(co) / 1000); } +void update() { + char *status; + char *avgs; + char *tmbln; + char *t0; + char *bat; + char *brightness; + + avgs = loadavg(); + 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("%s %s🌡 %s 📈 %s 📅 %s", + bat, brightness, t0, avgs, tmbln); + setstatus(status); + + free(t0); + free(bat); + free(avgs); + free(tmbln); + free(status); + free(brightness); +} + +void sleepUntilFullMinute() { + time_t tim; + struct tm *tm; + tim = time(NULL); + + tm = localtime(&tim); + int seconds_left = 60 - tm->tm_sec; + sleep(seconds_left); +} + int main(void) { - char *status; - char *avgs; - char *tmbln; - char *t0; - char *bat; - char *brightness; - if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "dwmstatus: cannot open display.\n"); return 1; } + update(); + sleepUntilFullMinute(); for (;;sleep(60)) { - avgs = loadavg(); - 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("%s %s🌡 %s 📈 %s 📅 %s", - bat, brightness, t0, avgs, tmbln); - setstatus(status); - - free(t0); - free(bat); - free(avgs); - free(tmbln); - free(status); - free(brightness); + update(); } XCloseDisplay(dpy);