diff --git a/src/Fl.cxx b/src/Fl.cxx index 1579d5ac4..efeb063ad 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -1,5 +1,6 @@ +#include // -// "$Id: Fl.cxx,v 1.24.2.11 1999/07/27 17:24:13 bill Exp $" +// "$Id: Fl.cxx,v 1.24.2.12 1999/08/22 23:31:21 gustavo Exp $" // // Main event handling code for the Fast Light Tool Kit (FLTK). // @@ -111,17 +112,19 @@ void Fl::remove_timeout(void (*cb)(void *), void *v) { numtimeouts = j; } -static void call_timeouts() { +static int call_timeouts() { + int expired = 0; while (numtimeouts) { if (timeout[0].time > 0) break; // we must remove timeout from array before doing the callback: void (*cb)(void*) = timeout[0].cb; void *arg = timeout[0].arg; - numtimeouts--; + numtimeouts--; expired++; if (numtimeouts) memmove(timeout, timeout+1, numtimeouts*sizeof(Timeout)); // now it is safe for the callback to do add_timeout: cb(arg); } + return expired; } void Fl::flush() { @@ -154,7 +157,7 @@ static int initclock; // if false we didn't call fl_elapsed() last time #endif // fl_elapsed must return the amount of time since the last time it was -// called. To reduce the number of system calls the to get the +// called. To reduce the number of system calls to get the // current time, the "initclock" symbol is turned on by an indefinite // wait. This should then reset the measured-from time and return zero static double fl_elapsed() { @@ -204,14 +207,15 @@ static void callidle() { int Fl::wait() { callidle(); - if (numtimeouts) {fl_elapsed(); call_timeouts();} + int expired = 0; + if (numtimeouts) {fl_elapsed(); expired = call_timeouts();} flush(); if (!Fl_X::first) return 0; // no windows - if (idle && !in_idle) + if ((idle && !in_idle) || expired) { fl_wait(1,0.0); - else if (numtimeouts) + } else if (numtimeouts) { fl_wait(1, timeout[0].time); - else { + } else { initclock = 0; fl_wait(0,0); } @@ -220,9 +224,10 @@ int Fl::wait() { double Fl::wait(double time) { callidle(); - if (numtimeouts) {time -= fl_elapsed(); call_timeouts();} + int expired = 0; + if (numtimeouts) {time -= fl_elapsed(); expired = call_timeouts();} flush(); - double wait_time = idle && !in_idle ? 0.0 : time; + double wait_time = (idle && !in_idle) || expired ? 0.0 : time; if (numtimeouts && timeout[0].time < wait_time) wait_time = timeout[0].time; fl_wait(1, wait_time); return time - fl_elapsed(); @@ -695,5 +700,5 @@ int fl_old_shortcut(const char* s) { } // -// End of "$Id: Fl.cxx,v 1.24.2.11 1999/07/27 17:24:13 bill Exp $". +// End of "$Id: Fl.cxx,v 1.24.2.12 1999/08/22 23:31:21 gustavo Exp $". //