Idle functions run continuously
while the GTK+ main loop has nothing else to do. Idle
functions run only when the event queue is empty and the
main loop would normally sit idly, waiting for something
to happen. As long as they return TRUE they are invoked over and over;
when they return FALSE,
they are removed, just as if
gtk_idle_remove() had been called.
The idle function API, shown in Figure 31, is
identical to the timeout and quit function APIs. Again,
gtk_idle_remove() should not be
called from within an idle function, because it will
corrupt GTK+'s idle function list. Return FALSE to remove the idle function.
Idle functions are mostly useful to queue "one-shot"
code, which is run after all events have been handled.
Relatively expensive operations such as GTK+ size
negotiation and GnomeCanvas
repaints take place in idle functions that return FALSE. This ensures that
expensive operations are performed only once, even though
multiple consecutive events independently request the
The GTK+ main loop contains a simple scheduler; idle
functions actually have priorities assigned to them, just
as UNIX processes do. You can assign a non-default
priority to your idle functions, but it's a complicated
topic outside the scope of this book.
guint gtk_idle_add(GtkFunction function, gpointer data);
Figure 31. Idle Functions