menusectionbox: Passthrough the focus function of custom widgets' gizmo
authorvanadiae <vanadiae35@gmail.com>
Mon, 2 Aug 2021 19:20:32 +0000 (21:20 +0200)
committervanadiae <vanadiae35@gmail.com>
Mon, 2 Aug 2021 19:20:32 +0000 (21:20 +0200)
It broke keyboard focusing any widget added through the custom widget
menu feature. So for example if you put e.g. a custom check box widget
in a menu, you won't be able to focus it.

This is because the gizmo is mostly used to custom drawing with e.g.
CSS for small visual elements like scale markers. That's probably why
gizmo's default focus overrides block the focus from going through
the children. So this commit fixes it by overriding those and passing
the focus through the children.

gtk/gtkmenusectionbox.c

index 89f01d3d6a8e755d1646be4f00c5c5f207cb6dcc..6d3251e341074cd7a7cc25ed92d9579b2509814a 100644 (file)
@@ -309,6 +309,25 @@ submenu_hidden (GtkPopoverMenu     *popover,
     gtk_menu_tracker_item_request_submenu_shown (item, FALSE);
 }
 
+/* We're using the gizmo as an easy single child container, not as
+ * a custom widget to draw some visual indicators (like markers).
+ * As such its default focus functions blocks focus through the children,
+ * so we need to handle it correctly here so that custom widgets inside
+ * menus can be focused.
+ */
+static gboolean
+custom_widget_focus (GtkGizmo        *gizmo,
+                     GtkDirectionType direction)
+{
+  return gtk_widget_focus_child (GTK_WIDGET (gizmo), direction);
+}
+
+static gboolean
+custom_widget_grab_focus (GtkGizmo *gizmo)
+{
+  return gtk_widget_grab_focus_child (GTK_WIDGET (gizmo));
+}
+
 static void
 gtk_menu_section_box_insert_func (GtkMenuTrackerItem *item,
                                   int                 position,
@@ -369,7 +388,7 @@ gtk_menu_section_box_insert_func (GtkMenuTrackerItem *item,
     {
       const char *id = gtk_menu_tracker_item_get_custom (item);
 
-      widget = gtk_gizmo_new ("widget", NULL, NULL, NULL, NULL, NULL, NULL);
+      widget = gtk_gizmo_new ("widget", NULL, NULL, NULL, NULL, custom_widget_focus, custom_widget_grab_focus);
       gtk_widget_set_layout_manager (widget, gtk_bin_layout_new ());
 
       if (g_hash_table_lookup (box->custom_slots, id))