diff options
author | clsr <clsr@clsr.net> | 2018-08-09 18:18:44 +0200 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2018-08-09 18:18:44 +0200 |
commit | cedca7b8b843413217b399ea1323c727994237ce (patch) | |
tree | 7289f5ff5dc93e7e9a8a2b09ffb2d17c91294861 | |
parent | 262fd581a79f61ee99b018938c480cf318ba6bd6 (diff) | |
download | dwmclock-1.2.0.tar.gz dwmclock-1.2.0.zip |
Add exact sleepv1.2.0
-rw-r--r-- | config.def.mk | 14 | ||||
-rw-r--r-- | dwmclock.c | 15 |
2 files changed, 26 insertions, 3 deletions
diff --git a/config.def.mk b/config.def.mk index 1860aaf..4265c82 100644 --- a/config.def.mk +++ b/config.def.mk @@ -6,20 +6,26 @@ CFLAGS+=-DBATTERY # set this to the correct path for your current system CFLAGS+=-DENERGY_FULL=\"/sys/class/power_supply/BAT0/energy_full\" CFLAGS+=-DENERGY_NOW=\"/sys/class/power_supply/BAT0/energy_now\" -CFLAGS+=-DSTATUS=\"/sys/class/power_supply/BAT0/status\" +CFLAGS+=-DSTATUS=\"/sys/class/power_supply/ADP1/online\" + # the string to match when the battery is charging; comment out to disable charging detection -CFLAGS+=-DCHARGING=\"Charging\\n\" +CFLAGS+=-DCHARGING=\"1\\n\" # possible alternative on some systems #CFLAGS+=-DENERGY_FULL=\"/sys/class/power_supply/BAT0/charge_full\" #CFLAGS+=-DENERGY_NOW=\"/sys/class/power_supply/BAT0/charge_now\" +#CFLAGS+=-DSTATUS=\"/sys/class/power_supply/BAT0/status\" +#CFLAGS+=-DCHARGING=\"Charging\\n\" # every how many seconds to refresh the battery charge display -CFLAGS+=-DBAT_REFRESH_SECONDS=60 +CFLAGS+=-DBAT_REFRESH_SECONDS=10 # this is here for legacy reasons, ignore it CFLAGS+=-DMUL=1 +# sleep to the start of the next second instead of for 1s +CFLAGS+=-DEXACT_SLEEP + # make settings @@ -33,3 +39,5 @@ LDFLAGS+=$(shell pkg-config --libs x11) # default paths DESTDIR?=/ PREFIX?=/usr/local +#DESTDIR?=~ +#PREFIX?=/local @@ -62,6 +62,9 @@ void handler(int sig) int main(void) { +#ifdef EXACT_SLEEP + struct timespec ts; +#endif /* EXACT_SLEEP */ struct tm *tm; time_t now; #ifdef BATTERY @@ -128,13 +131,25 @@ int main(void) perc[7] = ' '; #endif /* BATTERY */ +#ifdef EXACT_SLEEP + clock_gettime(CLOCK_REALTIME, &ts); + now = ts.tv_sec; +#else now = time(NULL); +#endif /* EXACT_SLEEP */ tm = localtime(&now); strftime(clock, 9, "%H:%M:%S", tm); XStoreName(disp, root, name); XFlush(disp); + +#ifdef EXACT_SLEEP + ts.tv_sec = 0; + ts.tv_nsec = 1000000000 - ts.tv_nsec; + nanosleep(&ts, NULL); +#else sleep(1); +#endif /* EXACT_SLEEP */ } XCloseDisplay(disp); |