[gtk: 1/2] menusectionbox: Passthrough the focus function of custom widgets' gizmo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 1/2] menusectionbox: Passthrough the focus function of custom widgets' gizmo
- Date: Mon, 2 Aug 2021 22:21:09 +0000 (UTC)
commit 9099888398612e7d1fe48167da52e99033a87326
Author: vanadiae <vanadiae35 gmail com>
Date: Mon Aug 2 21:20:32 2021 +0200
menusectionbox: Passthrough the focus function of custom widgets' gizmo
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 | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index 89f01d3d6a..6d3251e341 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -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))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]