The Unix version of FL calls the Unix-specific object Fl_Poll in order to implement these methods. This object provides a interface to the Unix select() or poll() call. You may find this object useful even if you don't use FL.
void Fl::run()
{for (;;) wait()}
.
Unfortunately some compilers will give you warnings if you don't put a
return statement after this, while others will warn you if you do
(because they realize it can't return). So don't use this in portable
programs.
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.
float Fl::wait(float time)
Time is actually measured from the point that the last Unix poll() 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 poll() 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, short events, void (*cb)(int, void*), void* = 0);
void Fl::remove_fd(int);
void Fl::set_idle(void (*cb)());
The idle callback should not call any Fl methods other than Fl_Object::redraw() and Fl::set_idle().
void Fl::flush()
int Fl::damage()
Fl_Object *Fl::readqueue();
void Fl::mouse_position(int &,int &)
Return where the mouse is on the screen by doing a round-trip query to the server. You should use Fl::event_x/y_root() if possible, but this function is necessary if you are not sure if a mouse event has been processed recently. If the display is not open, this will open it.