[gtk: 1/3] popovermenu: Cycle around focus also with (Shift+)Tab
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 1/3] popovermenu: Cycle around focus also with (Shift+)Tab
- Date: Thu, 5 Aug 2021 02:07:45 +0000 (UTC)
commit ef92adc87d64a37926a91d96b4ac22e7f929d954
Author: vanadiae <vanadiae35 gmail com>
Date: Mon Jul 5 19:20:58 2021 +0200
popovermenu: Cycle around focus also with (Shift+)Tab
Currently when moving the focus with (Shift+)Tab, it also traverses the window's
widgets, although it would be expected that the focus stays within the popover,
as it's (almost) like it's a separate window. This would be consistent with
the behaviour of the Up/down arrows, which do cycle around the focus once it
reaches the end.
So this commit makes the popovermenu cycle around focus in any direction, apart
from left/right because they are used to open and close submenus and it wouldn't
make sense anyway to cycle horizontally as there's usually only one widget per
line.
gtk/gtkpopovermenu.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index 3f999fa90f..9a3458584f 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -480,12 +480,21 @@ gtk_popover_menu_focus (GtkWidget *widget,
else
return TRUE;
}
- else if (direction == GTK_DIR_UP || direction == GTK_DIR_DOWN)
+ /* Cycle around with up/down arrows and (Shift+)Tab when modal */
+ else if (gtk_popover_get_autohide (GTK_POPOVER (menu)))
{
- GtkWidget *p;
+ GtkWidget *p = gtk_root_get_focus (gtk_widget_get_root (widget));
+
+ /* In the case where the popover doesn't have any focusable child, if
+ * the menu doesn't have any item for example, then the focus will end
+ * up out of the popover, hence creating an infinite loop below. To
+ * avoid this, just say we had focus and stop here.
+ */
+ if (!gtk_widget_is_ancestor (p, widget) && p != widget)
+ return TRUE;
/* cycle around */
- for (p = gtk_root_get_focus (gtk_widget_get_root (widget));
+ for (;
p != widget;
p = gtk_widget_get_parent (p))
{
@@ -493,7 +502,7 @@ gtk_popover_menu_focus (GtkWidget *widget,
}
if (gtk_widget_focus_move (widget, direction))
return TRUE;
- }
+ }
}
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]