From d918a77d34749962f66490bb72733b8119dd2419 Mon Sep 17 00:00:00 2001 From: Alexandros Theodotou Date: Sun, 12 Feb 2023 09:28:22 +0900 Subject: [PATCH] Remove timeout when disposing GtkEditableLabel Fixes: #5584 --- gtk/gtkeditablelabel.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gtk/gtkeditablelabel.c b/gtk/gtkeditablelabel.c index a4690960fb..d86d7c2353 100644 --- a/gtk/gtkeditablelabel.c +++ b/gtk/gtkeditablelabel.c @@ -72,6 +72,8 @@ struct _GtkEditableLabel GtkWidget *stack; GtkWidget *label; GtkWidget *entry; + + guint stop_editing_soon_id; }; struct _GtkEditableLabelClass @@ -196,10 +198,12 @@ static gboolean stop_editing_soon (gpointer data) { GtkEventController *controller = data; - GtkWidget *widget = gtk_event_controller_get_widget (controller); + GtkEditableLabel *self = GTK_EDITABLE_LABEL (gtk_event_controller_get_widget (controller)); if (!gtk_event_controller_focus_contains_focus (GTK_EVENT_CONTROLLER_FOCUS (controller))) - gtk_editable_label_stop_editing (GTK_EDITABLE_LABEL (widget), TRUE); + gtk_editable_label_stop_editing (self, TRUE); + + self->stop_editing_soon_id = 0; return FALSE; } @@ -208,7 +212,8 @@ static void gtk_editable_label_focus_out (GtkEventController *controller, GtkEditableLabel *self) { - g_timeout_add (100, stop_editing_soon, controller); + if (self->stop_editing_soon_id == 0) + self->stop_editing_soon_id = g_timeout_add (100, stop_editing_soon, controller); } static void @@ -361,6 +366,8 @@ gtk_editable_label_dispose (GObject *object) self->entry = NULL; self->label = NULL; + g_clear_handle_id (&self->stop_editing_soon_id, g_source_remove); + G_OBJECT_CLASS (gtk_editable_label_parent_class)->dispose (object); }