int Fl::run()
Fl::run() does exactly this and nothing more:
for (;;) Fl::wait();
Even though run() never returns, it claims to return an integer.
This is so you can end main() with "return Fl::run()
"
which is the only way to get the compiler made by a certain very large
software company to compile without errors in both debug and optimized
mode!
int Fl::wait()
If a set_idle() function has been done, this does Fl::flush(), calls the idle function, then does Fl::check() (thus it returns immediately).
If a timeout or file descriptor has been registered and it happens before any X events are ready, wait() returns immediately after the timeout or file descriptor callback is done.
The return value is always 1. This is so you can write an infinite
loop in main() as "while (Fl::wait()) {...}
",
which is the only way to get the compiler made by a certain very large
software company to compile without errors in both debug and optimized
mode!
float Fl::wait(float time)
Time is actually measured from the point that the last Unix select() call was done. This allows you to accurately make something happen at regular intervals. As long as A() does not take more than a second to execute, the following code will call A() exactly once per second:
for (;;) {
for (float time = 1.0; time > 0; ) time = Fl::wait(time);
A();
}
float Fl::reset();
Fl::reset();
for (float time = 1.0; time > 0; ) time = Fl::wait(time);
int Fl::check()
while (!calculation_done()) {
calculate();
Fl::check();
if (user_hit_abort_button()) break;
}
The return value is system-specific (on Unix it is whatever the select() call returned).
int Fl::ready();
while (!calculation_done()) {
calculate();
if (Fl::ready()) {
do_expensive_cleanup();
Fl::check();
if (user_hit_abort_button()) break;
}
}
void Fl::add_timeout(float t,void (*cb)(void*),void* v=0);
void Fl::remove_timeout(void (*cb)(void*), void* = 0);
This code will print "TICK" each second on stdout, no matter what else the user or program does:
void callback(void *) {
printf("TICK\n");
Fl::add_timeout(1.0,callback);
}
main() {...
Fl::add_timeout(1.0,callback);
Fl::run();
}
void Fl::add_fd(int fd, void (*cb)(int, void*), void* = 0);
void Fl::add_fd(int fd, int when, void (*cb)(int, void*), void* = 0);
void Fl::remove_fd(int);
The second version takes a when bitfield, with the bits FL_READ, FL_WRITE, and FL_EXCEPT defined, to indicate when the callback should be done. This probably only works on Unix.
Fl::remove_fd() gets rid of all the callbacks for a given file descriptor.
void Fl::add_test(int (*test)(void*), void (*cb)(void*), void* v=0);
This is often necessary if you are using a library that insists on reading and buffering input from a device but not acting on it. For instance glFlush() apparently reads all pending X events, thus causing the X file descriptor to be non-ready, even though there are pending X events visible with XQueued(). Such libraries are (imho) broken because they waste time doing a select() that the caller will need to do again anyway.
void Fl::remove_test(int (*test)(void*), void
(*cb)(void*), void* v=0);
void Fl::set_idle(void (*cb)());
The idle callback should not call any fltk methods other than Fl_Widget::redraw() and Fl::set_idle().
void Fl::flush()
int Fl::damage()
Fl_Widget *Fl::readqueue();