summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2019-12-26 18:13:03 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2019-12-26 18:13:03 +0100
commit3701950a90e0b57d4a64e9ca26c1616cbc386c39 (patch)
treeceda3b3c0d700fa02ba5b76a52b26f0834620450
parent35a3e7cc16f8312c5a750041adf67d2e086d059b (diff)
Fix rare early timeouts in Fl_Clock (STR 3516).
This is the main patch for Fl_Clock discussed in STR 3516. Although the root cause under Linux (in Fl::add_timeout()) has been fixed in a previous commit (35a3e7cc1) early timeouts may still occur, e.g. under Windows in a Virtualbox environment. This commit reverts bab61a93d and replaces it with the patch proposed by Manolo and further discussed in STR 3516.
-rw-r--r--CHANGES.txt2
-rw-r--r--src/Fl_Clock.cxx11
2 files changed, 10 insertions, 3 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 2f00c254a..0f9698124 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -18,6 +18,8 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2019
New Features and Extensions
- (add new items here)
+ - Fix Fl::add_timeout() under Linux (STR 3516).
+ - Fix early timeouts in Fl_Clock seen in some environments (STR 3516).
- Fl_Printer::begin_job() uses by default the Gnome print dialog on the X11
platform when the GTK library is available at run-time. That can be turned off
with Fl::option(OPTION_PRINTER_USES_GTK, false).
diff --git a/src/Fl_Clock.cxx b/src/Fl_Clock.cxx
index ca7237212..4d7f21e47 100644
--- a/src/Fl_Clock.cxx
+++ b/src/Fl_Clock.cxx
@@ -212,11 +212,16 @@ static void tick(void *v) {
time_t sec;
int usec;
Fl::system_driver()->gettime(&sec, &usec);
+ double delta = (1000000 - usec)/1000000.; // time till next second
+ // if current time is just before full second, show that full second
+ // and wait one more second (STR 3516)
+ if (delta < 0.1) {
+ delta += 1.0;
+ sec++;
+ }
((Fl_Clock*)v)->value((ulong)sec);
- // schedule timer event slightly later than the next second (+25 ms)
- // to prevent multiple timer events if triggered too early (STR 3516)
- Fl::add_timeout((1025000 - usec)/1000000., tick, v);
+ Fl::add_timeout(delta, tick, v);
}
int Fl_Clock::handle(int event) {