[gtk/fix-editable-label-spurious-focus-out: 1/2] window: Keep a reference to move_focus_widget
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/fix-editable-label-spurious-focus-out: 1/2] window: Keep a reference to move_focus_widget
- Date: Tue, 18 Oct 2022 18:25:47 +0000 (UTC)
commit e1d78821f662eda897e5187fca8fe9ec3f5f716f
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Oct 18 14:21:51 2022 -0400
window: Keep a reference to move_focus_widget
If we don't take a reference, it can happen that
the pointer is no longer valid by the time we
dereference it in after_paint.
gtk/gtkwindow.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 1de17f9048..6b4e2d77a7 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -2006,7 +2006,10 @@ gtk_window_root_set_focus (GtkRoot *root,
{
if (priv->move_focus &&
focus && gtk_widget_is_visible (focus))
- priv->move_focus = FALSE;
+ {
+ priv->move_focus = FALSE;
+ g_clear_object (&priv->move_focus_widget);
+ }
return;
}
@@ -2028,7 +2031,10 @@ gtk_window_root_set_focus (GtkRoot *root,
if (priv->move_focus &&
focus && gtk_widget_is_visible (focus))
- priv->move_focus = FALSE;
+ {
+ priv->move_focus = FALSE;
+ g_clear_object (&priv->move_focus_widget);
+ }
g_object_notify (G_OBJECT (self), "focus-widget");
}
@@ -2552,6 +2558,7 @@ gtk_window_dispose (GObject *object)
g_list_free_full (priv->foci, (GDestroyNotify) gtk_pointer_focus_unref);
priv->foci = NULL;
+ g_clear_object (&priv->move_focus_widget);
gtk_window_set_focus (window, NULL);
gtk_window_set_default_widget (window, NULL);
@@ -4695,6 +4702,9 @@ maybe_unset_focus_and_default (GtkWindow *window)
parent = _gtk_widget_get_parent (parent);
}
+
+ priv->move_focus = FALSE;
+ g_clear_object (&priv->move_focus_widget);
}
if (priv->unset_default)
@@ -5155,7 +5165,7 @@ _gtk_window_unset_focus_and_default (GtkWindow *window,
child = priv->focus_widget;
if (child && (child == widget || gtk_widget_is_ancestor (child, widget)))
{
- priv->move_focus_widget = widget;
+ priv->move_focus_widget = g_object_ref (widget);
priv->move_focus = TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]