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
This commit is contained in:
Manolo Gouy 2017-03-07 17:04:31 +00:00
parent c37744cde9
commit fdee9dbf5d

View File

@ -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 <FL/Fl.H>
#include <FL/Fl_Clock.H>
#include <FL/Fl_Round_Clock.H>
#include <FL/Fl_System_Driver.H>
#include <FL/fl_draw.H>
#include <math.h>
#include <time.h>
@ -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) {