The Main Event Loop

G-Golf Glib Main Event Loop low level API.
The Main Event Loop — manages all available sources of events

Procedures

g-main-loop-new
g-main-loop-run
g-main-loop-ref
g-main-loop-unref
g-main-loop-quit
g-main-context-new
g-main-context-default
g-timeout-source-new
g-timeout-source-new-seconds
g-idle-source-new
g-source-ref-count
g-source-ref
g-source-unref
g-source-free
g-source-attach
g-source-destroy
g-source-is-destroyed?
g-source-set-priority
g-source-get-priority
g-source-remove

Description

The main event loop manages all the available sources of events for GLib and GTK+ applications. These events can come from any number of different types of sources such as file descriptors (plain files, pipes or sockets) and timeouts. New types of event sources can also be added using g-source-attach.

Please read The Main Event Loop section from the Glib reference manual for a complete description.

Procedures

Note: in this section, the loop, context and source arguments are [must be] pointers to a GMainLoop, a GMainContext and a GSource respectively.

Procedure: g-main-loop-new [context #f] [is-running? #f]

Returns a pointer to a new GMainLoop.

Creates a new GMainLoop structure.

The context must be a pointer to a GMainContext of #f, in which case the default context is used. When is-running? is #t, it indicates that the loop is running. This is not very important since calling g-main-loop-run will set this to #t anyway.

Procedure: g-main-loop-ref loop

Returns loop.

Increases the loop reference count by one.

Procedure: g-main-loop-unref loop

Returns nothing.

Decreases the loop reference count by one. If the result is zero, free the loop and free all associated memory.

Procedure: g-main-loop-run loop

Returns nothing.

Runs a main loop until g-main-loop-quit is called on the loop. If this is called for the thread of the loop’s GMainContext, it will process events from the loop, otherwise it will simply wait.

Procedure: g-main-loop-quit loop

Returns nothing.

Stops a GMainLoop from running. Any calls to g-main-loop-run for the loop will return.

Note that sources that have already been dispatched when g-main-loop-quit is called will still be executed.

Procedure: g-main-context-new

Returns a pointer.

Creates and returns a (pointer to a) new GMainContext structure.

Procedure: g-main-context-default

Returns a pointer.

Returns the global default main context. This is the main context used for main loop functions when a main loop is not explicitly specified, and corresponds to the ‘main’ main loop.

Procedure: g-timeout-source-new interval

Returns a pointer.

Creates and returns (a pointer to) a new (timeout) GSource.

The source will not initially be associated with any GMainContext and must be added to one with g-source-attach before it will be executed.

The timeout interval is in milliseconds.

Procedure: g-timeout-source-new-seconds interval

Returns a pointer.

Creates and returns (a pointer to) a new (timeout) GSource.

The source will not initially be associated with any GMainContext and must be added to one with g-source-attach before it will be executed.

The timeout interval is in seconds.

Procedure: g-idle-source-new

Returns a pointer.

Creates and returns (a pointer to) a new (idle) GSource.

The source will not initially be associated with any GMainContext and must be added to one with g-source-attach before it will be executed. Note that the default priority for idle sources is 200, as compared to other sources which have a default priority of 300.

Procedure: g-source-ref-count source

Returns an integer.

Obtains and returns the reference count of source.

Procedure: g-source-ref source

Returns source.

Increases the source reference count by one.

Procedure: g-source-unref source

Returns nothing.

Decreases the source reference count by one. If the resulting reference count is zero the source and associated memory will be destroyed.

Procedure: g-source-free source

Returns nothing.

Calls g-source-destroy and decrements the reference count of source to 0 (so source will be destroyed and freed).

Procedure: g-source-attach source context

Returns an integer.

Adds source to context so that it will be executed within that context.

Returns the ID (greater than 0) for the source within the context.

Remove it by calling g-source-destroy.

Procedure: g-source-destroy source

Returns nothing.

Removes source from its GMainContext, if any, and mark it as destroyed. The source cannot be subsequently added to another context. It is safe to call this on sources which have already been removed from their context.

This does not unref source: if you still hold a reference, use g-source-unref to drop it.

Procedure: g-source-is-destroyed? source

Returns #t if source has been destroyed. Otherwise, it returns #f.

Once a source is destroyed it cannot be un-destroyed.

Procedure: g-source-set-priority source priority

Returns nothing.

Sets the source priority. While the main loop is being run, a source will be dispatched if it is ready to be dispatched and no sources at a higher (numerically smaller) priority are ready to be dispatched.

A child source always has the same priority as its parent. It is not permitted to change the priority of a source once it has been added as a child of another source.

Procedure: g-source-get-priority source priority

Returns an integer.

Obtains and returns the source priority.

Procedure: g-source-remove id

Returns #t.

Removes the source with the given id from the default main context. You must use g-source-destroy for sources added to a non-default main context.

It is an error to attempt to remove a non-existent source.

Source IDs can be reissued after a source has been destroyed. This could lead to the removal operation being performed against the wrong source, unless you are cautious.

For historical reasons, this procedure always returns #t.