Skip to content

Commit b00658d

Browse files
staticfloattknopp
authored andcommitted
Initial shot at using Gtk on Julia 1.3+ (#447)
* Let Gtk.jl use JLL packages instead of BinDeps
1 parent cfcfdf5 commit b00658d

File tree

15 files changed

+128
-163
lines changed

15 files changed

+128
-163
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ deps/deps.jl
33
docs/build
44
.DS_Store
55
Manifest.toml
6+
MutableArtifacts.toml
7+

.travis.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ os:
55
- linux
66
- osx
77
- windows
8+
arch:
9+
- x64
10+
- x86
11+
- arm64
812
julia:
9-
- 0.7
10-
- 1.0
11-
- 1.2
13+
- 1.3
1214
- nightly
1315
# uncomment the following lines to allow failures on nightly julia
1416
# (tests will run but not make your overall status red)
@@ -17,6 +19,15 @@ matrix:
1719
- julia: nightly
1820
- os: osx
1921
- stage: "Documentation" # This shouldn't be necessary
22+
exclude:
23+
- os: osx
24+
arch: x86
25+
- os: osx
26+
arch: arm64
27+
- os: windows
28+
arch: arm64
29+
- julia: nightly
30+
arch: arm64
2031
notifications:
2132
email: false
2233
git:
@@ -26,11 +37,11 @@ addons:
2637
packages:
2738
- xvfb
2839
- xauth
29-
- libgtk-3-dev
3040
script:
3141
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
3242
- if [[ `uname` = "Linux" ]]; then TESTCMD="xvfb-run julia"; else TESTCMD="julia"; fi
33-
- $TESTCMD -e 'using Pkg; Pkg.build(); Pkg.test(coverage=true)'
43+
- $TESTCMD -e 'using Pkg; pkg"add https://github.com/staticfloat/Cairo.jl#sf/jll_packages"'
44+
- travis_wait 30 $TESTCMD -e 'using Pkg; Pkg.build(); Pkg.test(coverage=true)'
3445

3546
## uncomment following lines to deploy documentation
3647
jobs:

Project.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ uuid = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
33
version = "0.18.0"
44

55
[deps]
6-
BinDeps = "9e28174c-4ba2-5203-b857-d8d62c4213ee"
76
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
7+
Cairo_jll = "83423d85-b0ee-5818-9007-b63ccbeb887a"
88
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
9+
GTK3_jll = "77ec8976-b24b-556a-a1bf-49a033a670a6"
10+
Glib_jll = "7746bdde-850d-59dc-9ae8-88ece973131d"
911
Graphics = "a2bd30eb-e257-5431-a919-1863eab51364"
10-
Homebrew = "d9be37ee-ecc9-5288-90f1-b9ca67657a75"
1112
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
13+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1214
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1315
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1416
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
15-
WinRPM = "c17dfb99-b4f7-5aad-8812-456da1ad7187"
17+
adwaita_icon_theme_jll = "b437f822-2cd6-5e08-a15c-8bac984d38ee"
18+
gdk_pixbuf_jll = "da03df04-f53b-5353-a52f-6a8b0620ced0"
19+
hicolor_icon_theme_jll = "059c91fe-1bad-52ad-bddd-f7b78713c282"
1620

1721
[compat]
18-
Cairo = "0.3, 0.4, 0.5, 0.6"
22+
Cairo = " 0.7"
1923
Graphics = "≥ 0.1.0"
20-
julia = "0.7, 1"
24+
julia = "≥ 1.3"

appveyor.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
environment:
22
matrix:
3-
- julia_version: 0.7
4-
- julia_version: 1.0
5-
- julia_version: 1.2
3+
- julia_version: 1.3
64
- julia_version: nightly
75

86
platform:
@@ -31,6 +29,7 @@ install:
3129

3230
build_script:
3331
- echo "%JL_BUILD_SCRIPT%"
32+
- C:\julia\bin\julia -e "using Pkg; pkg\"add https://github.com/staticfloat/Cairo.jl#sf/jll_packages\""
3433
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
3534

3635
test_script:

deps/build.jl

Lines changed: 0 additions & 70 deletions
This file was deleted.

deps/ext_glib.jl

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/GLib/GLib.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module GLib
22

3+
# Import `libgobject` and whatnot
4+
using Glib_jll
5+
36
if false
47
function include(x)
58
println("including $x")
@@ -42,8 +45,6 @@ bytestring(s::Ptr{UInt8}) = unsafe_string(s)
4245
g_malloc(s::Integer) = ccall((:g_malloc, libglib), Ptr{Nothing}, (Csize_t,), s)
4346
g_free(p::Ptr) = ccall((:g_free, libglib), Nothing, (Ptr{Nothing},), p)
4447

45-
include(joinpath("..", "..", "deps", "ext_glib.jl"))
46-
4748
ccall((:g_type_init, libgobject), Nothing, ())
4849

4950
include("MutableTypes.jl")

src/GLib/signals.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ function __init__gmainloop__()
350350
src, @cfunction(g_yield, Cint, (UInt,)), 1, C_NULL)
351351

352352
uv_fd = Sys.iswindows() ? -1 : ccall(:uv_backend_fd, Cint, (Ptr{Nothing},), Base.eventloop())
353-
global uv_pollfd = _GPollFD(uv_fd, typemax(Cushort))
353+
global uv_pollfd = _GPollFD(uv_fd, 0x1)
354354
if (uv_pollfd::_GPollFD).fd != -1
355355
ccall((:g_source_add_poll, GLib.libglib), Nothing, (Ptr{Nothing}, Ptr{_GPollFD}), src, Ref(uv_pollfd::_GPollFD))
356356
end

src/Gtk.jl

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# julia Gtk interface
22
module Gtk
33

4+
# Import binary definitions
5+
using GTK3_jll, Glib_jll, gdk_pixbuf_jll, adwaita_icon_theme_jll, hicolor_icon_theme_jll
6+
using Pkg.Artifacts
7+
const libgdk = libgdk3
8+
const libgtk = libgtk3
9+
10+
411
const suffix = :Leaf
512
include("GLib/GLib.jl")
613
using .GLib
@@ -17,11 +24,7 @@ import Base: convert, show, run, size, resize!, length, getindex, setindex!,
1724
parent, isempty, empty!, first, last, in, popfirst!,
1825
eltype, copy, isvalid, string, sigatomic_begin, sigatomic_end, (:), iterate
1926

20-
if VERSION < v"1.0"
21-
import Base: showall, select!, start
22-
else
23-
export showall, select!, start
24-
end
27+
export showall, select!, start
2528

2629
using Reexport
2730
@reexport using Graphics
@@ -67,6 +70,59 @@ include("theme.jl")
6770
include("gio.jl")
6871
include("application.jl")
6972

73+
function __init__()
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_icons_dir),
77+
dirname(hicolor_icons_dir),
78+
joinpath(dirname(GTK3_jll.libgdk3_path), "..", "share"),
79+
get(ENV, "XDG_DATA_DIRS", nothing),
80+
]), Sys.iswindows() ? ";" : ":")
81+
82+
# Next, ensure that gdk-pixbuf has its loaders.cache file; we generate a
83+
# MutableArtifacts.toml file that maps in a loaders.cache we dynamically
84+
# generate by running `gdk-pixbuf-query-loaders:`
85+
mutable_artifacts_toml = joinpath(dirname(@__DIR__), "MutableArtifacts.toml")
86+
loaders_cache_name = "gdk-pixbuf-loaders-cache"
87+
loaders_cache_hash = artifact_hash(loaders_cache_name, mutable_artifacts_toml)
88+
if loaders_cache_hash === nothing
89+
# Run gdk-pixbuf-query-loaders, capture output,
90+
loader_cache_contents = gdk_pixbuf_query_loaders() do gpql
91+
withenv("GDK_PIXBUF_MODULEDIR" => gdk_pixbuf_loaders_dir) do
92+
return String(read(`$gpql`))
93+
end
94+
end
95+
96+
# Write cache out to file in new artifact
97+
loaders_cache_hash = create_artifact() do art_dir
98+
open(joinpath(art_dir, "loaders.cache"), "w") do io
99+
write(io, loader_cache_contents)
100+
end
101+
end
102+
bind_artifact!(mutable_artifacts_toml,
103+
loaders_cache_name,
104+
loaders_cache_hash;
105+
force=true
106+
)
107+
end
108+
109+
# Point gdk to our cached loaders
110+
ENV["GDK_PIXBUF_MODULE_FILE"] = joinpath(artifact_path(loaders_cache_hash), "loaders.cache")
111+
ENV["GDK_PIXBUF_MODULEDIR"] = gdk_pixbuf_loaders_dir
112+
113+
GError() do error_check
114+
ccall((:gtk_init_with_args, libgtk), Bool,
115+
(Ptr{Nothing}, Ptr{Nothing}, Ptr{UInt8}, Ptr{Nothing}, Ptr{UInt8}, Ptr{GError}),
116+
C_NULL, C_NULL, "Julia Gtk Bindings", C_NULL, C_NULL, error_check)
117+
end
118+
119+
# if g_main_depth > 0, a glib main-loop is already running,
120+
# so we don't need to start a new one
121+
if ccall((:g_main_depth, GLib.libglib), Cint, ()) == 0
122+
global gtk_main_task = schedule(Task(gtk_main))
123+
end
124+
end
125+
70126
const ser_version = Serialization.ser_version
71127
let cachedir = joinpath(splitdir(@__FILE__)[1], "..", "gen")
72128
fastgtkcache = joinpath(cachedir, "gtk$(libgtk_version.major)_julia_ser$(ser_version)")

src/boxes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ mutable struct GdkPixbufFormat <: GBoxed
4141
handle::Ptr{GdkPixbufFormat}
4242
function GdkPixbufFormat(ref::Ptr{GdkPixbufFormat}, own::Bool = false)
4343
x = new( own ? ref :
44-
ccall((:gdk_pixbuf_format_copy, Gtk.libgdk_pixbuf), Nothing, (Ptr{GdkPixbufFormat},), ref))
44+
ccall((:gdk_pixbuf_format_copy, Gtk.libgdkpixbuf), Nothing, (Ptr{GdkPixbufFormat},), ref))
4545
finalizer(x, x::GdkPixbufFormat->begin
46-
ccall((:gdk_pixbuf_format_free, Gtk.libgdk_pixbuf), Nothing, (Ptr{GdkPixbufFormat},), x.handle)
46+
ccall((:gdk_pixbuf_format_free, Gtk.libgdkpixbuf), Nothing, (Ptr{GdkPixbufFormat},), x.handle)
4747
end)
4848
path
4949
end

0 commit comments

Comments
 (0)