W Wrapl, The Programming Language

Libraries:Gtk:Glib:GMain

Functions

ChildWatchAdd(pid @ Std.Object.T, function @ Std.Function.T, data @ Std.Address.T) : Std.Integer.SmallT

Sets a function to be called when the child indicated by pid exits, at a default priority, G_PRIORITY_DEFAULT.

If you obtain pid from g_spawn_async() or g_spawn_async_with_pipes() you will need to pass G_SPAWN_DO_NOT_REAP_CHILD as flag to the spawn function for the child watching to work.

Note that on platforms where GPid must be explicitly closed (see g_spawn_close_pid()) pid must not be closed while the source is still active. Typically, you will want to call g_spawn_close_pid() in the callback function for the source.

GLib supports only a single callback per process id.

This internally creates a main loop source using ChildWatchSourceNew and attaches it to the main loop context using SourceAttach. You can do these steps manually if you need greater control.

pid process id to watch. On POSIX the pid of a child process. On Windows a handle for a process (which doesn't have to be a child).
function function to call
data data to pass to function
Returns the ID (greater than 0) of the event source.


ChildWatchAddFull(priority @ Std.Integer.SmallT, pid @ Std.Object.T, function @ Std.Function.T, data @ Std.Address.T, notify @ Std.Function.T) : Std.Integer.SmallT

Sets a function to be called when the child indicated by pid exits, at the priority priority.

If you obtain pid from g_spawn_async() or g_spawn_async_with_pipes() you will need to pass G_SPAWN_DO_NOT_REAP_CHILD as flag to the spawn function for the child watching to work.

Note that on platforms where GPid must be explicitly closed (see g_spawn_close_pid()) pid must not be closed while the source is still active. Typically, you will want to call g_spawn_close_pid() in the callback function for the source.

GLib supports only a single callback per process id.

This internally creates a main loop source using ChildWatchSourceNew and attaches it to the main loop context using SourceAttach. You can do these steps manually if you need greater control.

priority the priority of the idle source. Typically this will be in the range between G_PRIORITY_DEFAULT_IDLE and G_PRIORITY_HIGH_IDLE.
pid process to watch. On POSIX the pid of a child process. On Windows a handle for a process (which doesn't have to be a child).
function function to call
data data to pass to function
notify function to call when the idle is removed, or NULL
Returns the ID (greater than 0) of the event source. Rename to: g_child_watch_add


ChildWatchSourceNew(pid @ Std.Object.T) : Gtk.Glib.GSource.T

Creates a new child_watch source.

The source will not initially be associated with any Gtk.Glib.GMainContext.T and must be added to one with SourceAttach before it will be executed.

Note that child watch sources can only be used in conjunction with g_spawn... when the G_SPAWN_DO_NOT_REAP_CHILD flag is used.

Note that on platforms where GPid must be explicitly closed (see g_spawn_close_pid()) pid must not be closed while the source is still active. Typically, you will want to call g_spawn_close_pid() in the callback function for the source.

Note further that using ChildWatchSourceNew is not compatible with calling waitpid(-1) in the application. Calling waitpid() for individual pids will still work fine.

pid process to watch. On POSIX the pid of a child process. On Windows a handle for a process (which doesn't have to be a child).
Returns the newly-created child watch source


ContextAcquire(context @ Gtk.Glib.GMainContext.T) : Std.Symbol.T

Tries to become the owner of the specified context. If some other thread is the owner of the context, returns FALSE immediately. Ownership is properly recursive: the owner can require ownership again and will release ownership when ContextRelease is called as many times as ContextAcquire.

You must be the owner of a context before you can call ContextPrepare, ContextQuery, ContextCheck, ContextDispatch.

context a Gtk.Glib.GMainContext.T
Returns TRUE if the operation succeeded, and this thread is now the owner of context.


ContextAddPoll(context @ Gtk.Glib.GMainContext.T, fd @ Std.Object.T, priority @ Std.Integer.SmallT) : Std.Object.T

Adds a file descriptor to the set of file descriptors polled for this context. This will very seldom be used directly. Instead a typical event source will use SourceAddPoll instead.

context a Gtk.Glib.GMainContext.T (or NULL for the default context)
fd a GPollFD structure holding information about a file descriptor to watch.
priority the priority for this file descriptor which should be the same as the priority used for SourceAttach to ensure that the file descriptor is polled whenever the results may be needed.


ContextCheck(context @ Gtk.Glib.GMainContext.T, max_priority @ Std.Integer.SmallT, fds @ Std.Object.T, n_fds @ Std.Integer.SmallT) : Std.Integer.SmallT

Passes the results of polling back to the main loop.

context a Gtk.Glib.GMainContext.T
max_priority the maximum numerical priority of sources to check
fds array of GPollFD's that was passed to the last call to ContextQuery. [array length=n_fds]
n_fds return value of ContextQuery
Returns TRUE if some sources are ready to be dispatched.


ContextDefault() : Gtk.Glib.GMainContext.T

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. See also ContextGetThreadDefault.

Returns the global default main context. [transfer none]


ContextDispatch(context @ Gtk.Glib.GMainContext.T) : Std.Object.T

Dispatches all pending sources.



ContextFindSourceByFuncsUserData(context @ Gtk.Glib.GMainContext.T, funcs @ Gtk.Glib.GSourceFuncs.T, user_data @ Std.Address.T) : Gtk.Glib.GSource.T

Finds a source with the given source functions and user data. If multiple sources exist with the same source function and user data, the first one found will be returned.

context a Gtk.Glib.GMainContext.T (if NULL, the default context will be used).
funcs the source_funcs passed to SourceNew.
user_data the user data from the callback.
Returns the source, if one was found, otherwise NULL. [transfer none]


ContextFindSourceById(context @ Gtk.Glib.GMainContext.T, source_id @ Std.Integer.SmallT) : Gtk.Glib.GSource.T

Finds a Gtk.Glib.GSource.T given a pair of context and ID.

context a Gtk.Glib.GMainContext.T (if NULL, the default context will be used)
source_id the source ID, as returned by SourceGetId.
Returns the Gtk.Glib.GSource.T if found, otherwise, NULL. [transfer none]


ContextFindSourceByUserData(context @ Gtk.Glib.GMainContext.T, user_data @ Std.Address.T) : Gtk.Glib.GSource.T

Finds a source with the given user data for the callback. If multiple sources exist with the same user data, the first one found will be returned.

context a Gtk.Glib.GMainContext.T
user_data the user_data for the callback.
Returns the source, if one was found, otherwise NULL. [transfer none]


ContextGetPollFunc(context @ Gtk.Glib.GMainContext.T) : Std.Object.T

Gets the poll function set by ContextSetPollFunc.

context a Gtk.Glib.GMainContext.T
Returns the poll function


ContextGetThreadDefault() : Gtk.Glib.GMainContext.T

Gets the thread-default Gtk.Glib.GMainContext.T for this thread. Asynchronous operations that want to be able to be run in contexts other than the default one should call this method to get a Gtk.Glib.GMainContext.T to add their Gtk.Glib.GSource.Ts to. (Note that even in single-threaded programs applications may sometimes want to temporarily push a non-default context, so it is not safe to assume that this will always return NULL if threads are not initialized.)

Returns the thread-default Gtk.Glib.GMainContext.T, or NULL if the thread-default context is the global default context. [transfer none]


ContextInvoke(context @ Gtk.Glib.GMainContext.T, function @ Std.Function.T, data @ Std.Address.T) : Std.Object.T

Invokes a function in such a way that context is owned during the invocation of function.

If context is NULL then the global default main context - as returned by ContextDefault - is used.

If context is owned by the current thread, function is called directly. Otherwise, if context is the thread-default main context of the current thread and ContextAcquire succeeds, then function is called and ContextRelease is called afterwards.

In any other case, an idle source is created to call function and that source is attached to context (presumably to be run in another thread). The idle source is attached with G_PRIORITY_DEFAULT priority. If you want a different priority, use ContextInvokeFull.

Note that, as with normal idle functions, function should probably return FALSE. If it returns TRUE, it will be continuously run in a loop (and may prevent this call from returning).

context a Gtk.Glib.GMainContext.T, or NULL. [allow-none]
function function to call
data data to pass to function


ContextInvokeFull(context @ Gtk.Glib.GMainContext.T, priority @ Std.Integer.SmallT, function @ Std.Function.T, data @ Std.Address.T, notify @ Std.Function.T) : Std.Object.T

Invokes a function in such a way that context is owned during the invocation of function.

This function is the same as ContextInvoke except that it lets you specify the priority incase function ends up being scheduled as an idle and also lets you give a Gtk.Glib.GDestroyNotify for data.

notify should not assume that it is called from any particular thread or with any particular context acquired.

context a Gtk.Glib.GMainContext.T, or NULL. [allow-none]
priority the priority at which to run function
function function to call
data data to pass to function
notify a function to call when data is no longer in use, or NULL.


ContextIsOwner(context @ Gtk.Glib.GMainContext.T) : Std.Symbol.T

Determines whether this thread holds the (recursive) ownership of this Gtk.Glib.GMainContext.T. This is useful to know before waiting on another thread that may be blocking to get ownership of context.

context a Gtk.Glib.GMainContext.T
Returns TRUE if current thread is owner of context.


ContextIteration(context @ Gtk.Glib.GMainContext.T, may_block @ Std.Symbol.T) : Std.Symbol.T

Runs a single iteration for the given main loop. This involves checking to see if any event sources are ready to be processed, then if no events sources are ready and may_block is TRUE, waiting for a source to become ready, then dispatching the highest priority events sources that are ready. Otherwise, if may_block is FALSE sources are not waited to become ready, only those highest priority events sources will be dispatched (if any), that are ready at this given moment without further waiting.

Note that even when may_block is TRUE, it is still possible for ContextIteration to return FALSE, since the the wait may be interrupted for other reasons than an event source becoming ready.

context a Gtk.Glib.GMainContext.T (if NULL, the default context will be used)
may_block whether the call may block.
Returns TRUE if events were dispatched.


ContextNew() : Gtk.Glib.GMainContext.T

Creates a new Gtk.Glib.GMainContext.T structure.

Returns the new Gtk.Glib.GMainContext.T


ContextPending(context @ Gtk.Glib.GMainContext.T) : Std.Symbol.T

Checks if any sources have pending events for the given context.

context a Gtk.Glib.GMainContext.T (if NULL, the default context will be used)
Returns TRUE if events are pending.


ContextPopThreadDefault(context @ Gtk.Glib.GMainContext.T) : Std.Object.T

Pops context off the thread-default context stack (verifying that it was on the top of the stack).

context a Gtk.Glib.GMainContext.T object, or NULL


ContextPrepare(context @ Gtk.Glib.GMainContext.T, priority @ Std.Object.T) : Std.Symbol.T

Prepares to poll sources within a main loop. The resulting information for polling is determined by calling ContextQuery.

context a Gtk.Glib.GMainContext.T
priority location to store priority of highest priority source already ready.
Returns TRUE if some source is ready to be dispatched prior to polling.


ContextPushThreadDefault(context @ Gtk.Glib.GMainContext.T) : Std.Object.T

Acquires context and sets it as the thread-default context for the current thread. This will cause certain asynchronous operations (such as most gio-based I/O) which are started in this thread to run under context and deliver their results to its main loop, rather than running under the global default context in the main thread. Note that calling this function changes the context returned by ContextGetThreadDefault, not the one returned by ContextDefault, so it does not affect the context used by functions like IdleAdd.

Normally you would call this function shortly after creating a new thread, passing it a Gtk.Glib.GMainContext.T which will be run by a Gtk.Glib.GMainLoop.T in that thread, to set a new default context for all async operations in that thread. (In this case, you don't need to ever call ContextPopThreadDefault.) In some cases however, you may want to schedule a single operation in a non-default context, or temporarily use a non-default context in the main thread. In that case, you can wrap the call to the asynchronous operation inside a ContextPushThreadDefault / ContextPopThreadDefault pair, but it is up to you to ensure that no other asynchronous operations accidentally get started while the non-default context is active.

Beware that libraries that predate this function may not correctly handle being used from a thread with a thread-default context. Eg, see Gtk.Gio.GFile.SupportsThreadContexts.

context a Gtk.Glib.GMainContext.T, or NULL for the global default context


ContextQuery(context @ Gtk.Glib.GMainContext.T, max_priority @ Std.Integer.SmallT, timeout_ @ Std.Object.T, fds @ Std.Object.T, n_fds @ Std.Integer.SmallT) : Std.Integer.SmallT

Determines information necessary to poll this main loop.

context a Gtk.Glib.GMainContext.T
max_priority maximum priority source to check
timeout_ location to store timeout to be used in polling. [out]
fds location to store GPollFD records that need to be polled. [out caller-allocates][array length=n_fds]
n_fds length of fds.
Returns the number of records actually stored in fds, or, if more than n_fds records need to be stored, the number of records that need to be stored.


ContextRef(context @ Gtk.Glib.GMainContext.T) : Gtk.Glib.GMainContext.T

Increases the reference count on a Gtk.Glib.GMainContext.T object by one.

context a Gtk.Glib.GMainContext.T
Returns the context that was passed in (since 2.6)


ContextRelease(context @ Gtk.Glib.GMainContext.T) : Std.Object.T

Releases ownership of a context previously acquired by this thread with ContextAcquire. If the context was acquired multiple times, the ownership will be released only when ContextRelease is called as many times as it was acquired.



ContextRemovePoll(context @ Gtk.Glib.GMainContext.T, fd @ Std.Object.T) : Std.Object.T

Removes file descriptor from the set of file descriptors to be polled for a particular context.

context a Gtk.Glib.GMainContext.T
fd a GPollFD descriptor previously added with ContextAddPoll


ContextSetPollFunc(context @ Gtk.Glib.GMainContext.T, func @ Std.Object.T) : Std.Object.T

Sets the function to use to handle polling of file descriptors. It will be used instead of the poll() system call (or GLib's replacement function, which is used where poll() isn't available).

This function could possibly be used to integrate the GLib event loop with an external event loop.

context a Gtk.Glib.GMainContext.T
func the function to call to poll all file descriptors


ContextUnref(context @ Gtk.Glib.GMainContext.T) : Std.Object.T

Decreases the reference count on a Gtk.Glib.GMainContext.T object by one. If the result is zero, free the context and free all associated memory.



ContextWait(context @ Gtk.Glib.GMainContext.T, cond @ Gtk.Glib.GCond.T, mutex @ Gtk.Glib.GMutex.T) : Std.Symbol.T

Tries to become the owner of the specified context, as with ContextAcquire. But if another thread is the owner, atomically drop mutex and wait on cond until that owner releases ownership or until cond is signaled, then try again (once) to become the owner.

context a Gtk.Glib.GMainContext.T
cond a condition variable
mutex a mutex, currently held
Returns TRUE if the operation succeeded, and this thread is now the owner of context.


ContextWakeup(context @ Gtk.Glib.GMainContext.T) : Std.Object.T

If context is currently waiting in a poll(), interrupt the poll(), and continue the iteration process.



CurrentSource() : Gtk.Glib.GSource.T

Returns the currently firing source for this thread.

Returns The currently firing source or NULL. [transfer none]


Depth() : Std.Integer.SmallT

Returns the depth of the stack of calls to ContextDispatch on any Gtk.Glib.GMainContext.T in the current thread. That is, when called from the toplevel, it gives 0. When called from within a callback from ContextIteration (or LoopRun, etc.) it returns 1. When called from within a callback to a recursive call to ContextIteration, it returns 2. And so forth.

This function is useful in a situation like the following: Imagine an extremely simple "garbage collected" system.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
static GList *free_list;

gpointer
allocate_memory (gsize size)
{ 
  gpointer result = g_malloc (size);
  free_list = g_list_prepend (free_list, result);
  return result;
}

void
free_allocated_memory (void)
{
  GList *l;
  for (l = free_list; l; l = l->next);
    g_free (l->data);
  g_list_free (free_list);
  free_list = NULL;
 }

[...]

while (TRUE); 
 {
   g_main_context_iteration (NULL, TRUE);
   free_allocated_memory();
  }


GetCurrentTime(result @ Gtk.Glib.GTimeVal.T) : Std.Object.T

Equivalent to the UNIX gettimeofday() function, but portable.

You may find g_get_real_time() to be more convenient.

result Gtk.Glib.GTimeVal.T structure in which to store current time.


GetMonotonicTime(result @ Gtk.Glib.GTimeSpec.T) : Std.Object.T

Queries the system monotonic time, if available.

On POSIX systems with clock_gettime() and CLOCK_MONOTONIC this call is a very shallow wrapper for that. Otherwise, we make a best effort that probably involves returning the wall clock time (with at least microsecond accuracy, subject to the limitations of the OS kernel).

It's important to note that POSIX CLOCK_MONOTONIC does not count time spent while the machine is suspended.

On Windows, "limitations of the OS kernel" is a rather substantial statement. Depending on the configuration of the system, the wall clock time is updated as infrequently as 64 times a second (which is approximately every 16ms).

Returns the monotonic time, in microseconds


IdleAdd(function @ Std.Function.T, data @ Std.Object.T) : Std.Integer.SmallT

Adds a function to be called whenever there are no higher priority events pending to the default main loop. The function is given the default idle priority, G_PRIORITY_DEFAULT_IDLE. If the function returns FALSE it is automatically removed from the list of event sources and will not be called again.

This internally creates a main loop source using IdleSourceNew and attaches it to the main loop context using SourceAttach. You can do these steps manually if you need greater control.

function function to call
data data to pass to function.
Returns the ID (greater than 0) of the event source.


IdleAddFull(priority @ Std.Integer.SmallT, function @ Std.Function.T, data @ Std.Object.T, notify @ Std.Function.T) : Std.Integer.SmallT

Adds a function to be called whenever there are no higher priority events pending. If the function returns FALSE it is automatically removed from the list of event sources and will not be called again.

This internally creates a main loop source using IdleSourceNew and attaches it to the main loop context using SourceAttach. You can do these steps manually if you need greater control.

priority the priority of the idle source. Typically this will be in the range between G_PRIORITY_DEFAULT_IDLE and G_PRIORITY_HIGH_IDLE.
function function to call
data data to pass to function
notify function to call when the idle is removed, or NULL
Returns the ID (greater than 0) of the event source. Rename to: g_idle_add


IdleRemoveByData(data @ Std.Address.T) : Std.Symbol.T

Removes the idle function with the given data.

data the data for the idle source's callback.
Returns TRUE if an idle source was found and removed.


IdleSourceNew() : Gtk.Glib.GSource.T

Creates a new idle source.

The source will not initially be associated with any Gtk.Glib.GMainContext.T and must be added to one with SourceAttach before it will be executed. Note that the default priority for idle sources is G_PRIORITY_DEFAULT_IDLE, as compared to other sources which have a default priority of G_PRIORITY_DEFAULT.

Returns the newly-created idle source


LoopGetContext(loop @ Gtk.Glib.GMainLoop.T) : Gtk.Glib.GMainContext.T

Returns the Gtk.Glib.GMainContext.T of loop.

loop a Gtk.Glib.GMainLoop.T.
Returns the Gtk.Glib.GMainContext.T of loop. [transfer none]


LoopIsRunning(loop @ Gtk.Glib.GMainLoop.T) : Std.Symbol.T

Checks to see if the main loop is currently being run via LoopRun.

loop a Gtk.Glib.GMainLoop.T.
Returns TRUE if the mainloop is currently being run.


LoopNew(context @ Gtk.Glib.GMainContext.T, is_running @ Std.Symbol.T) : Gtk.Glib.GMainLoop.T

Creates a new Gtk.Glib.GMainLoop.T structure.

context a Gtk.Glib.GMainContext.T (if NULL, the default context will be used). [allow-none]
is_running set to TRUE to indicate that the loop is running. This is not very important since calling LoopRun will set this to TRUE anyway.
Returns a new Gtk.Glib.GMainLoop.T.


LoopQuit(loop @ Gtk.Glib.GMainLoop.T) : Std.Object.T

Stops a Gtk.Glib.GMainLoop.T from running. Any calls to LoopRun for the loop will return.

Note that sources that have already been dispatched when LoopQuit is called will still be executed.



LoopRef(loop @ Gtk.Glib.GMainLoop.T) : Gtk.Glib.GMainLoop.T

Increases the reference count on a Gtk.Glib.GMainLoop.T object by one.

loop a Gtk.Glib.GMainLoop.T
Returns loop


LoopRun(loop @ Gtk.Glib.GMainLoop.T) : Std.Object.T

Runs a main loop until LoopQuit is called on the loop. If this is called for the thread of the loop's Gtk.Glib.GMainContext.T, it will process events from the loop, otherwise it will simply wait.



LoopUnref(loop @ Gtk.Glib.GMainLoop.T) : Std.Object.T

Decreases the reference count on a Gtk.Glib.GMainLoop.T object by one. If the result is zero, free the loop and free all associated memory.



SourceAddPoll(source @ Gtk.Glib.GSource.T, fd @ Std.Object.T) : Std.Object.T

Adds a file descriptor to the set of file descriptors polled for this source. This is usually combined with SourceNew to add an event source. The event source's check function will typically test the revents field in the GPollFD struct and return TRUE if events need to be processed.

source a Gtk.Glib.GSource.T
fd a GPollFD structure holding information about a file descriptor to watch.


SourceAttach(source @ Gtk.Glib.GSource.T, context @ Gtk.Glib.GMainContext.T) : Std.Integer.SmallT

Adds a Gtk.Glib.GSource.T to a context so that it will be executed within that context. Remove it by calling SourceDestroy.

source a Gtk.Glib.GSource.T
context a Gtk.Glib.GMainContext.T (if NULL, the default context will be used)
Returns the ID (greater than 0) for the source within the Gtk.Glib.GMainContext.T.


SourceDestroy(source @ Gtk.Glib.GSource.T) : Std.Object.T

Removes a source from its Gtk.Glib.GMainContext.T, if any, and mark it as destroyed. The source cannot be subsequently added to another context.



SourceGetCanRecurse(source @ Gtk.Glib.GSource.T) : Std.Symbol.T

Checks whether a source is allowed to be called recursively. see SourceSetCanRecurse.

source a Gtk.Glib.GSource.T
Returns whether recursion is allowed.


SourceGetContext(source @ Gtk.Glib.GSource.T) : Gtk.Glib.GMainContext.T

Gets the Gtk.Glib.GMainContext.T with which the source is associated. Calling this function on a destroyed source is an error.

source a Gtk.Glib.GSource.T
Returns the Gtk.Glib.GMainContext.T with which the source is associated, or NULL if the context has not yet been added to a source. [transfer none]


SourceGetCurrentTime(source @ Gtk.Glib.GSource.T, timeval @ Gtk.Glib.GTimeVal.T) : Std.Object.T

Warning

SourceGetCurrentTime has been deprecated since version 2.28 and should not be used in newly-written code. use SourceGetTime instead



SourceGetId(source @ Gtk.Glib.GSource.T) : Std.Integer.SmallT

Returns the numeric ID for a particular source. The ID of a source is a positive integer which is unique within a particular main loop context. The reverse mapping from ID to source is done by ContextFindSourceById.

source a Gtk.Glib.GSource.T
Returns the ID (greater than 0) for the source


SourceGetName(source @ Gtk.Glib.GSource.T) : Std.String.T

Gets a name for the source, used in debugging and profiling. The name may be NULL if it has never been set with SourceSetName.

source a Gtk.Glib.GSource.T
Returns the name of the source


SourceGetPriority(source @ Gtk.Glib.GSource.T) : Std.Integer.SmallT

Gets the priority of a source.

source a Gtk.Glib.GSource.T
Returns the priority of the source


SourceGetTime(source @ Gtk.Glib.GSource.T, timespec @ Gtk.Glib.GTimeSpec.T) : Std.Object.T

Gets the time to be used when checking this source. The advantage of calling this function over calling GetMonotonicTime directly is that when checking multiple sources, GLib can cache a single value instead of having to repeatedly get the system monotonic time.

The time here is the system monotonic time, if available, or some other reasonable alternative otherwise. See GetMonotonicTime.

source a Gtk.Glib.GSource.T
Returns the monotonic time in microseconds


SourceIsDestroyed(source @ Gtk.Glib.GSource.T) : Std.Symbol.T

Returns whether source has been destroyed.

This is important when you operate upon your objects from within idle handlers, but may have freed the object before the dispatch of your idle handler.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
static gboolean 
idle_callback (gpointer data)
{
  SomeWidget *self = data;
   
  GDK_THREADS_ENTER ();
  /* do stuff with self */
  self->idle_id = 0;
  GDK_THREADS_LEAVE ();
   
  return FALSE;
}
 
static void 
some_widget_do_stuff_later (SomeWidget *self)
{
  self->idle_id = g_idle_add (idle_callback, self);
}
 
static void 
some_widget_finalize (GObject *object)
{
  SomeWidget *self = SOME_WIDGET (object);
   
  if (self->idle_id)
    g_source_remove (self->idle_id);
   
  G_OBJECT_CLASS (parent_class)->finalize (object);
}


SourceNew(source_funcs @ Gtk.Glib.GSourceFuncs.T, struct_size @ Std.Integer.SmallT) : Gtk.Glib.GSource.T

Creates a new Gtk.Glib.GSource.T structure. The size is specified to allow creating structures derived from Gtk.Glib.GSource.T that contain additional data. The size passed in must be at least sizeof (GSource).

The source will not initially be associated with any Gtk.Glib.GMainContext.T and must be added to one with SourceAttach before it will be executed.

source_funcs structure containing functions that implement the sources behavior.
struct_size size of the Gtk.Glib.GSource.T structure to create.
Returns the newly-created Gtk.Glib.GSource.T.


SourceRef(source @ Gtk.Glib.GSource.T) : Gtk.Glib.GSource.T

Increases the reference count on a source by one.

source a Gtk.Glib.GSource.T
Returns source


SourceRemove(tag @ Std.Integer.SmallT) : Std.Symbol.T

Removes the source with the given id from the default main context. The id of a Gtk.Glib.GSource.T is given by SourceGetId, or will be returned by the functions SourceAttach, IdleAdd, IdleAddFull, TimeoutAdd, TimeoutAddFull, ChildWatchAdd, ChildWatchAddFull, Gtk.Glib.GIOChannel.AddWatch, and Gtk.Glib.GIOChannel.AddWatchFull.

See also SourceDestroy. You must use SourceDestroy for sources added to a non-default main context.

tag the ID of the source to remove.
Returns TRUE if the source was found and removed.


SourceRemoveByFuncsUserData(funcs @ Gtk.Glib.GSourceFuncs.T, user_data @ Std.Address.T) : Std.Symbol.T

Removes a source from the default main loop context given the source functions and user data. If multiple sources exist with the same source functions and user data, only one will be destroyed.

funcs The source_funcs passed to SourceNew
user_data the user data for the callback
Returns TRUE if a source was found and removed.


SourceRemoveByUserData(user_data @ Std.Address.T) : Std.Symbol.T

Removes a source from the default main loop context given the user data for the callback. If multiple sources exist with the same user data, only one will be destroyed.

user_data the user_data for the callback.
Returns TRUE if a source was found and removed.


SourceRemovePoll(source @ Gtk.Glib.GSource.T, fd @ Std.Object.T) : Std.Object.T

Removes a file descriptor from the set of file descriptors polled for this source.

source a Gtk.Glib.GSource.T
fd a GPollFD structure previously passed to SourceAddPoll.


SourceSetCallback(source @ Gtk.Glib.GSource.T, func @ Std.Function.T, data @ Std.Address.T, notify @ Std.Function.T) : Std.Object.T

Sets the callback function for a source. The callback for a source is called from the source's dispatch function.

The exact type of func depends on the type of source; ie. you should not count on func being called with data as its first parameter.

Typically, you won't use this function. Instead use functions specific to the type of source you are using.

source the source
func a callback function
data the data to pass to callback function
notify a function to call when data is no longer in use, or NULL.


SourceSetCallbackIndirect(source @ Gtk.Glib.GSource.T, callback_data @ Std.Address.T, callback_funcs @ Gtk.Glib.GSourceCallbackFuncs.T) : Std.Object.T

Sets the callback function storing the data as a refcounted callback "object". This is used internally. Note that calling SourceSetCallbackIndirect assumes an initial reference count on callback_data, and thus callback_funcs->unref will eventually be called once more than callback_funcs->ref.

source the source
callback_data pointer to callback data "object"
callback_funcs functions for reference counting callback_data and getting the callback and data


SourceSetCanRecurse(source @ Gtk.Glib.GSource.T, can_recurse @ Std.Symbol.T) : Std.Object.T

Sets whether a source can be called recursively. If can_recurse is TRUE, then while the source is being dispatched then this source will be processed normally. Otherwise, all processing of this source is blocked until the dispatch function returns.

source a Gtk.Glib.GSource.T
can_recurse whether recursion is allowed for this source


SourceSetFuncs(source @ Gtk.Glib.GSource.T, funcs @ Gtk.Glib.GSourceFuncs.T) : Std.Object.T

Sets the source functions (can be used to override default implementations) of an unattached source.



SourceSetName(source @ Gtk.Glib.GSource.T, name @ Std.String.T) : Std.Object.T

Sets a name for the source, used in debugging and profiling. The name defaults to NULL.

The source name should describe in a human-readable way what the source does. For example, "X11 event queue" or "GTK+ repaint idle handler" or whatever it is.

It is permitted to call this function multiple times, but is not recommended due to the potential performance impact. For example, one could change the name in the "check" function of a Gtk.Glib.GSourceFuncs.T to include details like the event type in the source name.

source a Gtk.Glib.GSource.T
name debug name for the source


SourceSetNameById(tag @ Std.Integer.SmallT, name @ Std.String.T) : Std.Object.T

Sets the name of a source using its ID.

This is a convenience utility to set source names from the return value of IdleAdd, TimeoutAdd, etc.

tag a Gtk.Glib.GSource.T ID
name debug name for the source


SourceSetPriority(source @ Gtk.Glib.GSource.T, priority @ Std.Integer.SmallT) : Std.Object.T

Sets the priority of a source. 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.

source a Gtk.Glib.GSource.T
priority the new priority.


SourceUnref(source @ Gtk.Glib.GSource.T) : Std.Object.T

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



TimeoutAdd(interval @ Std.Integer.SmallT, function @ Std.Function.T, data @ Std.Object.T) : Std.Integer.SmallT

Sets a function to be called at regular intervals, with the default priority, G_PRIORITY_DEFAULT. The function is called repeatedly until it returns FALSE, at which point the timeout is automatically destroyed and the function will not be called again. The first call to the function will be at the end of the first interval.

Note that timeout functions may be delayed, due to the processing of other event sources. Thus they should not be relied on for precise timing. After each call to the timeout function, the time of the next timeout is recalculated based on the current time and the given interval (it does not try to 'catch up' time lost in delays).

If you want to have a timer in the "seconds" range and do not care about the exact time of the first call of the timer, use the TimeoutAddSeconds function; this function allows for more optimizations and more efficient system power usage.

This internally creates a main loop source using TimeoutSourceNew and attaches it to the main loop context using SourceAttach. You can do these steps manually if you need greater control.

The interval given is in terms of monotonic time, not wall clock time. See GetMonotonicTime.

interval the time between calls to the function, in milliseconds (1/1000ths of a second)
function function to call
data data to pass to function
Returns the ID (greater than 0) of the event source.


TimeoutAddFull(priority @ Std.Integer.SmallT, interval @ Std.Integer.SmallT, function @ Std.Function.T, data @ Std.Object.T, notify @ Std.Function.T) : Std.Integer.SmallT

Sets a function to be called at regular intervals, with the given priority. The function is called repeatedly until it returns FALSE, at which point the timeout is automatically destroyed and the function will not be called again. The notify function is called when the timeout is destroyed. The first call to the function will be at the end of the first interval.

Note that timeout functions may be delayed, due to the processing of other event sources. Thus they should not be relied on for precise timing. After each call to the timeout function, the time of the next timeout is recalculated based on the current time and the given interval (it does not try to 'catch up' time lost in delays).

This internally creates a main loop source using TimeoutSourceNew and attaches it to the main loop context using SourceAttach. You can do these steps manually if you need greater control.

The interval given in terms of monotonic time, not wall clock time. See GetMonotonicTime.

priority the priority of the timeout source. Typically this will be in the range between G_PRIORITY_DEFAULT and G_PRIORITY_HIGH.
interval the time between calls to the function, in milliseconds (1/1000ths of a second)
function function to call
data data to pass to function
notify function to call when the timeout is removed, or NULL
Returns the ID (greater than 0) of the event source. Rename to: g_timeout_add


TimeoutAddSeconds(interval @ Std.Integer.SmallT, function @ Std.Function.T, data @ Std.Object.T) : Std.Integer.SmallT

Sets a function to be called at regular intervals with the default priority, G_PRIORITY_DEFAULT. The function is called repeatedly until it returns FALSE, at which point the timeout is automatically destroyed and the function will not be called again.

This internally creates a main loop source using TimeoutSourceNewSeconds and attaches it to the main loop context using SourceAttach. You can do these steps manually if you need greater control. Also see TimeoutAddSecondsFull.

Note that the first call of the timer may not be precise for timeouts of one second. If you need finer precision and have such a timeout, you may want to use TimeoutAdd instead.

The interval given is in terms of monotonic time, not wall clock time. See GetMonotonicTime.

interval the time between calls to the function, in seconds
function function to call
data data to pass to function
Returns the ID (greater than 0) of the event source.


TimeoutAddSecondsFull(priority @ Std.Integer.SmallT, interval @ Std.Integer.SmallT, function @ Std.Function.T, data @ Std.Object.T, notify @ Std.Function.T) : Std.Integer.SmallT

Sets a function to be called at regular intervals, with priority. The function is called repeatedly until it returns FALSE, at which point the timeout is automatically destroyed and the function will not be called again.

Unlike TimeoutAdd, this function operates at whole second granularity. The initial starting point of the timer is determined by the implementation and the implementation is expected to group multiple timers together so that they fire all at the same time. To allow this grouping, the interval to the first timer is rounded and can deviate up to one second from the specified interval. Subsequent timer iterations will generally run at the specified interval.

Note that timeout functions may be delayed, due to the processing of other event sources. Thus they should not be relied on for precise timing. After each call to the timeout function, the time of the next timeout is recalculated based on the current time and the given interval

If you want timing more precise than whole seconds, use TimeoutAdd instead.

The grouping of timers to fire at the same time results in a more power and CPU efficient behavior so if your timer is in multiples of seconds and you don't require the first timer exactly one second from now, the use of TimeoutAddSeconds is preferred over TimeoutAdd.

This internally creates a main loop source using TimeoutSourceNewSeconds and attaches it to the main loop context using SourceAttach. You can do these steps manually if you need greater control.

The interval given is in terms of monotonic time, not wall clock time. See GetMonotonicTime.

priority the priority of the timeout source. Typically this will be in the range between G_PRIORITY_DEFAULT and G_PRIORITY_HIGH.
interval the time between calls to the function, in seconds
function function to call
data data to pass to function
notify function to call when the timeout is removed, or NULL
Returns the ID (greater than 0) of the event source. Rename to: g_timeout_add_seconds


TimeoutSourceNew(interval @ Std.Integer.SmallT) : Gtk.Glib.GSource.T

Creates a new timeout source.

The source will not initially be associated with any Gtk.Glib.GMainContext.T and must be added to one with SourceAttach before it will be executed.

The interval given is in terms of monotonic time, not wall clock time. See GetMonotonicTime.

interval the timeout interval in milliseconds.
Returns the newly-created timeout source


TimeoutSourceNewSeconds(interval @ Std.Integer.SmallT) : Gtk.Glib.GSource.T

Creates a new timeout source.

The source will not initially be associated with any Gtk.Glib.GMainContext.T and must be added to one with SourceAttach before it will be executed.

The scheduling granularity/accuracy of this timeout source will be in seconds.

The interval given in terms of monotonic time, not wall clock time. See GetMonotonicTime.

interval the timeout interval in seconds
Returns the newly-created timeout source