From 9a6d3bd7be88960c6aae2777f6ea50cfcd1ffa12 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 12 Jan 2022 01:19:47 -0500 Subject: [PATCH] tidy up --- src/Gtk.jl | 5 ++++- src/base.jl | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Gtk.jl b/src/Gtk.jl index 691e5bf2..eb16da42 100644 --- a/src/Gtk.jl +++ b/src/Gtk.jl @@ -134,9 +134,12 @@ function __init__() global gtk_main_task = schedule(Task(gtk_main)) end - idle(get(ENV, "GTK_START_IDLE", "true") == "true") + AUTO_IDLE[] = get(ENV, "GTK_AUTO_IDLE", "true") == "true" + idle(AUTO_IDLE[]) end +const AUTO_IDLE = Ref{Bool}(true) + """ Gtk.idle(b::Bool = true) diff --git a/src/base.jl b/src/base.jl index a7897255..270097bc 100644 --- a/src/base.jl +++ b/src/base.jl @@ -29,24 +29,24 @@ visible(w::GtkWidget) = Bool(ccall((:gtk_widget_get_visible, libgtk), Cint, (Ptr visible(w::GtkWidget, state::Bool) = @sigatom ccall((:gtk_widget_set_visible, libgtk), Nothing, (Ptr{GObject}, Cint), w, state) const SHOWN_WIDGETS = WeakKeyDict() +function handle_auto_idle(w::GtkWidget) + if AUTO_IDLE[] + idle(false) + SHOWN_WIDGETS[w] = nothing + signal_connect(w, :destroy) do w + delete!(SHOWN_WIDGETS, w) + isempty(SHOWN_WIDGETS) && idle(true) + end + end +end function show(w::GtkWidget) - idle(false) + handle_auto_idle(w) @sigatom ccall((:gtk_widget_show, libgtk), Nothing, (Ptr{GObject},), w) - SHOWN_WIDGETS[w] = nothing - signal_connect(w, :destroy) do w - delete!(SHOWN_WIDGETS, w) - isempty(SHOWN_WIDGETS) && idle(true) - end w end function showall(w::GtkWidget) - idle(false) + handle_auto_idle(w) @sigatom ccall((:gtk_widget_show_all, libgtk), Nothing, (Ptr{GObject},), w) - SHOWN_WIDGETS[w] = nothing - signal_connect(w, :destroy) do w - delete!(SHOWN_WIDGETS, w) - isempty(SHOWN_WIDGETS) && idle(true) - end w end