[gnome-bluetooth] settings: Fix key naviguation



commit c90d9b1c560613e11c05920813c66b0ed5656d18
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Dec 10 01:33:49 2013 +0100

    settings: Fix key naviguation
    
    We only have a single list, so this is easier.

 lib/bluetooth-settings-widget.c |   76 ++++++++-------------------------------
 1 files changed, 15 insertions(+), 61 deletions(-)
---
diff --git a/lib/bluetooth-settings-widget.c b/lib/bluetooth-settings-widget.c
index 6f179b5..eb2392e 100644
--- a/lib/bluetooth-settings-widget.c
+++ b/lib/bluetooth-settings-widget.c
@@ -78,9 +78,6 @@ struct _BluetoothSettingsWidgetPrivate {
        /* Visible */
        GtkWidget           *visible_label;
        GtkWidget           *visible_revealer;
-
-       GList               *boxes;
-       GList               *boxes_reverse;
 };
 
 G_DEFINE_TYPE(BluetoothSettingsWidget, bluetooth_settings_widget, GTK_TYPE_BOX)
@@ -1307,60 +1304,21 @@ static gboolean
 keynav_failed (GtkWidget *list, GtkDirectionType direction, BluetoothSettingsWidget *self)
 {
        BluetoothSettingsWidgetPrivate *priv = BLUETOOTH_SETTINGS_WIDGET_GET_PRIVATE (self);
-  GtkWidget *next_list = NULL;
-  GList *item, *boxes_list;
-  gdouble value, lower, upper, page;
-
-  /* Find the list in the list of GtkListBoxes */
-  if (direction == GTK_DIR_DOWN)
-    boxes_list = priv->boxes;
-  else
-    boxes_list = priv->boxes_reverse;
-
-  item = g_list_find (boxes_list, list);
-  g_assert (item);
-  item = item->next;
-  while (1)
-    {
-      if (item == NULL)
-        item = boxes_list;
-
-      /* Avoid looping */
-      if (item->data == list)
-        break;
-
-      if (gtk_widget_is_visible (item->data))
-        {
-          next_list = item->data;
-          break;
-        }
-
-    item = item->next;
-  }
-
-  if (next_list)
-    {
-      gtk_widget_child_focus (next_list, direction);
-      return TRUE;
-    }
-
-  value = gtk_adjustment_get_value (priv->focus_adjustment);
-  lower = gtk_adjustment_get_lower (priv->focus_adjustment);
-  upper = gtk_adjustment_get_upper (priv->focus_adjustment);
-  page  = gtk_adjustment_get_page_size (priv->focus_adjustment);
-
-  if (direction == GTK_DIR_UP && value > lower)
-    {
-      gtk_adjustment_set_value (priv->focus_adjustment, lower);
-      return TRUE;
-    }
-  else if (direction == GTK_DIR_DOWN && value < upper - page)
-    {
-      gtk_adjustment_set_value (priv->focus_adjustment, upper - page);
-      return TRUE;
-    }
-
-  return FALSE;
+       GList *children, *item;
+
+       children = gtk_container_get_children (GTK_CONTAINER (priv->device_list));
+
+       if (direction == GTK_DIR_DOWN) {
+               item = children;
+       } else {
+               item = g_list_last (children);
+       }
+
+       gtk_widget_child_focus (item->data, direction);
+
+       g_list_free (children);
+
+       return TRUE;
 }
 
 static void
@@ -1437,7 +1395,6 @@ add_device_section (BluetoothSettingsWidget *self)
        gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, TRUE, 0);
 
        priv->device_list = widget = gtk_list_box_new ();
-       priv->boxes_reverse = g_list_prepend (priv->boxes_reverse, priv->device_list);
        g_signal_connect (widget, "keynav-failed", G_CALLBACK (keynav_failed), self);
        gtk_list_box_set_selection_mode (GTK_LIST_BOX (widget), GTK_SELECTION_NONE);
        gtk_list_box_set_header_func (GTK_LIST_BOX (widget),
@@ -1781,9 +1738,6 @@ bluetooth_settings_widget_init (BluetoothSettingsWidget *self)
 
        add_device_section (self);
 
-       priv->boxes = g_list_copy (priv->boxes_reverse);
-       priv->boxes = g_list_reverse (priv->boxes);
-
        box = gtk_scrolled_window_new (NULL, NULL);
        gtk_widget_set_hexpand (box, TRUE);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (box),


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