[gtk/fontrendering-demo-fix] gtk-demo: Make fontrendering demo work more than once




commit b58bad557b614a348388bcac7be352b1e5bd1fc8
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Aug 5 14:36:01 2020 -0400

    gtk-demo: Make fontrendering demo work more than once
    
    We weren't cleaning up properly, causing the window
    to not close the second time it is opened.
    
    Fixes: #3019

 demos/gtk-demo/fontrendering.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
---
diff --git a/demos/gtk-demo/fontrendering.c b/demos/gtk-demo/fontrendering.c
index a56b242ad5..d6c3525604 100644
--- a/demos/gtk-demo/fontrendering.c
+++ b/demos/gtk-demo/fontrendering.c
@@ -21,12 +21,6 @@ static PangoContext *context;
 
 static int scale = 10;
 
-static void
-on_destroy (gpointer data)
-{
-  window = NULL;
-}
-
 static void
 update_image (void)
 {
@@ -251,9 +245,7 @@ do_fontrendering (GtkWidget *do_widget)
       window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
       gtk_window_set_display (GTK_WINDOW (window),
                               gtk_widget_get_display (do_widget));
-      g_signal_connect (window, "destroy",
-                        G_CALLBACK (on_destroy), NULL);
-      g_object_set_data_full (G_OBJECT (window), "builder", builder, g_object_unref);
+      g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
       font_button = GTK_WIDGET (gtk_builder_get_object (builder, "font_button"));
       up_button = GTK_WIDGET (gtk_builder_get_object (builder, "up_button"));
       down_button = GTK_WIDGET (gtk_builder_get_object (builder, "down_button"));
@@ -276,6 +268,8 @@ do_fontrendering (GtkWidget *do_widget)
       g_signal_connect (show_extents, "notify::active", G_CALLBACK (update_image), NULL);
 
       update_image ();
+
+      g_object_unref (builder);
     }
 
   if (!gtk_widget_get_visible (window))


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