From fdee9dbf5d3d90e1258fb110fe7ce8d09e818d0d Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Tue, 7 Mar 2017 17:04:31 +0000 Subject: Have all Fl_Clock objects in a single FLTK app tick approximately at the same time. Before this change, clocks can tick at any point within a second, so 2 clocks can appear to disagree on the time they give (by less than a second). To see that, run the clock test program, icons one of the clocks, and uniconize it just before the other clock will tick. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12188 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Clock.cxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/Fl_Clock.cxx') diff --git a/src/Fl_Clock.cxx b/src/Fl_Clock.cxx index 46b326181..220479a9e 100644 --- a/src/Fl_Clock.cxx +++ b/src/Fl_Clock.cxx @@ -3,7 +3,7 @@ // // Clock widget for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2010 by Bill Spitzak and others. +// Copyright 1998-2017 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -183,8 +184,11 @@ Fl_Clock::Fl_Clock(uchar t, int X, int Y, int W, int H, const char *L) } static void tick(void *v) { - ((Fl_Clock*)v)->value((ulong) time(0)); - Fl::add_timeout(1.0, tick, v); + time_t sec; + int usec; + Fl::system_driver()->gettime(&sec, &usec); + ((Fl_Clock*)v)->value((ulong)sec); + Fl::add_timeout((1000000 - usec)/1000000., tick, v); // time till next second } int Fl_Clock::handle(int event) { -- cgit v1.2.3