From 0d9838b7712b9f2a8732f2989f9af05926533319 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 19 Jul 2009 18:56:19 +0000 Subject: use more precise timings --- aclock.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/aclock.c b/aclock.c index 9188b0c..c91a71c 100644 --- a/aclock.c +++ b/aclock.c @@ -36,12 +36,12 @@ catch(int sig) } void -settimer(int sec) +settimer(int sec, int usec) { struct itimerval itv; itv.it_value.tv_sec = sec; - itv.it_value.tv_usec = 0; + itv.it_value.tv_usec = usec; itv.it_interval = itv.it_value; setitimer(ITIMER_REAL, &itv, NULL); @@ -86,16 +86,19 @@ main(void) time_t t; struct tm *ltime; struct winsize ws; + struct timeval tv; signal(SIGWINCH, catch); signal(SIGALRM, catch); signal(SIGINT, catch); - settimer(1); initscr(); curs_set(0); while (!die) { + gettimeofday(&tv, NULL); + settimer(0, 1000000 - tv.tv_usec); + if (redraw && ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) != -1) { resizeterm(ws.ws_row, ws.ws_col); clear(); -- cgit v1.2.3