GLib Reference

The GLib submodule wraps functions and types in the GLib (libglib), GObject (libgobject), and Gio (libgio) C libraries. Julia users probably don't care where things are defined in the C libraries, but we organize things in this documentation according to that same scheme to mirror the C API documentation, which is the ultimate source of information for understanding how and why things work.

The GLib library contains functions and types that are useful for writing C code, but most are not useful in Julia because they duplicate functionality in Julia's Base library. The important functions in GLib for users of this package concern the GLib event loop, the GVariant type, and error/warning message handling.

Event loop

The GLib event loop is used by GTK to schedule and coordinate user input, drawing, etc. much like Julia uses the libuv event loop. Gtk4.jl inherited Gtk.jl's integration of the two event loops. There are situations when you may want to stop or pause the GLib main loop (for example, ProfileView.jl does this while running @profile). There are also many cases when you have to be careful about how to call functions because some of the API is not thread safe.

Gtk4.GLib.pause_main_loopFunction
pause_main_loop(f)

Pauses the GLib event loop around a function. Restores the original state of the event loop after calling the function. This function does not pause the event loop if it is being run by a GApplication.

source
Gtk4.GLib.start_main_loopFunction
start_main_loop(wait=false)

If the default GLib main event loop is not already running, start a Julia task that runs it. Returns the task. If wait is true, it will block until the main loop starts running.

See also stop_main_loop.

source
Gtk4.GLib.stop_main_loopFunction
stop_main_loop(wait=false)

Stops the default GLib main loop after the next iteration. If wait is true, it will block until the main loop stops running.

Does not affect loop operation if GApplication's run() method is being used instead of GLib.start_main_loop().

See also start_main_loop.

source
Gtk4.GLib.@idle_addMacro
@idle_add(ex)

Create a function from an expression ex that will be called when there are no higher priority GTK events to be processed. This function can be used from any thread.

See also g_idle_add.

Related GTK function: g_idle_add()

source
Gtk4.GLib.g_idle_addFunction
g_idle_add(f, priority=PRIORITY_DEFAULT_IDLE)

Add a Julia function f that will be called when there are no higher priority GTK events to be processed. This function can be used from any thread. The optional priority argument, which is an integer, sets the priority of the event source (smaller is higher priority). The GLib main loop uses this priority value to decide what sources to handle next.

See also @idle_add.

Related GTK function: g_idle_add_full()

source
Gtk4.GLib.g_timeout_addFunction
g_timeout_add(f, interval, priority=PRIORITY_DEFAULT)

Add a function f that will be called every interval milliseconds by the GTK main loop. If the function returns true, it will be called again after another interval milliseconds. If it returns false it will not be called again. The optional priority argument, which is an integer, sets the priority of the event source (smaller is higher priority). The GLib main loop uses this priority value to decide what sources to handle next.

This function returns an event source ID that can be used with g_source_remove to stop the timeout externally.

Related GTK function: g_timeout_add()

source
Gtk4.GLib.g_source_removeFunction
g_source_remove(id::Integer)

Remove the event source identified by id from the GLib main loop. The id is returned by g_idle_add and g_timeout_add. The main loop reuses id's so care should be taken that the source intended to be removed is still active.

Related GTK function: g_source_remove()

source
Gtk4.GLib.set_uv_loop_integrationFunction
set_uv_loop_integration(s = "auto")

Change Gtk4.jl's libuv loop integration setting. The argument s should be "auto" to use Gtk4.jl's default setting or "enabled" or "disabled" to override this. This setting will take effect after restarting Julia.

Enabling libuv loop integration may improve REPL response on some platforms (Mac) but negatively impacts multithreaded performance. This function has no effect when running on Windows.

source

GVariant

The GVariant type is used as a container in the Actions system. The types that can be stored and accessed in Gtk4.jl are currently: Bool, UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64, Float64, String, and tuples containing these.

The only time you're going to need to deal with GVariants is when you create them to use as a parameter or to set the state of an action, or access values within GVariants in action handlers.

Gtk4.GLib.GVariantType
GVariant(x)

Create a GVariant that contains the value x. This is a container used to pass parameters and store states in GLib's action system.

The value is accessed from a GVariant gv using gv[t], where t is the Julia type. For example, to access a boolean inside a GVariant, use gv[Bool].

source

Message handling

GLib has a facility for emitting informational messages, warnings, and critical warnings. When C functions emit these they show up in the Julia REPL. In many cases these are unavoidable or at least pretty harmless, and they are a common source of complaints from users of Gtk4 or downstream packages. One can filter these out by providing a "log writer" function.

Gtk4.GLib.suppress_C_messagesFunction
suppress_C_messages()

Sets the preference "C_message_handling" to "suppress_all", which intercepts all messages from the C libraries and stores them in an internal buffer. This setting will take effect the next time Julia is started.

The stored messages can be found in GLib.C_message_buffer.

See also show_C_messages.

source
Gtk4.GLib.show_C_messagesFunction
show_C_messages()

Sets the preference "C_message_handling" to "", which allows messages and warnings from the C libraries to be displayed. This setting will take effect the next time Julia is started.

See also suppress_C_messages.

source
Gtk4.GLib.set_log_writer_funcFunction
set_log_writer_func(log_func)

Sets a function that is used to handle messages. The function should be of the form log_func(log_level,fields) and should return true if the message was handled and otherwise false.

This function must be called only once per Julia session.

source