Skip to content

Commit

Permalink
keep waitforsignal() working for other situations too
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand committed Feb 21, 2024
1 parent f0c1e5a commit d28a83b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/GLib/signals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,12 @@ end
waitforsignal(obj::GObject, signal)
Returns when a GObject's signal is emitted. Can be used to wait for a window to
be closed.
be closed. This function should only be used for signals that return nothing, with one exception: the "close-request" signal of GtkWindow.
"""
function waitforsignal(obj::GObject,signal)
c = Condition()
signal_connect(obj, signal) do w
notify(c)
return false
end
wait(c)
end
Expand Down
14 changes: 14 additions & 0 deletions src/windows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ push!(w::GtkWindow, widget::GtkWidget) = (G_.set_child(w, widget); w)
setindex!(w::GtkWindow, widget::Union{Nothing,GtkWidget}) = G_.set_child(w, widget)
getindex(w::GtkWindow) = G_.get_child(w)

# totally ugly hack to salvage this Gtk.jl legacy function for its original purpose
function GLib.waitforsignal(obj::GtkWindow,signal)
if signal === :close_request || signal == "close-request"
c = Condition()
signal_connect(obj, signal) do w
notify(c)
return false
end
wait(c)
else
invoke(GLib.waitforsignal, Tuple{GObject,Any}, obj, signal)
end
end

function push!(wg::GtkWindowGroup, w::GtkWindow)
G_.add_window(wg,w)
wg
Expand Down

0 comments on commit d28a83b

Please sign in to comment.