summaryrefslogtreecommitdiff
path: root/src/Fl_Clock.cxx
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2017-03-07 17:04:31 +0000
committerManolo Gouy <Manolo>2017-03-07 17:04:31 +0000
commitfdee9dbf5d3d90e1258fb110fe7ce8d09e818d0d (patch)
tree80ebff50262678f17cfa48c0e09f37f96d28bba2 /src/Fl_Clock.cxx
parentc37744cde9ff9a4e9e476a9a4acebfee87650f29 (diff)
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
Diffstat (limited to 'src/Fl_Clock.cxx')
-rw-r--r--src/Fl_Clock.cxx10
1 files changed, 7 insertions, 3 deletions
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 <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) {