From 1b017e36d0367a558dd9911e41a6c7d989968934 Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Tue, 26 Jul 2022 00:06:32 +0200 Subject: [PATCH] Align with full minute --- dwmstatus.c | 62 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 23 deletions(-) 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);