Skip to content

Commit

Permalink
reorganize tests, add some docs on preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand committed Aug 5, 2023
1 parent ce3d3c5 commit 3415d04
Show file tree
Hide file tree
Showing 16 changed files with 745 additions and 700 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Gtk4"
uuid = "9db2cae5-386f-4011-9d63-a5602296539b"
version = "0.4.2"
version = "0.5.0"

[deps]
BitFlags = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
Expand Down
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ makedocs(
],
"Gtk.jl to Gtk4.jl" => "diff3to4.md",
"Reference" => ["doc/reference.md",
"doc/GLib_reference.md"
"doc/GLib_reference.md",
"doc/preferences.md"
],
#"GI Reference" => "doc/GI_reference.md"
],
Expand Down
8 changes: 6 additions & 2 deletions docs/src/diff3to4.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ Events such as button presses are handled through "event controllers" in GTK 4.

Dialogs no longer have a `run` method that takes over the GLib main loop while waiting for the user's response.

## For developers
## GLib event loop

All uses of `mutable` from `GLib.MutableTypes` should be replaced by Julia's `Ref`.
The GLib main loop starts automatically if Julia is in an interactive session. If not, you will have to start it by calling `start_main_loop` or by creating a `GtkApplication` and calling `run` (see the example `application.jl`).

## MutableTypes and GValue

All uses of `mutable` from Gtk.jl's `GLib.MutableTypes` should be replaced by Julia's `Ref`.
The type of a `GValue` can be set using `settype!` rather than `setindex!`.

## More information
Expand Down
21 changes: 21 additions & 0 deletions docs/src/doc/preferences.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Preference Settings

Here is a list of preferences for Gtk4 that can be set using Preferences.jl.

## EGL directories (Linux & Wayland)

GTK4 has a few different rendering backends, and by default on Linux it uses one based on OpenGL. Gtk4.jl uses JLL based libraries rather than the ones that come with your Linux distribution, and on Wayland, unfortunately, unless you tell `libglvnd_jll` where to find libEGL, it will be unable to find an OpenGL provider. As a result, on Wayland a Cairo-based fallback backend will be used. This may work fine for you, but it means that `GtkGLArea` will not work. We can tell `libglvnd_jll` where to find libEGL by setting the environment variable `__EGL_VENDOR_LIBRARY_DIRS`. See [here](https://gitlab.freedesktop.org/glvnd/libglvnd/-/blob/master/src/EGL/icd_enumeration.md) for details.

You can point `libglvnd_jll` to a libEGL location using the preference `"EGL_vendorlib_dirs"`:
```julia
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.**
## UV loop integration
GTK relies on an event loop (provided by GLib) to process and handle mouse and keyboard events, while Julia relies on its own event loop (provided by libuv) for IO, timers, etc. Interactions between these event loops can cause REPL lag and can interfere with multithreading performance. Explicit integration of the two loops by creating a libuv event source in the GLib main loop is currently [disabled](https://github.com/JuliaGraphics/Gtk.jl/pull/630) because it caused [slowdowns in multithreaded code](https://github.com/JuliaGraphics/Gtk.jl/issues/503). On some Macs, unfortunately, [REPL lag](https://github.com/JuliaGtk/Gtk4.jl/issues/23) occurs without this explicit integration (explicit in the sense that libuv can insert events in the GLib main loop through its own GSource).
By default, explicit GLib loop integration is only turned on on Macs in an interactive session. You can override this using the preference `"uv_loop_integration"`. If it's set to "enabled", the libuv GSource will be created. If it's set to "disabled", the libuv GSource will not be created, even on Macs in an interactive session. The setting "auto" uses the default behavior. The functions `GLib.set_uv_loop_integration` and `GLib.get_uv_loop_integration` can be used to set and get the preference.
1 change: 1 addition & 0 deletions src/GLib/gio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Base.islink(f::GFile) = (G_.query_file_type(f,FileQueryInfoFlags_NONE,nothing)==
Base.basename(f::GFile) = G_.get_basename(f)
path(f::GFile) = G_.get_path(f)

query_info(f::GFile, attributes="*", flags=FileQueryInfoFlags_NONE) = G_.query_info(f,attributes,flags,nothing)
Base.keys(fi::GFileInfo) = G_.list_attributes(fi,nothing)
function getindex(fi::GFileInfo,att::AbstractString)
typ = G_.get_attribute_type(fi,att)
Expand Down
2 changes: 2 additions & 0 deletions src/GLib/loop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ to stop the timeout.
Related GTK function: [`g_timeout_add`()]($(gtkdoc_func_url("glib","timeout_add")))
"""
function g_timeout_add(cb::Function, interval::Integer, priority=PRIORITY_DEFAULT)
#is_loop_running() || @warn("g_timeout_add needs GLib main loop to be running.")
callback = @cfunction(GSourceFunc, Cint, (Ref{Function},))
ref, deref = gc_ref_closure(cb)
return ccall((:g_timeout_add_full, libglib),Cint,
Expand All @@ -35,6 +36,7 @@ See also [`@idle_add`](@ref).
Related GTK function: [`g_idle_add_full`()]($(gtkdoc_func_url("glib","idle_add_full")))
"""
function g_idle_add(cb::Function, priority=PRIORITY_DEFAULT_IDLE)
#is_loop_running() || @warn("g_idle_add needs GLib main loop to be running.")
callback = @cfunction(GSourceFunc, Cint, (Ref{Function},))
ref, deref = gc_ref_closure(cb)
return ccall((:g_idle_add_full , libglib),Cint,
Expand Down
8 changes: 7 additions & 1 deletion test/gfile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using Test
path=pwd()

f=GLib.GFile(path)
@test basename(f) == "test"
path2=GLib.path(GFile(f))

@test path==path2
Expand All @@ -19,8 +20,13 @@ f2=GLib.G_.dup(GFile(f))
@test ispath(GFile(f))

@test isdir(GFile(f))
@test !isfile(GFile(f))

fi = GLib.G_.query_info(GFile(f),"*",GLib.FileQueryInfoFlags_NONE,nothing)
fi = GLib.query_info(f)
@test fi["standard::name"] == "test"
for k in keys(fi)
q=fi[k]
end
attributes = GLib.G_.list_attributes(fi,nothing)

#fileinfo=Ref{GFileInfo}()
Expand Down
Loading

0 comments on commit 3415d04

Please sign in to comment.