Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Initial shot at using Gtk on Julia 1.3+ #447

Merged
merged 18 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ deps/deps.jl
docs/build
.DS_Store
Manifest.toml
MutableArtifacts.toml

21 changes: 16 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ os:
- linux
- osx
- windows
arch:
- x64
- x86
- arm64
julia:
- 0.7
- 1.0
- 1.2
- 1.3
- nightly
# uncomment the following lines to allow failures on nightly julia
# (tests will run but not make your overall status red)
Expand All @@ -17,6 +19,15 @@ matrix:
- julia: nightly
- os: osx
- stage: "Documentation" # This shouldn't be necessary
exclude:
- os: osx
arch: x86
- os: osx
arch: arm64
- os: windows
arch: arm64
- julia: nightly
arch: arm64
notifications:
email: false
git:
Expand All @@ -26,11 +37,11 @@ addons:
packages:
- xvfb
- xauth
- libgtk-3-dev
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- if [[ `uname` = "Linux" ]]; then TESTCMD="xvfb-run julia"; else TESTCMD="julia"; fi
- $TESTCMD -e 'using Pkg; Pkg.build(); Pkg.test(coverage=true)'
- $TESTCMD -e 'using Pkg; pkg"add https://github.com/staticfloat/Cairo.jl#sf/jll_packages"'
- travis_wait 30 $TESTCMD -e 'using Pkg; Pkg.build(); Pkg.test(coverage=true)'

## uncomment following lines to deploy documentation
jobs:
Expand Down
14 changes: 9 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ uuid = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
version = "0.18.0"

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

[compat]
Cairo = "0.3, 0.4, 0.5, 0.6"
Cairo = " 0.7"
Graphics = "≥ 0.1.0"
julia = "0.7, 1"
julia = "≥ 1.3"
5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
environment:
matrix:
- julia_version: 0.7
- julia_version: 1.0
- julia_version: 1.2
- julia_version: 1.3
- julia_version: nightly

platform:
Expand Down Expand Up @@ -31,6 +29,7 @@ install:

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

test_script:
Expand Down
70 changes: 0 additions & 70 deletions deps/build.jl

This file was deleted.

22 changes: 0 additions & 22 deletions deps/ext_glib.jl

This file was deleted.

5 changes: 3 additions & 2 deletions src/GLib/GLib.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module GLib

# Import `libgobject` and whatnot
using Glib_jll

if false
function include(x)
println("including $x")
Expand Down Expand Up @@ -42,8 +45,6 @@ bytestring(s::Ptr{UInt8}) = unsafe_string(s)
g_malloc(s::Integer) = ccall((:g_malloc, libglib), Ptr{Nothing}, (Csize_t,), s)
g_free(p::Ptr) = ccall((:g_free, libglib), Nothing, (Ptr{Nothing},), p)

include(joinpath("..", "..", "deps", "ext_glib.jl"))

ccall((:g_type_init, libgobject), Nothing, ())

include("MutableTypes.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/GLib/signals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function __init__gmainloop__()
src, @cfunction(g_yield, Cint, (UInt,)), 1, C_NULL)

uv_fd = Sys.iswindows() ? -1 : ccall(:uv_backend_fd, Cint, (Ptr{Nothing},), Base.eventloop())
global uv_pollfd = _GPollFD(uv_fd, typemax(Cushort))
global uv_pollfd = _GPollFD(uv_fd, 0x1)
if (uv_pollfd::_GPollFD).fd != -1
ccall((:g_source_add_poll, GLib.libglib), Nothing, (Ptr{Nothing}, Ptr{_GPollFD}), src, Ref(uv_pollfd::_GPollFD))
end
Expand Down
66 changes: 61 additions & 5 deletions src/Gtk.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# julia Gtk interface
module Gtk

# Import binary definitions
using GTK3_jll, Glib_jll, gdk_pixbuf_jll, adwaita_icon_theme_jll, hicolor_icon_theme_jll
using Pkg.Artifacts
const libgdk = libgdk3
const libgtk = libgtk3


const suffix = :Leaf
include("GLib/GLib.jl")
using .GLib
Expand All @@ -17,11 +24,7 @@ import Base: convert, show, run, size, resize!, length, getindex, setindex!,
parent, isempty, empty!, first, last, in, popfirst!,
eltype, copy, isvalid, string, sigatomic_begin, sigatomic_end, (:), iterate

if VERSION < v"1.0"
import Base: showall, select!, start
else
export showall, select!, start
end
export showall, select!, start

using Reexport
@reexport using Graphics
Expand Down Expand Up @@ -67,6 +70,59 @@ include("theme.jl")
include("gio.jl")
include("application.jl")

function __init__()
# Set XDG_DATA_DIRS so that Gtk can find its icons and schemas
ENV["XDG_DATA_DIRS"] = join(filter(x -> x != nothing, [
dirname(adwaita_icons_dir),
dirname(hicolor_icons_dir),
joinpath(dirname(GTK3_jll.libgdk3_path), "..", "share"),
get(ENV, "XDG_DATA_DIRS", nothing),
]), Sys.iswindows() ? ";" : ":")

# Next, ensure that gdk-pixbuf has its loaders.cache file; we generate a
# MutableArtifacts.toml file that maps in a loaders.cache we dynamically
# generate by running `gdk-pixbuf-query-loaders:`
mutable_artifacts_toml = joinpath(dirname(@__DIR__), "MutableArtifacts.toml")
loaders_cache_name = "gdk-pixbuf-loaders-cache"
loaders_cache_hash = artifact_hash(loaders_cache_name, mutable_artifacts_toml)
if loaders_cache_hash === nothing
# Run gdk-pixbuf-query-loaders, capture output,
loader_cache_contents = gdk_pixbuf_query_loaders() do gpql
withenv("GDK_PIXBUF_MODULEDIR" => gdk_pixbuf_loaders_dir) do
return String(read(`$gpql`))
end
end

# Write cache out to file in new artifact
loaders_cache_hash = create_artifact() do art_dir
open(joinpath(art_dir, "loaders.cache"), "w") do io
write(io, loader_cache_contents)
end
end
bind_artifact!(mutable_artifacts_toml,
loaders_cache_name,
loaders_cache_hash;
force=true
)
end

# Point gdk to our cached loaders
ENV["GDK_PIXBUF_MODULE_FILE"] = joinpath(artifact_path(loaders_cache_hash), "loaders.cache")
ENV["GDK_PIXBUF_MODULEDIR"] = gdk_pixbuf_loaders_dir

GError() do error_check
ccall((:gtk_init_with_args, libgtk), Bool,
(Ptr{Nothing}, Ptr{Nothing}, Ptr{UInt8}, Ptr{Nothing}, Ptr{UInt8}, Ptr{GError}),
C_NULL, C_NULL, "Julia Gtk Bindings", C_NULL, C_NULL, error_check)
end

# if g_main_depth > 0, a glib main-loop is already running,
# so we don't need to start a new one
if ccall((:g_main_depth, GLib.libglib), Cint, ()) == 0
global gtk_main_task = schedule(Task(gtk_main))
end
end

const ser_version = Serialization.ser_version
let cachedir = joinpath(splitdir(@__FILE__)[1], "..", "gen")
fastgtkcache = joinpath(cachedir, "gtk$(libgtk_version.major)_julia_ser$(ser_version)")
Expand Down
4 changes: 2 additions & 2 deletions src/boxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ mutable struct GdkPixbufFormat <: GBoxed
handle::Ptr{GdkPixbufFormat}
function GdkPixbufFormat(ref::Ptr{GdkPixbufFormat}, own::Bool = false)
x = new( own ? ref :
ccall((:gdk_pixbuf_format_copy, Gtk.libgdk_pixbuf), Nothing, (Ptr{GdkPixbufFormat},), ref))
ccall((:gdk_pixbuf_format_copy, Gtk.libgdkpixbuf), Nothing, (Ptr{GdkPixbufFormat},), ref))
finalizer(x, x::GdkPixbufFormat->begin
ccall((:gdk_pixbuf_format_free, Gtk.libgdk_pixbuf), Nothing, (Ptr{GdkPixbufFormat},), x.handle)
ccall((:gdk_pixbuf_format_free, Gtk.libgdkpixbuf), Nothing, (Ptr{GdkPixbufFormat},), x.handle)
end)
path
end
Expand Down
12 changes: 6 additions & 6 deletions src/cairo.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Cairo._jl_libcairo
using Cairo_jll

# GtkCanvas is the plain Gtk drawing canvas built on Cairo.
mutable struct GtkCanvas <: GtkDrawingArea # NOT an @GType
Expand Down Expand Up @@ -99,18 +99,18 @@ function cairo_surface_for(widget::GtkCanvas)
end

function canvas_on_draw_event(::Ptr{GObject}, cc::Ptr{Nothing}, widget::GtkCanvas) # cc is a Cairo context
ccall((:cairo_set_source_surface, _jl_libcairo), Nothing,
ccall((:cairo_set_source_surface, libcairo), Nothing,
(Ptr{Nothing}, Ptr{Nothing}, Float64, Float64), cc, widget.back.ptr, 0, 0)
ccall((:cairo_paint, _jl_libcairo), Nothing, (Ptr{Nothing},), cc)
ccall((:cairo_paint, libcairo), Nothing, (Ptr{Nothing},), cc)
Int32(false) # propagate the event further
end

function canvas_on_expose_event(::Ptr{GObject}, e::Ptr{Nothing}, widget::GtkCanvas) # e is a GdkEventExpose
cc = ccall((:gdk_cairo_create, libgdk), Ptr{Nothing}, (Ptr{Nothing},), gdk_window(widget))
ccall((:cairo_set_source_surface, _jl_libcairo), Nothing,
ccall((:cairo_set_source_surface, libcairo), Nothing,
(Ptr{Nothing}, Ptr{Nothing}, Float64, Float64), cc, widget.back.ptr, 0, 0)
ccall((:cairo_paint, _jl_libcairo), Nothing, (Ptr{Nothing},), cc)
ccall((:cairo_destroy, _jl_libcairo), Nothing, (Ptr{Nothing},), cc)
ccall((:cairo_paint, libcairo), Nothing, (Ptr{Nothing},), cc)
ccall((:cairo_destroy, libcairo), Nothing, (Ptr{Nothing},), cc)
Int32(false) # propagate the event further
end

Expand Down
Loading