gtk-demo: Fix cleanup of search entry demo

We can't use the ::destroy signal anymore; use
a weak ref instead, and make ensure the entry
stays around long enough for us to finish the
cleanup.

Fixes: #3004
This commit is contained in:
Matthias Clasen 2020-08-02 21:53:59 -04:00
parent a7e25f2c73
commit df85ef1754

View File

@ -37,6 +37,7 @@ static void
search_progress_done (GtkEntry *entry) search_progress_done (GtkEntry *entry)
{ {
gtk_entry_set_progress_fraction (entry, 0.0); gtk_entry_set_progress_fraction (entry, 0.0);
g_object_unref (entry);
} }
static gboolean static gboolean
@ -56,8 +57,9 @@ start_search_feedback (gpointer data)
{ {
gtk_entry_set_progress_fraction (GTK_ENTRY (data), 0.1); gtk_entry_set_progress_fraction (GTK_ENTRY (data), 0.1);
search_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 100, search_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 100,
(GSourceFunc)search_progress, data, (GSourceFunc)search_progress, g_object_ref (data),
(GDestroyNotify)search_progress_done); (GDestroyNotify)search_progress_done);
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
@ -163,7 +165,8 @@ activate_cb (GtkEntry *entry,
} }
static void static void
search_entry_destroyed (GtkWidget *widget) search_entry_destroyed (gpointer data,
GObject *widget)
{ {
if (finish_search_id != 0) if (finish_search_id != 0)
{ {
@ -262,8 +265,8 @@ do_search_entry (GtkWidget *do_widget)
gtk_window_set_display (GTK_WINDOW (window), gtk_widget_get_display (do_widget)); gtk_window_set_display (GTK_WINDOW (window), gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Search Entry"); gtk_window_set_title (GTK_WINDOW (window), "Search Entry");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE); gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "destroy",
G_CALLBACK (search_entry_destroyed), &window); g_object_weak_ref (G_OBJECT (window), search_entry_destroyed, &window);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_widget_set_margin_start (vbox, 5); gtk_widget_set_margin_start (vbox, 5);