Skip to content

Commit

Permalink
GI-generated signals for a GObject's interfaces
Browse files Browse the repository at this point in the history
also add a few tests
  • Loading branch information
jwahlstrand committed Oct 29, 2023
1 parent f3285f2 commit fd5b527
Show file tree
Hide file tree
Showing 8 changed files with 819 additions and 68 deletions.
4 changes: 2 additions & 2 deletions GI/src/giexport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ function all_object_signals!(exprs,ns;skiplist=Symbol[],object_skiplist=Symbol[]
if in(name,object_skiplist)
continue
end
signals = get_signals(o)
signals = get_all_signals(o)
for s in signals
(exclude_deprecated && is_deprecated(s)) && continue
push!(exprs, decl(s))
push!(exprs, decl(s,o))
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions GI/src/giimport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ function gobject_decl(objectinfo)
end
push!(exprs, decl)
# if there are signals, add "signal_return_type" method, and "signal_arg_types" method
signals = get_signals(objectinfo)
signals = get_all_signals(objectinfo)
sigdict = signal_dict_incl_parents(objectinfo)
if length(signals)>0
signalnames = [Symbol(replace(String(sname),"-"=>"_")) for sname in get_name.(signals)]
Expand Down Expand Up @@ -450,14 +450,14 @@ function get_arg_types(signalinfo::GISignalInfo)
end

## Signal output
function decl(signalinfo::GISignalInfo)
function decl(signalinfo::GISignalInfo, objectinfo=nothing)
name = get_name(signalinfo)
fname=Symbol(replace(String(name),"-"=>"_"))
oname = Symbol("on_$fname")
rettypefunc = Symbol("$(fname)_signal_return_type")
typeargsfunc = Symbol("$(fname)_signal_arg_types")
@assert is_method(signalinfo)
object = get_container(signalinfo)
object = isnothing(objectinfo) ? get_container(signalinfo) : objectinfo
@assert object !== nothing
objtypeinfo = extract_type(InstanceType,object)
rettype = get_ret_type(signalinfo)
Expand Down
9 changes: 9 additions & 0 deletions GI/src/girepo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ function get_properties(info::GIInterfaceInfo)
(Ptr{GIBaseInfo}, Cint), info, i)) for i=0:n-1]
end

# including the interfaces
function get_all_signals(info::GIObjectInfo)
sigs = get_signals(info)
for interf in get_interfaces(info)
append!(sigs, get_signals(interf))
end
sigs
end

getindex(info::GIRegisteredTypeInfo, name::Symbol) = find_method(info, name)

# one->one
Expand Down
48 changes: 45 additions & 3 deletions src/gen/gdk4_structs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,15 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GdkTexture})
signalnames(supertype(GdkTexture))
vcat([:invalidate_contents, :invalidate_size], signalnames(supertype(GdkTexture)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GdkTexture
eval((d[name])[1])
end
function GLib.signal_argument_types(::Type{T}, name::Symbol) where T <: GdkTexture
Tuple(eval.((d[name])[2]))
end
end
end
begin
Expand All @@ -743,7 +751,15 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GdkGLTexture})
signalnames(supertype(GdkGLTexture))
vcat([:invalidate_contents, :invalidate_size], signalnames(supertype(GdkGLTexture)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GdkGLTexture
eval((d[name])[1])
end
function GLib.signal_argument_types(::Type{T}, name::Symbol) where T <: GdkGLTexture
Tuple(eval.((d[name])[2]))
end
end
end
begin
Expand Down Expand Up @@ -781,7 +797,15 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GdkMemoryTexture})
signalnames(supertype(GdkMemoryTexture))
vcat([:invalidate_contents, :invalidate_size], signalnames(supertype(GdkMemoryTexture)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GdkMemoryTexture
eval((d[name])[1])
end
function GLib.signal_argument_types(::Type{T}, name::Symbol) where T <: GdkMemoryTexture
Tuple(eval.((d[name])[2]))
end
end
end
begin
Expand Down Expand Up @@ -1173,6 +1197,18 @@ $(Expr(:toplevel, quote
function on_update(f, object::GdkFrameClock, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "update", Nothing, (), after, user_data)
end
function on_invalidate_contents(f, object::GdkGLTexture, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "invalidate-contents", Nothing, (), after, user_data)
end
function on_invalidate_size(f, object::GdkGLTexture, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "invalidate-size", Nothing, (), after, user_data)
end
function on_invalidate_contents(f, object::GdkMemoryTexture, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "invalidate-contents", Nothing, (), after, user_data)
end
function on_invalidate_size(f, object::GdkMemoryTexture, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "invalidate-size", Nothing, (), after, user_data)
end
function on_invalidate(f, object::GdkMonitor, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "invalidate", Nothing, (), after, user_data)
end
Expand Down Expand Up @@ -1203,6 +1239,12 @@ $(Expr(:toplevel, quote
function on_render(f, object::GdkSurface, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "render", Cint, (cairoRegion,), after, user_data)
end
function on_invalidate_contents(f, object::GdkTexture, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "invalidate-contents", Nothing, (), after, user_data)
end
function on_invalidate_size(f, object::GdkTexture, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "invalidate-size", Nothing, (), after, user_data)
end
function on_images_updated(f, object::GdkVulkanContext, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "images-updated", Nothing, (), after, user_data)
end
Expand Down
131 changes: 123 additions & 8 deletions src/gen/gio_structs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GApplication})
vcat([:activate, :command_line, :handle_local_options, :name_lost, :open, :shutdown, :startup], signalnames(supertype(GApplication)))
vcat([:activate, :command_line, :handle_local_options, :name_lost, :open, :shutdown, :startup, :action_added, :action_enabled_changed, :action_removed, :action_state_changed], signalnames(supertype(GApplication)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]), :startup => (:Nothing, Any[]), :shutdown => (:Nothing, Any[]), :command_line => (:Int32, Any[:(Ptr{GObject})]), :name_lost => (:Cint, Any[]), :open => (:Nothing, Any[:(Ptr{Ptr{GObject}}), :Int32, :Cstring]), :activate => (:Nothing, Any[]), :handle_local_options => (:Int32, Any[:GVariantDict]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GApplication
Expand Down Expand Up @@ -1005,7 +1005,15 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GDBusActionGroup})
signalnames(supertype(GDBusActionGroup))
vcat([:action_added, :action_enabled_changed, :action_removed, :action_state_changed], signalnames(supertype(GDBusActionGroup)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GDBusActionGroup
eval((d[name])[1])
end
function GLib.signal_argument_types(::Type{T}, name::Symbol) where T <: GDBusActionGroup
Tuple(eval.((d[name])[2]))
end
end
end
begin
Expand Down Expand Up @@ -1213,7 +1221,7 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GDBusObjectManagerClient})
vcat([:interface_proxy_properties_changed, :interface_proxy_signal], signalnames(supertype(GDBusObjectManagerClient)))
vcat([:interface_proxy_properties_changed, :interface_proxy_signal, :interface_added, :interface_removed, :object_added, :object_removed], signalnames(supertype(GDBusObjectManagerClient)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]), :interface_proxy_signal => (:Nothing, Any[:(Ptr{GObject}), :(Ptr{GObject}), :Cstring, :Cstring, :GVariant]), :interface_proxy_properties_changed => (:Nothing, Any[:(Ptr{GObject}), :(Ptr{GObject}), :GVariant, :(Ptr{Cstring})]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GDBusObjectManagerClient
Expand Down Expand Up @@ -1243,7 +1251,15 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GDBusObjectManagerServer})
signalnames(supertype(GDBusObjectManagerServer))
vcat([:interface_added, :interface_removed, :object_added, :object_removed], signalnames(supertype(GDBusObjectManagerServer)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GDBusObjectManagerServer
eval((d[name])[1])
end
function GLib.signal_argument_types(::Type{T}, name::Symbol) where T <: GDBusObjectManagerServer
Tuple(eval.((d[name])[2]))
end
end
end
begin
Expand All @@ -1265,7 +1281,15 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GDBusObjectProxy})
signalnames(supertype(GDBusObjectProxy))
vcat([:interface_added, :interface_removed], signalnames(supertype(GDBusObjectProxy)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GDBusObjectProxy
eval((d[name])[1])
end
function GLib.signal_argument_types(::Type{T}, name::Symbol) where T <: GDBusObjectProxy
Tuple(eval.((d[name])[2]))
end
end
end
begin
Expand All @@ -1287,7 +1311,7 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GDBusObjectSkeleton})
vcat([:authorize_method], signalnames(supertype(GDBusObjectSkeleton)))
vcat([:authorize_method, :interface_added, :interface_removed], signalnames(supertype(GDBusObjectSkeleton)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]), :authorize_method => (:Cint, Any[:(Ptr{GObject}), :(Ptr{GObject})]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GDBusObjectSkeleton
Expand Down Expand Up @@ -1811,7 +1835,15 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GListStore})
signalnames(supertype(GListStore))
vcat([:items_changed], signalnames(supertype(GListStore)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GListStore
eval((d[name])[1])
end
function GLib.signal_argument_types(::Type{T}, name::Symbol) where T <: GListStore
Tuple(eval.((d[name])[2]))
end
end
end
begin
Expand Down Expand Up @@ -2357,7 +2389,15 @@ $(Expr(:toplevel, quote
end
begin
function GLib.signalnames(::Type{GSimpleActionGroup})
signalnames(supertype(GSimpleActionGroup))
vcat([:action_added, :action_enabled_changed, :action_removed, :action_state_changed], signalnames(supertype(GSimpleActionGroup)))
end
let d = Dict{Symbol, Tuple{Any, Any}}(:notify => (:Nothing, Any[:GParam]))
function GLib.signal_return_type(::Type{T}, name::Symbol) where T <: GSimpleActionGroup
eval((d[name])[1])
end
function GLib.signal_argument_types(::Type{T}, name::Symbol) where T <: GSimpleActionGroup
Tuple(eval.((d[name])[2]))
end
end
end
begin
Expand Down Expand Up @@ -3733,9 +3773,33 @@ $(Expr(:toplevel, quote
function on_startup(f, object::GApplication, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "startup", Nothing, (), after, user_data)
end
function on_action_added(f, object::GApplication, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-added", Nothing, (Cstring,), after, user_data)
end
function on_action_enabled_changed(f, object::GApplication, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-enabled-changed", Nothing, (Cstring, Cint), after, user_data)
end
function on_action_removed(f, object::GApplication, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-removed", Nothing, (Cstring,), after, user_data)
end
function on_action_state_changed(f, object::GApplication, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-state-changed", Nothing, (Cstring, GVariant), after, user_data)
end
function on_cancelled(f, object::GCancellable, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "cancelled", Nothing, (), after, user_data)
end
function on_action_added(f, object::GDBusActionGroup, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-added", Nothing, (Cstring,), after, user_data)
end
function on_action_enabled_changed(f, object::GDBusActionGroup, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-enabled-changed", Nothing, (Cstring, Cint), after, user_data)
end
function on_action_removed(f, object::GDBusActionGroup, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-removed", Nothing, (Cstring,), after, user_data)
end
function on_action_state_changed(f, object::GDBusActionGroup, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-state-changed", Nothing, (Cstring, GVariant), after, user_data)
end
function on_allow_mechanism(f, object::GDBusAuthObserver, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "allow-mechanism", Cint, (Cstring,), after, user_data)
end
Expand All @@ -3751,9 +3815,45 @@ $(Expr(:toplevel, quote
function on_interface_proxy_signal(f, object::GDBusObjectManagerClient, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "interface-proxy-signal", Nothing, (Ptr{GObject}, Ptr{GObject}, Cstring, Cstring, GVariant), after, user_data)
end
function on_interface_added(f, object::GDBusObjectManagerClient, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "interface-added", Nothing, (Ptr{GObject}, Ptr{GObject}), after, user_data)
end
function on_interface_removed(f, object::GDBusObjectManagerClient, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "interface-removed", Nothing, (Ptr{GObject}, Ptr{GObject}), after, user_data)
end
function on_object_added(f, object::GDBusObjectManagerClient, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "object-added", Nothing, (Ptr{GObject},), after, user_data)
end
function on_object_removed(f, object::GDBusObjectManagerClient, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "object-removed", Nothing, (Ptr{GObject},), after, user_data)
end
function on_interface_added(f, object::GDBusObjectManagerServer, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "interface-added", Nothing, (Ptr{GObject}, Ptr{GObject}), after, user_data)
end
function on_interface_removed(f, object::GDBusObjectManagerServer, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "interface-removed", Nothing, (Ptr{GObject}, Ptr{GObject}), after, user_data)
end
function on_object_added(f, object::GDBusObjectManagerServer, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "object-added", Nothing, (Ptr{GObject},), after, user_data)
end
function on_object_removed(f, object::GDBusObjectManagerServer, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "object-removed", Nothing, (Ptr{GObject},), after, user_data)
end
function on_interface_added(f, object::GDBusObjectProxy, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "interface-added", Nothing, (Ptr{GObject},), after, user_data)
end
function on_interface_removed(f, object::GDBusObjectProxy, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "interface-removed", Nothing, (Ptr{GObject},), after, user_data)
end
function on_authorize_method(f, object::GDBusObjectSkeleton, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "authorize-method", Cint, (Ptr{GObject}, Ptr{GObject}), after, user_data)
end
function on_interface_added(f, object::GDBusObjectSkeleton, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "interface-added", Nothing, (Ptr{GObject},), after, user_data)
end
function on_interface_removed(f, object::GDBusObjectSkeleton, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "interface-removed", Nothing, (Ptr{GObject},), after, user_data)
end
function on_new_connection(f, object::GDBusServer, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "new-connection", Cint, (Ptr{GObject},), after, user_data)
end
Expand All @@ -3763,6 +3863,9 @@ $(Expr(:toplevel, quote
function on_got_completion_data(f, object::GFilenameCompleter, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "got-completion-data", Nothing, (), after, user_data)
end
function on_items_changed(f, object::GListStore, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "items-changed", Nothing, (UInt32, UInt32, UInt32), after, user_data)
end
function on_items_changed(f, object::GMenuModel, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "items-changed", Nothing, (Int32, Int32, Int32), after, user_data)
end
Expand Down Expand Up @@ -3805,6 +3908,18 @@ $(Expr(:toplevel, quote
function on_change_state(f, object::GSimpleAction, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "change-state", Nothing, (GVariant,), after, user_data)
end
function on_action_added(f, object::GSimpleActionGroup, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-added", Nothing, (Cstring,), after, user_data)
end
function on_action_enabled_changed(f, object::GSimpleActionGroup, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-enabled-changed", Nothing, (Cstring, Cint), after, user_data)
end
function on_action_removed(f, object::GSimpleActionGroup, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-removed", Nothing, (Cstring,), after, user_data)
end
function on_action_state_changed(f, object::GSimpleActionGroup, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "action-state-changed", Nothing, (Cstring, GVariant), after, user_data)
end
function on_event(f, object::GSocketClient, user_data = object, after = false)
GLib.signal_connect_generic(f, object, "event", Nothing, (UInt32, Ptr{GObject}, Ptr{GObject}), after, user_data)
end
Expand Down
Loading

0 comments on commit fd5b527

Please sign in to comment.