fontbutton: Destroy dialog in unrealize()

This way, we can be sure it's always using the right display.

We can also be sure that it doesn't leak.
This commit is contained in:
Benjamin Otte 2021-08-23 05:55:56 +02:00
parent 9a2f4d8026
commit 480112f9aa

View File

@ -461,6 +461,16 @@ gtk_font_button_activate (GtkFontButton *self)
gtk_widget_activate (self->button);
}
static void
gtk_font_button_unrealize (GtkWidget *widget)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (widget);
g_clear_pointer ((GtkWindow **) &font_button->font_dialog, gtk_window_destroy);
GTK_WIDGET_CLASS (gtk_font_button_parent_class)->unrealize (widget);
}
static void
gtk_font_button_class_init (GtkFontButtonClass *klass)
{
@ -476,6 +486,7 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
widget_class->grab_focus = gtk_widget_grab_focus_child;
widget_class->focus = gtk_widget_focus_child;
widget_class->unrealize = gtk_font_button_unrealize;
klass->font_set = NULL;
klass->activate = gtk_font_button_activate;
@ -628,9 +639,6 @@ gtk_font_button_finalize (GObject *object)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (object);
if (font_button->font_dialog != NULL)
gtk_window_destroy (GTK_WINDOW (font_button->font_dialog));
g_free (font_button->title);
clear_font_data (font_button);