[gtk/kjellahl/gtkheaderbar-signal-handlers] headerbar: Disconnect signal handlers when children are removed



commit e41c049c966da9f8df8c3b64d8369d0480c67de3
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Tue Nov 12 13:24:56 2019 +0100

    headerbar: Disconnect signal handlers when children are removed
    
    The signal handler that calls notify_child_cb() is disconnected
    from a child widget before the child is removed from the header bar.
    
    Fixes #2246

 gtk/gtkheaderbar.c | 49 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index 7141a2d300..788d360ea1 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -805,25 +805,6 @@ gtk_header_bar_get_custom_title (GtkHeaderBar *bar)
   return priv->custom_title;
 }
 
-static void
-gtk_header_bar_dispose (GObject *object)
-{
-  GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (GTK_HEADER_BAR (object));
-
-  if (priv->label_sizing_box)
-    {
-      gtk_widget_destroy (priv->label_sizing_box);
-      g_clear_object (&priv->label_sizing_box);
-    }
-
-  g_clear_pointer (&priv->custom_title, gtk_widget_unparent);
-  g_clear_pointer (&priv->label_box, gtk_widget_unparent);
-  g_clear_pointer (&priv->start_box, gtk_widget_unparent);
-  g_clear_pointer (&priv->end_box, gtk_widget_unparent);
-
-  G_OBJECT_CLASS (gtk_header_bar_parent_class)->dispose (object);
-}
-
 static void
 gtk_header_bar_finalize (GObject *object)
 {
@@ -981,11 +962,13 @@ gtk_header_bar_remove (GtkContainer *container,
 
   if (parent == priv->start_box)
     {
+      g_signal_handlers_disconnect_by_func (widget, notify_child_cb, bar);
       gtk_container_remove (GTK_CONTAINER (priv->start_box), widget);
       removed = TRUE;
     }
   else if (parent == priv->end_box)
     {
+      g_signal_handlers_disconnect_by_func (widget, notify_child_cb, bar);
       gtk_container_remove (GTK_CONTAINER (priv->end_box), widget);
       removed = TRUE;
     }
@@ -1046,6 +1029,34 @@ gtk_header_bar_forall (GtkContainer *container,
     }
 }
 
+static void
+disconnect_notify_child_cb (GtkWidget *widget,
+                            GtkHeaderBar *bar)
+{
+  g_signal_handlers_disconnect_by_func (widget, notify_child_cb, bar);
+}
+
+static void
+gtk_header_bar_dispose (GObject *object)
+{
+  GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (GTK_HEADER_BAR (object));
+
+  gtk_header_bar_forall (GTK_CONTAINER (object), (GtkCallback) disconnect_notify_child_cb, object);
+
+  if (priv->label_sizing_box)
+    {
+      gtk_widget_destroy (priv->label_sizing_box);
+      g_clear_object (&priv->label_sizing_box);
+    }
+
+  g_clear_pointer (&priv->custom_title, gtk_widget_unparent);
+  g_clear_pointer (&priv->label_box, gtk_widget_unparent);
+  g_clear_pointer (&priv->start_box, gtk_widget_unparent);
+  g_clear_pointer (&priv->end_box, gtk_widget_unparent);
+
+  G_OBJECT_CLASS (gtk_header_bar_parent_class)->dispose (object);
+}
+
 static GType
 gtk_header_bar_child_type (GtkContainer *container)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]