[gnome-flashback/wip/segeiger/inputmethods: 3/4] input-sources: implement accelerator_activated_cb in GfInputSourceManager



commit ae201c4118a6f14d2c9e1b7f1a64fb780aaf888f
Author: Sebastian Geiger <sbastig gmx net>
Date:   Sat Sep 19 18:37:18 2015 +0200

    input-sources: implement accelerator_activated_cb in GfInputSourceManager

 .../libinput-sources/gf-input-source-manager.c     |   78 ++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/gf-input-source-manager.c 
b/gnome-flashback/libinput-sources/gf-input-source-manager.c
index 29fd3fe..54ac9e6 100644
--- a/gnome-flashback/libinput-sources/gf-input-source-manager.c
+++ b/gnome-flashback/libinput-sources/gf-input-source-manager.c
@@ -70,6 +70,8 @@ struct _GfInputSourceManager
 
   GList                 *mru_sources;
   GList                 *mru_sources_backup;
+
+  GfInputSource         *currentSource;
 };
 
 enum
@@ -209,12 +211,87 @@ switch_input_backward_changed_cb (GSettings *settings,
   manager->switch_source_backward_action = action;
 }
 
+static gint
+source_comparator (gconstpointer a, gconstpointer b)
+{
+  GfInputSource *source_a;
+  GfInputSource *source_b;
+
+  source_a = GF_INPUT_SOURCE (a);
+  source_b = GF_INPUT_SOURCE (b);
+
+  return gf_input_source_get_index (source_a) - gf_input_source_get_index (source_b);
+}
+
 static void
 accelerator_activated_cb (GfKeybindings *keybindings,
                           guint          action,
                           GVariant      *parameters,
                           gpointer       user_data)
 {
+  GfInputSourceManager *manager;
+  GfInputSource *input_source;
+
+  GList *source_indexes;
+  GList *source_values;
+  GList *sorted_source_values;
+  GList *current_item;
+
+  gint index;
+
+  manager = GF_INPUT_SOURCE_MANAGER (user_data);
+
+  source_indexes = g_hash_table_get_keys (manager->input_sources);
+  source_values = g_hash_table_get_values (manager->input_sources);
+
+  sorted_source_values = g_list_sort (source_values, source_comparator);
+
+  if (g_list_length (source_indexes) == 0)
+    {
+      gf_keyboard_manager_ungrab (manager->keyboard_manager, GDK_CURRENT_TIME);
+      return;
+    }
+
+  input_source = manager->currentSource;
+
+  if (input_source == NULL)
+    input_source = sorted_source_values->data;
+
+  index = gf_input_source_get_index (input_source);
+
+  current_item = g_list_nth (sorted_source_values, (guint) index);
+
+  if (action == manager->switch_source_action)
+    {
+      if (current_item->next == NULL)
+        current_item = g_list_first(sorted_source_values);
+      else
+        current_item = current_item->next;
+
+      while (current_item->data == NULL && current_item->next != NULL)
+      {
+        current_item = current_item->next;
+      }
+      input_source = current_item->data;
+    }
+  else
+    {
+      if (current_item->prev == NULL)
+          current_item = g_list_last (sorted_source_values);
+      else
+        current_item = current_item->prev;
+
+      while (current_item->data == NULL && current_item->prev != NULL)
+        {
+          current_item = current_item->prev;
+        }
+      input_source = current_item->data;
+    }
+
+  g_list_free (source_indexes);
+  g_list_free (source_values);
+
+  gf_input_source_activate (input_source);
 }
 
 static void
@@ -375,6 +452,7 @@ static void
 current_input_source_changed (GfInputSourceManager *manager,
                               GfInputSource        *new_source)
 {
+  manager->currentSource = new_source;
 }
 
 static void


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