GTK+
The GIMP Toolkit

General
Introduction
Screenshots
Download
Mailing Lists
Language Bindings
Themes
Bug Tracker

Documentation
FAQ
Tutorial
API Reference
Published Books

Projects
Pango
Inti
GNOME
GTK+ for Win32
GtkFB (Framebuffer)
GTK+ on DirectFB
GTK+ for BeOS

Applications
GIMP
Abiword
Dia
Glade
GnuCash
Gnumeric

GNOME Software Map

Chapter 18. Timeouts, IO and Idle Functions

Table of Contents
18.1. Timeouts
18.2. Monitoring IO
18.3. Idle Functions

18.1. Timeouts

You may be wondering how you make GTK do useful work when in gtk_main. Well, you have several options. Using the following function you can create a timeout function that will be called every "interval" milliseconds.

gint gtk_timeout_add( guint32     interval,
                      GtkFunction function,
                      gpointer    data );

The first argument is the number of milliseconds between calls to your function. The second argument is the function you wish to have called, and the third, the data passed to this callback function. The return value is an integer "tag" which may be used to stop the timeout by calling:

void gtk_timeout_remove( gint tag );

You may also stop the timeout function by returning zero or FALSE from your callback function. Obviously this means if you want your function to continue to be called, it should return a non-zero value, i.e., TRUE.

The declaration of your callback should look something like this:

gint timeout_callback( gpointer data );