summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorey Berla <corey@berla.me>2022-08-21 14:13:06 -0700
committerAntónio Fernandes <antoniof@gnome.org>2022-08-23 19:16:09 +0000
commit55b9c1d89f12be1719df1982b17d493f7f4faf5b (patch)
treedfbff8083f195770ada8308ff253ffc9a25fee48
parent73e77399bc0054607c8755f7fb2d2f0065bc27cf (diff)
downloadnautilus-55b9c1d89f12be1719df1982b17d493f7f4faf5b.tar.gz
files-view: Grab focus when background / selection menu closed
After closes the background or selection menu (by clicking out of the menu or escape) the focus goes to the back button in the toolbar, rather than the last focused item. It's not clear if this is a gtk issue or because our complex configuration. Connect the "closed" signal to simply grab back the focus to the files view. This isn't perfect because it doesn't necessarily grab the last focussed child, but it saves from adding too much complexity. Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2433
-rw-r--r--src/nautilus-files-view.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 3663834e9..fb2b22675 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -8393,6 +8393,12 @@ nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
* closed because it wouldn't activate the actions then. */
g_clear_pointer (&priv->selection_menu, gtk_widget_unparent);
priv->selection_menu = gtk_popover_menu_new_from_model (NULL);
+
+ /* There's something related to NautilusFilesView that isn't grabbing the
+ * focus back when the popover is closed. Let's force it as a workaround. */
+ g_signal_connect_object (priv->selection_menu, "closed",
+ G_CALLBACK (gtk_widget_grab_focus), view,
+ G_CONNECT_SWAPPED);
gtk_widget_set_parent (priv->selection_menu, GTK_WIDGET (view));
gtk_popover_set_has_arrow (GTK_POPOVER (priv->selection_menu), FALSE);
gtk_widget_set_halign (priv->selection_menu, GTK_ALIGN_START);
@@ -8445,6 +8451,12 @@ nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
* closed because it wouldn't activate the actions then. */
g_clear_pointer (&priv->background_menu, gtk_widget_unparent);
priv->background_menu = gtk_popover_menu_new_from_model (NULL);
+
+ /* There's something related to NautilusFilesView that isn't grabbing the
+ * focus back when the popover is closed. Let's force it as a workaround. */
+ g_signal_connect_object (priv->background_menu, "closed",
+ G_CALLBACK (gtk_widget_grab_focus), view,
+ G_CONNECT_SWAPPED);
gtk_widget_set_parent (priv->background_menu, GTK_WIDGET (view));
gtk_popover_set_has_arrow (GTK_POPOVER (priv->background_menu), FALSE);
gtk_widget_set_halign (priv->background_menu, GTK_ALIGN_START);