Gtk4.jl

Julia package for Gtk4 using GObject introspection
Author JuliaGtk
Popularity
54 Stars
Updated Last
2 Months Ago
Started In
November 2021

Julia interface to GTK version 4

CI codecov.io

GUI building using GTK version 4. See Gtk.jl for an unmaintained Julia package that wraps GTK version 3. Note that Gtk.jl and Gtk4.jl cannot be imported in the same Julia session.

This package builds on Gtk.jl but uses GObject introspection to support more of the functionality of the GTK library and its dependencies. Libraries that are wrapped by this package include libglib, libgobject, and libgio (all in the GLib submodule), libpango (in the Pango submodule), libgdkpixbuf (in the GdkPixbufLib submodule), and libgdk4, libgsk4, and libgtk4 (in the main Gtk4 module). GObject introspection for Julia is implemented using GI.jl, which is also hosted in this repository.

Documentation for the master branch version of this package can be found here. Example code can be found here. Complete GTK documentation is available at https://www.gtk.org/docs.

Package scope and alternatives

This package is intended to be a relatively thin wrapper of the GTK library based largely on GObject introspection, analogous to PyGObject. Using it beyond simple widgets requires some knowledge of the GTK API (the Gtk4.jl documentation covers a small fraction of the API available through introspection). It is also very possible to crash or freeze Julia if you're not careful.

Those seeking a more user friendly, well documented, curated GUI building experience based on GTK should consider using Mousetrap. Other popular packages for creating desktop GUI interfaces include QML.jl, Blink.jl, Electron.jl, and CImGui.jl.

Related packages

Other registered packages extend the functionality of Gtk4.jl:

  • GtkObservables.jl: provides integration with Observables.jl. This package can simplify making interactive GUI's with Gtk4.jl.
  • Gtk4Makie.jl: provides integration with the popular plotting package Makie.jl, specifically its interactive, high performance GLMakie backend.

Current status

For auto-generated code, Gtk4.jl relies on GObject introspection data generated on a Linux x86_64 machine, which may result in code that crashes on 32 bit computers. This mostly seems to affect obscure parts of GLib that are unlikely to be useful to Julia users, but 32 bit users should be aware of this.

Note that this package uses binaries for the GTK library and its dependencies that are built and packaged using BinaryBuilder.jl. On Linux it does not use the binaries that are packaged with your distribution. The build scripts for the binaries used by Gtk4.jl, including the library versions currently being used, can be found by perusing Yggdrasil.jl.

Known incompatibilities

Gtk4.jl can interfere with PyPlot.jl. Calling Gtk4 functions before PyPlot functions seems to work better, and changing the PyPlot backend to one that does not involve GTK (any version) may prevent issues. Gtk4.jl has also been reported to interfere with GLMakie.jl, though this doesn't always seem to happen. To use Gtk4 based packages with Makie, you can use Gtk4Makie.jl.

Enabling GTK4's EGL backend (Linux)

On Wayland, a Cairo-based fallback backend will be used unless you tell libglvnd_jll where to find libEGL. This can be done by setting the environment variable __EGL_VENDOR_LIBRARY_DIRS. See here for details.

For convenience, in Gtk4.jl this can be set as a preference for a particular Julia environment using Preferences.jl:

using Gtk4
Gtk4.set_EGL_vendorlib_dirs("/usr/share/glvnd/egl_vendor.d")
[ Info: Setting will take effect after restarting Julia.

where "/usr/share/glvnd/egl_vendor.d" is a typical location for Mesa's libEGL (this should be modified if it's somewhere else on your distribution). Other vendor-provided libraries may be in other locations, and a colon-separated list of directories can be used for that situation. Note that this has only been tested for the Mesa-provided libEGL on Fedora and Ubuntu.