Skip to content

Commit

Permalink
Allow gtk_init_check to fail (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand authored Feb 15, 2025
1 parent cc368c9 commit cba4a8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 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.7.5"
version = "0.7.6"

[deps]
BitFlags = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
Expand Down
11 changes: 7 additions & 4 deletions src/Gtk4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ function set_EGL_vendorlib_dirs(dirs)
@info("Setting will take effect after restarting Julia.")
end

const initialized = Ref(false) # whether `init_check` succeeded, not necessarily the same as GTK4's `is_initialized`

function __init__()
in("Gtk",[x.name for x in keys(Base.loaded_modules)]) && error("Gtk4 is incompatible with Gtk.")

Expand Down Expand Up @@ -186,8 +188,11 @@ function __init__()
end
end

success = ccall((:gtk_init_check, libgtk4), Cint, ()) != 0
success || error("gtk_init_check() failed.")
initialized[] = ccall((:gtk_init_check, libgtk4), Cint, ()) != 0
if !initialized[]
@warn("Gtk4 initialization failed. Calling Gtk4 methods will cause Julia to crash.")
return
end

if Sys.islinux() || Sys.isfreebsd()
G_.set_default_icon_name("julia")
Expand All @@ -198,8 +203,6 @@ function __init__()
GLib.G_.set_prgname("julia")

isinteractive() && GLib.start_main_loop()

#@debug("Gtk4 initialized.")
end

isinitialized() = G_.is_initialized()
Expand Down

0 comments on commit cba4a8f

Please sign in to comment.