[gtk+] GtkColorEditor: Keep ref on pre-popup focus widget



commit f44b9ef1f0b9bce88f01b258714338a9006f60e1
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jun 21 13:57:20 2016 +0200

    GtkColorEditor: Keep ref on pre-popup focus widget
    
    And ensure it's still visible before returning the keyboard focus to it.
    Because of the extra ref, add a dispose handler that will ensure the
    ref is lost (by popping down), although this should be already ensured
    through other paths (eg. when the popup widget loses visibility).
    
    This fixes a possible crash in dispose paths, where we might be restoring
    focus on an already destroyed widget, and at a time where, if the toplevel
    is being itself disposed, no new focus should be set.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=767849

 gtk/gtkcoloreditor.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkcoloreditor.c b/gtk/gtkcoloreditor.c
index f45949c..ed8f48b 100644
--- a/gtk/gtkcoloreditor.c
+++ b/gtk/gtkcoloreditor.c
@@ -175,8 +175,9 @@ dismiss_current_popup (GtkColorEditor *editor)
       editor->priv->popup_position = 0;
       if (editor->priv->popdown_focus)
         {
-          gtk_widget_grab_focus (editor->priv->popdown_focus);
-          editor->priv->popdown_focus = NULL;
+          if (gtk_widget_is_visible (editor->priv->popdown_focus))
+            gtk_widget_grab_focus (editor->priv->popdown_focus);
+          g_clear_object (&editor->priv->popdown_focus);
         }
     }
 }
@@ -218,7 +219,7 @@ popup_edit (GtkWidget      *widget,
     {
       dismiss_current_popup (editor);
       toplevel = gtk_widget_get_toplevel (GTK_WIDGET (editor));
-      editor->priv->popdown_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
+      g_set_object (&editor->priv->popdown_focus, gtk_window_get_focus (GTK_WINDOW (toplevel)));
       editor->priv->current_popup = popup;
       editor->priv->popup_position = position;
       gtk_widget_show (popup);
@@ -396,6 +397,16 @@ gtk_color_editor_init (GtkColorEditor *editor)
 }
 
 static void
+gtk_color_editor_dispose (GObject *object)
+{
+  GtkColorEditor *editor = GTK_COLOR_EDITOR (object);
+
+  dismiss_current_popup (editor);
+
+  G_OBJECT_CLASS (gtk_color_editor_parent_class)->dispose (object);
+}
+
+static void
 gtk_color_editor_get_property (GObject    *object,
                                guint       prop_id,
                                GValue     *value,
@@ -463,6 +474,7 @@ gtk_color_editor_class_init (GtkColorEditorClass *class)
   GObjectClass *object_class = G_OBJECT_CLASS (class);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
 
+  object_class->dispose = gtk_color_editor_dispose;
   object_class->get_property = gtk_color_editor_get_property;
   object_class->set_property = gtk_color_editor_set_property;
 


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