[gtk/wip/antoniof/backport-list-focus] listbase: Grab focus on items instead of container
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/antoniof/backport-list-focus] listbase: Grab focus on items instead of container
- Date: Fri, 21 Oct 2022 08:03:16 +0000 (UTC)
commit b86c91de1d2562209093250ddf43f17f7265d539
Author: António Fernandes <antoniof gnome org>
Date: Thu Sep 15 01:52:22 2022 +0100
listbase: Grab focus on items instead of container
The container view itself being focusable makes keyboard navigation
slower by adding a useless focus step.
It also means if an item gets removed, the focus jumps back to the view,
instead of jumping to the next item, as seen in nautilus bug report:
https://gitlab.gnome.org/GNOME/nautilus/-/issues/2489
Instead of making the GtkListBase container itself focusable, override
the .grab_focus() vfunc. This way, calling gtk_widget_grab_focus() on
the view container keeps working sucessfully, but focuses the focus
item directly instead.
This is particularly useful to have because applicaiton authors do
not have direct acess to this class's children, so they can't call
gtk_widget_grab_focus() on them directly.
(cherry picked from commit 4fc429892086e8bc1c9be94d5184e7eeff518f9c)
gtk/gtklistbase.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
---
diff --git a/gtk/gtklistbase.c b/gtk/gtklistbase.c
index 0d09c8d26c..03bcb48288 100644
--- a/gtk/gtklistbase.c
+++ b/gtk/gtklistbase.c
@@ -569,6 +569,20 @@ gtk_list_base_focus (GtkWidget *widget,
return gtk_widget_child_focus (item->widget, direction);
}
+static gboolean
+gtk_list_base_grab_focus (GtkWidget *widget)
+{
+ GtkListBase *self = GTK_LIST_BASE (widget);
+ GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
+ guint pos;
+
+ pos = gtk_list_item_tracker_get_position (priv->item_manager, priv->focus);
+ if (gtk_list_base_grab_focus_on_item (self, pos, FALSE, FALSE, FALSE))
+ return TRUE;
+
+ return GTK_WIDGET_CLASS (gtk_list_base_parent_class)->grab_focus (widget);
+}
+
static void
gtk_list_base_dispose (GObject *object)
{
@@ -1120,6 +1134,7 @@ gtk_list_base_class_init (GtkListBaseClass *klass)
gpointer iface;
widget_class->focus = gtk_list_base_focus;
+ widget_class->grab_focus = gtk_list_base_grab_focus;
gobject_class->dispose = gtk_list_base_dispose;
gobject_class->get_property = gtk_list_base_get_property;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]