diff --git a/.gitignore b/.gitignore index d173ff58..ceec9d67 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ deps/deps.jl docs/build .DS_Store Manifest.toml +MutableArtifacts.toml + diff --git a/.travis.yml b/.travis.yml index 68387fbc..38ab97c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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) @@ -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: @@ -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: diff --git a/Project.toml b/Project.toml index 605278bc..4c591905 100644 --- a/Project.toml +++ b/Project.toml @@ -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" [compat] -Cairo = "0.3, 0.4, 0.5, 0.6" +Cairo = "≥ 0.7" Graphics = "≥ 0.1.0" -julia = "0.7, 1" +julia = "≥ 1.3" diff --git a/appveyor.yml b/appveyor.yml index 1738a2d8..9f311fe0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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: @@ -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: diff --git a/deps/build.jl b/deps/build.jl deleted file mode 100755 index 0feaa6d7..00000000 --- a/deps/build.jl +++ /dev/null @@ -1,70 +0,0 @@ -using BinDeps - -@BinDeps.setup - -group = library_group("gtk") - -glib = library_dependency("glib", aliases = ["libglib-2.0", "libglib-2.0-0"], group = group) -gobject = library_dependency("gobject", aliases = ["libgobject-2.0", "libgobject-2.0-0"], group = group) -gtk = library_dependency("gtk", aliases = ["libgtk-3", "libgtk-3-0"], group = group) -gdk = library_dependency("gdk", aliases = ["libgdk-3", "libgdk-3-0"], group = group) -# for gtk2 use these two lines instead of the previous two -#gtk = library_dependency("gtk", aliases = ["libgtk-quartz-2.0", "libgtk-win32-2.0-0", "libgtk-x11-2.0"], group = group) -#gdk = library_dependency("gdk", aliases = ["libgdk-quartz-2.0", "libgdk-win32-2.0-0", "libgdk-x11-2.0"], group = group) -gdk_pixbuf = library_dependency("gdk_pixbuf", aliases = ["libgdk_pixbuf-2.0", "libgdk_pixbuf-2.0-0"], group = group) -gio = library_dependency("gio", aliases = ["libgio-2.0", "libgio-2.0-0"], group = group) - -deps = [glib, gobject, gtk, gdk, gdk_pixbuf, gio] - -if Sys.islinux() - provides(AptGet, "libgtk-3-dev", deps) - provides(Yum, "gtk3", deps) -end - -if Sys.iswindows() - using WinRPM - provides(WinRPM.RPM,"libgtk-3-0", [gtk,gdk,gdk_pixbuf,glib,gio], os = :Windows) - provides(WinRPM.RPM,"libgobject-2_0-0", [gobject], os = :Windows) - - # install some other quasi-required packages - WinRPM.install([ - "glib2-tools","gtk3-tools","gtk2-tools", - "pango-tools","gdk-pixbuf-query-loaders", - "hicolor-icon-theme","tango-icon-theme", - "gnome-icon-theme","gnome-icon-theme-extras", - "gnome-icon-theme-symbolic",]; - yes = !isinteractive()) # don't prompt for unattended installs - - # compile the schemas - libdir = joinpath(dirname(pathof(WinRPM)), "..", "deps","usr","$(Sys.ARCH)-w64-mingw32","sys-root","mingw","bin") - run(`$libdir/glib-compile-schemas $libdir/../share/glib-2.0/schemas`) -end - -if Sys.isapple() - using Homebrew - provides(Homebrew.HB, "gtk+3", [gtk, gdk, gobject], os = :Darwin, onload = - """ - function __init__bindeps__() - if "XDG_DATA_DIRS" in keys(ENV) - ENV["XDG_DATA_DIRS"] *= ":" * joinpath("$(Homebrew.brew_prefix)", "share") - else - ENV["XDG_DATA_DIRS"] = joinpath("$(Homebrew.brew_prefix)", "share") - end - ENV["GDK_PIXBUF_MODULEDIR"] = joinpath("$(Homebrew.brew_prefix)", "lib/gdk-pixbuf-2.0/2.10.0/loaders") - ENV["GDK_PIXBUF_MODULE_FILE"] = joinpath("$(Homebrew.brew_prefix)", "lib/gdk-pixbuf-2.0/2.10.0/loaders.cache") - run(`$(joinpath("$(Homebrew.brew_prefix)", "bin/gdk-pixbuf-query-loaders")) --update-cache`) - end - """) - provides(Homebrew.HB, "glib", [glib, gio], os = :Darwin) - provides(Homebrew.HB, "gdk-pixbuf", gdk_pixbuf, os = :Darwin) - Homebrew.add("adwaita-icon-theme") -end - -@BinDeps.install Dict([ - (:glib, :libglib), - (:gobject, :libgobject), - (:gtk, :libgtk), - (:gdk, :libgdk), - (:gdk_pixbuf, :libgdk_pixbuf), - (:gio, :libgio), -]) diff --git a/deps/ext_glib.jl b/deps/ext_glib.jl deleted file mode 100644 index 6548cfde..00000000 --- a/deps/ext_glib.jl +++ /dev/null @@ -1,22 +0,0 @@ -const _depspath = joinpath(dirname(@__FILE__), "deps.jl") - -if isfile(_depspath) - include(_depspath) -end - -const KERNEL = Base.Sys.KERNEL - -if !isdefined(@__MODULE__, :libgobject) - if KERNEL == :Windows || KERNEL == :NT - const libgobject = "libgobject-2.0-0" - else - const libgobject = "libgobject-2.0" - end -end -if !isdefined(@__MODULE__, :libglib) - if KERNEL == :Windows || KERNEL == :NT - const libglib = "libglib-2.0-0" - else - const libglib = "libglib-2.0" - end -end diff --git a/src/GLib/GLib.jl b/src/GLib/GLib.jl index db955b6b..40b58da7 100644 --- a/src/GLib/GLib.jl +++ b/src/GLib/GLib.jl @@ -1,5 +1,8 @@ module GLib +# Import `libgobject` and whatnot +using Glib_jll + if false function include(x) println("including $x") @@ -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") diff --git a/src/GLib/signals.jl b/src/GLib/signals.jl index e8c779a2..c3cc42f9 100644 --- a/src/GLib/signals.jl +++ b/src/GLib/signals.jl @@ -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 diff --git a/src/Gtk.jl b/src/Gtk.jl index d04eee24..d3512134 100644 --- a/src/Gtk.jl +++ b/src/Gtk.jl @@ -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 @@ -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 @@ -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)") diff --git a/src/boxes.jl b/src/boxes.jl index c9e5783e..c1f73cd3 100644 --- a/src/boxes.jl +++ b/src/boxes.jl @@ -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 diff --git a/src/cairo.jl b/src/cairo.jl index c6ab77a7..45cdf79b 100644 --- a/src/cairo.jl +++ b/src/cairo.jl @@ -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 @@ -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 diff --git a/src/displays.jl b/src/displays.jl index 66ccf8e1..b76edae7 100644 --- a/src/displays.jl +++ b/src/displays.jl @@ -167,9 +167,9 @@ function GdkPixbufLeaf(; stream = nothing, resource_path = nothing, filename = n elseif resource_path !== nothing GError() do error_check if width == -1 && height == -1 - pixbuf = ccall((:gdk_pixbuf_new_from_resource, libgdk_pixbuf), Ptr{GObject}, (Ptr{UInt8}, Ptr{Ptr{GError}}), bytestring(resource_path), error_check) + pixbuf = ccall((:gdk_pixbuf_new_from_resource, libgdkpixbuf), Ptr{GObject}, (Ptr{UInt8}, Ptr{Ptr{GError}}), bytestring(resource_path), error_check) else - pixbuf = ccall((:gdk_pixbuf_new_from_resource_at_scale, libgdk_pixbuf), Ptr{GObject}, + pixbuf = ccall((:gdk_pixbuf_new_from_resource_at_scale, libgdkpixbuf), Ptr{GObject}, (Ptr{UInt8}, Cint, Cint, Cint, Ptr{Ptr{GError}}), bytestring(resource_path), width, height, preserve_aspect_ratio, error_check) end return pixbuf !== C_NULL @@ -177,9 +177,9 @@ function GdkPixbufLeaf(; stream = nothing, resource_path = nothing, filename = n elseif filename !== nothing GError() do error_check if width == -1 && height == -1 - pixbuf = ccall((:gdk_pixbuf_new_from_file, libgdk_pixbuf), Ptr{GObject}, (Ptr{UInt8}, Ptr{Ptr{GError}}), bytestring(filename), error_check) + pixbuf = ccall((:gdk_pixbuf_new_from_file, libgdkpixbuf), Ptr{GObject}, (Ptr{UInt8}, Ptr{Ptr{GError}}), bytestring(filename), error_check) else - pixbuf = ccall((:gdk_pixbuf_new_from_file_at_scale, libgdk_pixbuf), Ptr{GObject}, + pixbuf = ccall((:gdk_pixbuf_new_from_file_at_scale, libgdkpixbuf), Ptr{GObject}, (Ptr{UInt8}, Cint, Cint, Cint, Ptr{Ptr{GError}}), bytestring(filename), width, height, preserve_aspect_ratio, error_check) end return pixbuf !== C_NULL @@ -187,13 +187,13 @@ function GdkPixbufLeaf(; stream = nothing, resource_path = nothing, filename = n elseif xpm_data !== nothing @assert(width == -1 && height == -1, "GdkPixbuf cannot set the width/height of a image from xpm_data") GError() do error_check - pixbuf = ccall((:gdk_pixbuf_new_from_xpm_data, libgdk_pixbuf), Ptr{GObject}, (Ptr{Ptr{Nothing}},), xpm_data) + pixbuf = ccall((:gdk_pixbuf_new_from_xpm_data, libgdkpixbuf), Ptr{GObject}, (Ptr{Ptr{Nothing}},), xpm_data) return pixbuf !== C_NULL end elseif inline_data !== nothing @assert(width == -1 && height == -1, "GdkPixbuf cannot set the width/height of a image from inline_data") GError() do error_check - pixbuf = ccall((:gdk_pixbuf_new_from_inline, libgdk_pixbuf), Ptr{GObject}, (Cint, Ptr{Nothing}, Cint, Ptr{Ptr{GError}}), sizeof(inline_data), inline_data, true, error_check) + pixbuf = ccall((:gdk_pixbuf_new_from_inline, libgdkpixbuf), Ptr{GObject}, (Cint, Ptr{Nothing}, Cint, Ptr{Ptr{GError}}), sizeof(inline_data), inline_data, true, error_check) return pixbuf !== C_NULL end elseif data !== nothing # RGB or RGBA array, packed however you wish @@ -202,14 +202,14 @@ function GdkPixbufLeaf(; stream = nothing, resource_path = nothing, filename = n width = size(data, 1) * bstride(data, 1)/(3 + Int(alpha)) height = size(data, 2) ref_data, deref_data = GLib.gc_ref_closure(data) - pixbuf = ccall((:gdk_pixbuf_new_from_data, libgdk_pixbuf), Ptr{GObject}, + pixbuf = ccall((:gdk_pixbuf_new_from_data, libgdkpixbuf), Ptr{GObject}, (Ptr{Nothing}, Cint, Cint, Cint, Cint, Cint, Cint, Ptr{Nothing}, Ptr{Nothing}), data, 0, alpha, 8, width, height, bstride(data, 2), deref_data, ref_data) else @assert(width != -1 && height != -1, "GdkPixbuf requires a width, height, and has_alpha to create an uninitialized pixbuf") alpha = convert(Bool, has_alpha) - pixbuf = ccall((:gdk_pixbuf_new, libgdk_pixbuf), Ptr{GObject}, + pixbuf = ccall((:gdk_pixbuf_new, libgdkpixbuf), Ptr{GObject}, (Cint, Cint, Cint, Cint, Cint), 0, alpha, 8, width, height) end return GdkPixbufLeaf(pixbuf) @@ -217,28 +217,28 @@ end #GdkPixbufLoader for new with type/mimetype #GdkPixbuf(callback, stream, width = -1, height = -1, preserve_aspect_ratio = true) -copy(img::GdkPixbuf) = GdkPixbufLeaf(ccall((:gdk_pixbuf_copy, libgdk_pixbuf), Ptr{GObject}, (Ptr{GObject},), img)) -slice(img::GdkPixbuf, x, y) = GdkPixbufLeaf(ccall((:gdk_pixbuf_new_subpixbuf, libgdk_pixbuf), Ptr{GObject}, +copy(img::GdkPixbuf) = GdkPixbufLeaf(ccall((:gdk_pixbuf_copy, libgdkpixbuf), Ptr{GObject}, (Ptr{GObject},), img)) +slice(img::GdkPixbuf, x, y) = GdkPixbufLeaf(ccall((:gdk_pixbuf_new_subpixbuf, libgdkpixbuf), Ptr{GObject}, (Ptr{GObject}, Cint, Cint, Cint, Cint), img, first(x)-1, first(y)-1, length(x), length(y))) -width(img::GdkPixbuf) = ccall((:gdk_pixbuf_get_width, libgdk_pixbuf), Cint, (Ptr{GObject},), img) -height(img::GdkPixbuf) = ccall((:gdk_pixbuf_get_height, libgdk_pixbuf), Cint, (Ptr{GObject},), img) +width(img::GdkPixbuf) = ccall((:gdk_pixbuf_get_width, libgdkpixbuf), Cint, (Ptr{GObject},), img) +height(img::GdkPixbuf) = ccall((:gdk_pixbuf_get_height, libgdkpixbuf), Cint, (Ptr{GObject},), img) size(a::GdkPixbuf, i::Integer) = (i == 1 ? width(a) : (i == 2 ? height(a) : 1)) size(a::GdkPixbuf) = (width(a), height(a)) Base.ndims(::GdkPixbuf) = 2 function bstride(img::GdkPixbuf, i) if i == 1 - convert(Cint, div(ccall((:gdk_pixbuf_get_bits_per_sample, libgdk_pixbuf), Cint, (Ptr{GObject},), img) * - ccall((:gdk_pixbuf_get_n_channels, libgdk_pixbuf), Cint, (Ptr{GObject},), img) + 7, 8)) + convert(Cint, div(ccall((:gdk_pixbuf_get_bits_per_sample, libgdkpixbuf), Cint, (Ptr{GObject},), img) * + ccall((:gdk_pixbuf_get_n_channels, libgdkpixbuf), Cint, (Ptr{GObject},), img) + 7, 8)) elseif i == 2 - ccall((:gdk_pixbuf_get_rowstride, libgdk_pixbuf), Cint, (Ptr{GObject},), img) + ccall((:gdk_pixbuf_get_rowstride, libgdkpixbuf), Cint, (Ptr{GObject},), img) else convert(Cint, 0) end end function eltype(img::GdkPixbuf) #nbytes = stride(img, 1) - nbytes = convert(Cint, div(ccall((:gdk_pixbuf_get_bits_per_sample, libgdk_pixbuf), Cint, (Ptr{GObject},), img) * - ccall((:gdk_pixbuf_get_n_channels, libgdk_pixbuf), Cint, (Ptr{GObject},), img) + 7, 8)) + nbytes = convert(Cint, div(ccall((:gdk_pixbuf_get_bits_per_sample, libgdkpixbuf), Cint, (Ptr{GObject},), img) * + ccall((:gdk_pixbuf_get_n_channels, libgdkpixbuf), Cint, (Ptr{GObject},), img) + 7, 8)) if nbytes == 3 RGB elseif nbytes == 4 @@ -249,9 +249,9 @@ function eltype(img::GdkPixbuf) end function convert(::Type{MatrixStrided}, img::GdkPixbuf) MatrixStrided( - convert(Ptr{eltype(img)}, ccall((:gdk_pixbuf_get_pixels, libgdk_pixbuf), Ptr{Nothing}, (Ptr{GObject},), img)), + convert(Ptr{eltype(img)}, ccall((:gdk_pixbuf_get_pixels, libgdkpixbuf), Ptr{Nothing}, (Ptr{GObject},), img)), width = width(img), height = height(img), - rowstride = ccall((:gdk_pixbuf_get_rowstride, libgdk_pixbuf), Cint, (Ptr{GObject},), img)) + rowstride = ccall((:gdk_pixbuf_get_rowstride, libgdkpixbuf), Cint, (Ptr{GObject},), img)) end getindex(img::GdkPixbuf, x::Index, y::Index) = convert(MatrixStrided, img)[x, y] setindex!(img::GdkPixbuf, pix, x::Index, y::Index) = setindex!(convert(MatrixStrided, img), pix, x, y) diff --git a/src/events.jl b/src/events.jl index f875b1c4..5552a98f 100644 --- a/src/events.jl +++ b/src/events.jl @@ -6,24 +6,6 @@ function gtk_quit() ccall((:gtk_main_quit, libgtk), Nothing, ()) end -function __init__() - 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 Sys.iswindows() - @warn "You are using Gtk on Windows which is currently buggy. Expect your REPL/IDE and anything depending on task switches become sluggish." - 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 - - add_events(widget::GtkWidget, mask::Integer) = ccall((:gtk_widget_add_events, libgtk), Nothing, (Ptr{GObject}, GEnum), widget, mask) # widget[:event] = function(ptr, obj) diff --git a/src/gtktypes.jl b/src/gtktypes.jl index b5ae68e3..8c85afcb 100644 --- a/src/gtktypes.jl +++ b/src/gtktypes.jl @@ -111,7 +111,7 @@ end @gtktype GtkAboutDialog @gtktype GtkMessageDialog @Gtype GApplication libgio g_application -@Gtype GdkPixbuf libgdk_pixbuf gdk_pixbuf +@Gtype GdkPixbuf libgdkpixbuf gdk_pixbuf #TODO: @gtktype GtkScaleButton @gtktype GtkApplication diff --git a/test/gui.jl b/test/gui.jl index 72e0a721..cd379bba 100755 --- a/test/gui.jl +++ b/test/gui.jl @@ -51,8 +51,10 @@ end @testset "gui" begin wdth, hght = screen_size() -@test wdth > 0 && hght > 0 - +if !Sys.iswindows() + @test wdth > 0 && hght > 0 +end + @testset "Window" begin w = Window("Window", 400, 300) |> showall if !Sys.iswindows() @@ -60,9 +62,9 @@ if !Sys.iswindows() @test width(w) == 400 @test height(w) == 300 @test size(w) == (400, 300) + wdth, hght = screen_size(w) + @test wdth > 0 && hght > 0 end -wdth, hght = screen_size(w) -@test wdth > 0 && hght > 0 G_.gravity(w,10) #GRAVITY_STATIC sleep(0.1) ## Check Window positions