
Notes on how to implement plib over gtk
---------------------------------------

(1) gtk_timeout_add (gtkmain.c) uses g_timeout_add (glib gmain.c),
which gets the time as of the call and adds the specified interval as
the first select timeout.  Hence, p_timer/p_idler can be implemented
neatly like this:

As far as gtk is concerned, the application has a single routine that
alternates between being called as an idler: Its data context tells
whether it has been invoked as a timeout or an idler.  If it is a
timeout, then services the timeout; if it is an idler, it calls the
application on_idle (and remembers if it wants to be called again).
In either case, before returning, it calls the application on_poll
function.  If app_on_poll returns >=0, it calls gtk_timeout_add to add
itself as a timeout with the specified interval, then returns 0 to
remove its previous incarnation (as either a timeout or idler).
Otherwise, it returns 0 unless app_on_idle was called and returned 0.

Unclear: need to know whether gtk calls its idler over and over
without waiting for new input between idler calls (seems most likely),
or whether it calls an idler only once and waits for new input before
calling it again.  In the former case, really just want a sequence of
timeouts with 0 for immediate recall, or HUGE to wait forever.
