|
2 | 2 | module Gtk |
3 | 3 |
|
4 | 4 | # Import binary definitions |
5 | | -using GTK3_jll |
6 | | -using Glib_jll |
7 | | -using gdk_pixbuf_jll |
| 5 | +using GTK3_jll, Glib_jll, gdk_pixbuf_jll, adwaita_icon_theme_jll, gdk_pixbuf_jll |
| 6 | +using Pkg.Artifacts |
8 | 7 | const libgdk = libgdk3 |
9 | 8 | const libgtk = libgtk3 |
10 | 9 |
|
@@ -72,16 +71,44 @@ include("gio.jl") |
72 | 71 | include("application.jl") |
73 | 72 |
|
74 | 73 | function __init__() |
75 | | - # Set up environment variables so that gdk-pixbuf can find its loaders |
76 | | - if get(ENV, "GDK_PIXBUF_MODULEDIR", "") == "" |
77 | | - ENV["GDK_PIXBUF_MODULEDIR"] = joinpath( |
78 | | - dirname(gdk_pixbuf_jll.libgdkpixbuf_path), |
79 | | - "gdk-pixbuf-2.0", |
80 | | - "2.10.0", |
81 | | - "loaders", |
| 74 | + # Set XDG_DATA_DIRS so that Gtk can find its icons and schemas |
| 75 | + ENV["XDG_DATA_DIRS"] = join(filter(x -> x != nothing, [ |
| 76 | + dirname(adwaita_icon_theme_jll.icons_dir), |
| 77 | + joinpath(dirname(GTK3_jll.libgdk3_path), "..", "share"), |
| 78 | + get(ENV, "XDG_DATA_DIRS", nothing), |
| 79 | + ]), ":") |
| 80 | + |
| 81 | + # Next, ensure that gdk-pixbuf has its loaders.cache file; we generate a |
| 82 | + # MutableArtifacts.toml file that maps in a loaders.cache we dynamically |
| 83 | + # generate by running `gdk-pixbuf-query-loaders:` |
| 84 | + mutable_artifacts_toml = joinpath(dirname(@__DIR__), "MutableArtifacts.toml") |
| 85 | + loaders_cache_name = "gdk-pixbuf-loaders-cache" |
| 86 | + loaders_cache_hash = artifact_hash(loaders_cache_name, mutable_artifacts_toml) |
| 87 | + if loaders_cache_hash === nothing |
| 88 | + # Run gdk-pixbuf-query-loaders, capture output, |
| 89 | + loader_cache_contents = gdk_pixbuf_query_loaders() do gpql |
| 90 | + withenv("GDK_PIXBUF_MODULEDIR" => gdk_pixbuf_loaders_dir) do |
| 91 | + return String(read(`$gpql`)) |
| 92 | + end |
| 93 | + end |
| 94 | + |
| 95 | + # Write cache out to file in new artifact |
| 96 | + loaders_cache_hash = create_artifact() do art_dir |
| 97 | + open(joinpath(art_dir, "loaders.cache"), "w") do io |
| 98 | + write(io, loader_cache_contents) |
| 99 | + end |
| 100 | + end |
| 101 | + bind_artifact!(mutable_artifacts_toml, |
| 102 | + loaders_cache_name, |
| 103 | + loaders_cache_hash; |
| 104 | + force=true |
82 | 105 | ) |
83 | 106 | end |
84 | 107 |
|
| 108 | + # Point gdk to our cached loaders |
| 109 | + ENV["GDK_PIXBUF_MODULE_FILE"] = joinpath(artifact_path(loaders_cache_hash), "loaders.cache") |
| 110 | + ENV["GDK_PIXBUF_MODULEDIR"] = gdk_pixbuf_loaders_dir |
| 111 | + |
85 | 112 | GError() do error_check |
86 | 113 | ccall((:gtk_init_with_args, libgtk), Bool, |
87 | 114 | (Ptr{Nothing}, Ptr{Nothing}, Ptr{UInt8}, Ptr{Nothing}, Ptr{UInt8}, Ptr{GError}), |
|
0 commit comments