aboutsummaryrefslogtreecommitdiffstats
path: root/dwmclock.c
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2018-08-09 18:18:44 +0200
committerclsr <clsr@clsr.net>2018-08-09 18:18:44 +0200
commitcedca7b8b843413217b399ea1323c727994237ce (patch)
tree7289f5ff5dc93e7e9a8a2b09ffb2d17c91294861 /dwmclock.c
parent262fd581a79f61ee99b018938c480cf318ba6bd6 (diff)
downloaddwmclock-cedca7b8b843413217b399ea1323c727994237ce.tar.gz
dwmclock-cedca7b8b843413217b399ea1323c727994237ce.zip
Add exact sleepv1.2.0
Diffstat (limited to 'dwmclock.c')
-rw-r--r--dwmclock.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/dwmclock.c b/dwmclock.c
index e7fd938..b409555 100644
--- a/dwmclock.c
+++ b/dwmclock.c
@@ -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);