window: Don't focus invisible widgets
authorMatthias Clasen <mclasen@redhat.com>
Mon, 17 Oct 2022 19:10:51 +0000 (15:10 -0400)
committerMat <mail@mathias.is>
Tue, 18 Oct 2022 17:37:19 +0000 (20:37 +0300)
Only clear a queued move_focus if the widget
we are focusing is actually visible.

This was happening in some cases when popovers
are dismissed by clicking outside, and it was
causing us to miss proper focus updates that
were already queued.

gtk/gtkwindow.c

index ff16a681041f9b8842560cf8dacb2adfed3cdf3a..1de17f90487235c176542bf9f3793118f66febbf 100644 (file)
@@ -2004,7 +2004,9 @@ gtk_window_root_set_focus (GtkRoot   *root,
 
   if (focus == priv->focus_widget)
     {
-      priv->move_focus = FALSE;
+      if (priv->move_focus &&
+          focus && gtk_widget_is_visible (focus))
+        priv->move_focus = FALSE;
       return;
     }
 
@@ -2024,7 +2026,9 @@ gtk_window_root_set_focus (GtkRoot   *root,
 
   g_clear_object (&old_focus);
 
-  priv->move_focus = FALSE;
+  if (priv->move_focus &&
+      focus && gtk_widget_is_visible (focus))
+    priv->move_focus = FALSE;
 
   g_object_notify (G_OBJECT (self), "focus-widget");
 }
@@ -4689,7 +4693,7 @@ maybe_unset_focus_and_default (GtkWindow *window)
                 break;
             }
 
-           parent = _gtk_widget_get_parent (parent);
+          parent = _gtk_widget_get_parent (parent);
         }
     }