[libhandy] preferences-group: Allow navigating out of the listbox



commit 250dc9bfd96516b85f85c67eb0e8cbe9eb15be78
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed Jan 6 16:53:17 2021 +0100

    preferences-group: Allow navigating out of the listbox
    
    This allows moving out of the lisbox with up or down instead of trapping
    the user in, which make sense as a preferences page is full of
    consecutive listboxes.

 src/hdy-preferences-group.c  | 17 +++++++++++++++++
 src/hdy-preferences-group.ui |  1 +
 2 files changed, 18 insertions(+)
---
diff --git a/src/hdy-preferences-group.c b/src/hdy-preferences-group.c
index e19f7e0a..f8e1c2d8 100644
--- a/src/hdy-preferences-group.c
+++ b/src/hdy-preferences-group.c
@@ -86,6 +86,22 @@ update_listbox_visibility (HdyPreferencesGroup *self)
   gtk_widget_set_visible (GTK_WIDGET (priv->listbox), children != NULL);
 }
 
+static gboolean
+listbox_keynav_failed_cb (HdyPreferencesGroup *self,
+                          GtkDirectionType     direction)
+{
+  GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
+
+  if (!toplevel)
+    return FALSE;
+
+  if (direction != GTK_DIR_UP && direction != GTK_DIR_DOWN)
+    return FALSE;
+
+  return gtk_widget_child_focus (toplevel, direction == GTK_DIR_UP ?
+                                 GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD);
+}
+
 typedef struct {
   HdyPreferencesGroup *group;
   GtkCallback callback;
@@ -284,6 +300,7 @@ hdy_preferences_group_class_init (HdyPreferencesGroupClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, HdyPreferencesGroup, listbox_box);
   gtk_widget_class_bind_template_child_private (widget_class, HdyPreferencesGroup, title);
   gtk_widget_class_bind_template_callback (widget_class, update_listbox_visibility);
+  gtk_widget_class_bind_template_callback (widget_class, listbox_keynav_failed_cb);
 }
 
 static void
diff --git a/src/hdy-preferences-group.ui b/src/hdy-preferences-group.ui
index 33cfcdb9..81c35da4 100644
--- a/src/hdy-preferences-group.ui
+++ b/src/hdy-preferences-group.ui
@@ -44,6 +44,7 @@
                 <property name="visible">True</property>
                 <signal name="add" handler="update_listbox_visibility" after="yes" swapped="yes"/>
                 <signal name="remove" handler="update_listbox_visibility" after="yes" swapped="yes"/>
+                <signal name="keynav-failed" handler="listbox_keynav_failed_cb" swapped="yes"/>
                 <style>
                   <class name="content"/>
                 </style>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]