[gtk/BUG_popover_focus_new_folder_issue_GTK3] Fix popovers not restablishing default widget



commit de99b2f0b8f9602c5acf675b43a4fbdce9ab6de4
Author: Nelson Benítez León <nbenitezl gmail com>
Date:   Thu Aug 29 19:40:54 2019 -0400

    Fix popovers not restablishing default widget
    
    Popovers have special handling to restablish
    the previous 'default' and 'focused' widget,
    that code it's in the map() unmap() handlers
    in gtk/popover.c .
    
    But, at the same time, GtkWindow also does
    automatic restablishing of previous 'default' and
    'focused' widgets, that's in _gtk_window_unset_focus_and_default()
    function in gtk/gtkwindow.c which is called from
    gtk_widget_hide() in gtk/gtkwidget.c .
    
    So, when a popover is closed, both code-paths are
    executed, conflicting with each other and resulting
    in the popover failing to properly restablish the
    default widget.
    
    The commit that introduced _gtk_window_unset_focus_and_default()
    to gtkwindow.c is from 2002 (commit ff9c2c5669) so
    it predates by far the popover.c implementation,
    therefore the rationale thing to do here is to exempt
    popovers from being handled in _gtk_window_unset_focus_and_default()
    (as that function is oblivion to the fact that
    popovers have their own handling).
    
    So, this commit exempts popovers from being handled
    in the aforementioned function, but only for
    the 'default' widget part atm, because although
    by the previous rationale we should exempt it
    from the 'focused' widget part too, I could not
    find a bug in the issue tracker about that, so
    instead we just exempt the 'default' widget part
    that we know for sure it fixes issue #2125
    
    Fixes issue #2125

 gtk/gtkwindow.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 62a7cb7686..fe6b03858b 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -9091,6 +9091,11 @@ gtk_window_style_updated (GtkWidget *widget)
  * 
  * Checks whether the focus and default widgets of @window are
  * @widget or a descendent of @widget, and if so, unset them.
+ *
+ * If @widget is a #GtkPopover then nothing will be done with
+ * respect to the default widget of @window, the reason being that
+ * popovers already have specific logic for clearing/restablishing
+ * the default widget of its enclosing window.
  **/
 void
 _gtk_window_unset_focus_and_default (GtkWindow *window,
@@ -9115,15 +9120,18 @@ _gtk_window_unset_focus_and_default (GtkWindow *window,
       if (child == widget)
        gtk_window_set_focus (GTK_WINDOW (window), NULL);
     }
-      
-  child = priv->default_widget;
-      
-  while (child && child != widget)
-    child = _gtk_widget_get_parent (child);
-
-  if (child == widget)
-    gtk_window_set_default (window, NULL);
   
+  if (!GTK_IS_POPOVER (widget))
+    {
+      child = priv->default_widget;
+
+      while (child && child != widget)
+        child = _gtk_widget_get_parent (child);
+
+      if (child == widget)
+        gtk_window_set_default (window, NULL);
+    }
+
   g_object_unref (widget);
   g_object_unref (window);
 }


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