[Xfce4-commits] <xfce4-settings:master> Configure group key from xfce4-keyboard-settings.

Igor Slepchin noreply at xfce.org
Wed Aug 22 23:14:01 CEST 2012


Updating branch refs/heads/master
         to 3eb6c191e1a92e57fa0edde785b0f0b8088b40c5 (commit)
       from 9e08b67bfacc1f82f4d943146dbf6dec24100da2 (commit)

commit 3eb6c191e1a92e57fa0edde785b0f0b8088b40c5
Author: Igor Slepchin <igor.slepchin at gmail.com>
Date:   Mon Jul 16 15:16:35 2012 -0400

    Configure group key from xfce4-keyboard-settings.
    
    The group key setting is stored in /Default/XkbOptions/Group
    on keyboard-layout channel.
    
    This fixes bugs 5476, 5580 (together with a corresponding commit
    to xfce4-xkb-plugin).

 dialogs/keyboard-settings/keyboard-dialog.glade    |   39 +++++-
 dialogs/keyboard-settings/xfce-keyboard-settings.c |  147 ++++++++++++++++++-
 xfsettingsd/keyboard-layout.c                      |  100 +++++++++++++
 3 files changed, 277 insertions(+), 9 deletions(-)

diff --git a/dialogs/keyboard-settings/keyboard-dialog.glade b/dialogs/keyboard-settings/keyboard-dialog.glade
index 9edbb6d..6768c09 100644
--- a/dialogs/keyboard-settings/keyboard-dialog.glade
+++ b/dialogs/keyboard-settings/keyboard-dialog.glade
@@ -689,6 +689,43 @@
                       </packing>
                     </child>
                     <child>
+                      <object class="GtkFrame" id="xkb_grpkey_frame">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label_xalign">0</property>
+                        <property name="shadow_type">none</property>
+                        <child>
+                          <object class="GtkAlignment" id="alignment6">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="border_width">6</property>
+                            <property name="left_padding">12</property>
+                            <child>
+                              <object class="GtkComboBox" id="xkb_grpkey_combo">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                        <child type="label">
+                          <object class="GtkLabel" id="label1">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">Change layout option</property>
+                            <attributes>
+                              <attribute name="weight" value="bold"/>
+                            </attributes>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
                       <object class="GtkFrame" id="xkb_layout_frame">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
@@ -802,7 +839,7 @@
                       <packing>
                         <property name="expand">True</property>
                         <property name="fill">True</property>
-                        <property name="position">2</property>
+                        <property name="position">3</property>
                       </packing>
                     </child>
                   </object>
diff --git a/dialogs/keyboard-settings/xfce-keyboard-settings.c b/dialogs/keyboard-settings/xfce-keyboard-settings.c
index e8b6811..428f112 100644
--- a/dialogs/keyboard-settings/xfce-keyboard-settings.c
+++ b/dialogs/keyboard-settings/xfce-keyboard-settings.c
@@ -63,9 +63,16 @@ enum
 
 enum
 {
-    XKB_COMBO_DESCRIPTION = 0,
-    XKB_COMBO_MODELS,
-    XKB_COMBO_NUM_COLUMNS
+    XKB_MODEL_COMBO_DESCRIPTION = 0,
+    XKB_MODEL_COMBO_MODELS,
+    XKB_MODEL_COMBO_NUM_COLUMNS
+};
+
+enum
+{
+    XKB_GRPKEY_COMBO_DESCRIPTION = 0,
+    XKB_GRPKEY_COMBO_KEYS,
+    XKB_GRPKEY_COMBO_NUM_COLUMNS
 };
 
 enum
@@ -136,6 +143,14 @@ static void                      xfce_keyboard_settings_add_model_to_combo    (X
 static void                      xfce_keyboard_settings_init_model            (XfceKeyboardSettings      *settings);
 static void                      xfce_keyboard_settings_model_changed_cb      (GtkComboBox               *combo,
                                                                                XfceKeyboardSettings      *settings);
+
+static void                      xfce_keyboard_settings_add_grpkey_to_combo   (XklConfigRegistry         *config_registry,
+                                                                               const XklConfigItem       *config_item,
+                                                                               gpointer                   user_data);
+static void                      xfce_keyboard_settings_init_grpkey           (XfceKeyboardSettings      *settings);
+static void                      xfce_keyboard_settings_grpkey_changed_cb     (GtkComboBox               *combo,
+                                                                               XfceKeyboardSettings      *settings);
+
 static void                      xfce_keyboard_settings_active_layout_cb      (GtkTreeView               *view,
                                                                                XfceKeyboardSettings      *settings);
 static void                      xfce_keyboard_settings_update_layout_buttons (XfceKeyboardSettings      *settings);
@@ -250,10 +265,12 @@ xfce_keyboard_settings_constructed (GObject *object)
   GObject              *kbd_shortcuts_view;
   GObject              *xkb_numlock;
   GObject              *button;
+  GtkTreeIter           iter;
 #ifdef HAVE_LIBXKLAVIER
   GObject              *xkb_use_system_default_checkbutton;
   GObject              *xkb_tab_layout_vbox;
   GObject              *xkb_model_combo;
+  GObject              *xkb_grpkey_combo;
   GObject              *xkb_layout_view;
   GObject              *xkb_layout_add_button;
   GObject              *xkb_layout_edit_button;
@@ -350,7 +367,7 @@ xfce_keyboard_settings_constructed (GObject *object)
                     settings);
 
   /* Keyboard model combo */
-  list_store = gtk_list_store_new (XKB_COMBO_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+  list_store = gtk_list_store_new (XKB_MODEL_COMBO_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store), 0, GTK_SORT_ASCENDING);
   xkl_config_registry_foreach_model (settings->priv->xkl_registry,
                                      xfce_keyboard_settings_add_model_to_combo,
@@ -371,6 +388,35 @@ xfce_keyboard_settings_constructed (GObject *object)
                     G_CALLBACK (xfce_keyboard_settings_model_changed_cb),
                     settings);
 
+  /* Group key combo */
+  list_store = gtk_list_store_new (XKB_GRPKEY_COMBO_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store), 0, GTK_SORT_ASCENDING);
+
+  gtk_list_store_append (list_store, &iter);
+  gtk_list_store_set (list_store, &iter,
+                      XKB_GRPKEY_COMBO_DESCRIPTION, "-",
+                      XKB_GRPKEY_COMBO_KEYS, "", -1);
+
+  xkl_config_registry_foreach_option (settings->priv->xkl_registry,
+                                      "grp",
+                                      xfce_keyboard_settings_add_grpkey_to_combo,
+                                      list_store);
+
+  xkb_grpkey_combo = gtk_builder_get_object (GTK_BUILDER (settings), "xkb_grpkey_combo");
+  gtk_combo_box_set_model (GTK_COMBO_BOX (xkb_grpkey_combo), GTK_TREE_MODEL (list_store));
+  g_object_unref (G_OBJECT (list_store));
+
+  gtk_cell_layout_clear (GTK_CELL_LAYOUT (xkb_grpkey_combo));
+  renderer = gtk_cell_renderer_text_new ();
+  g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
+  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (xkb_grpkey_combo), renderer, TRUE);
+  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (xkb_grpkey_combo), renderer, "text", 0);
+
+  xfce_keyboard_settings_init_grpkey (settings);
+  g_signal_connect (G_OBJECT (xkb_grpkey_combo), "changed",
+                    G_CALLBACK (xfce_keyboard_settings_grpkey_changed_cb),
+                    settings);
+
   /* Keyboard layout/variant treeview */
   settings->priv->layout_selection_treestore = NULL;
   xkb_layout_view = gtk_builder_get_object (GTK_BUILDER (settings), "xkb_layout_view");
@@ -407,6 +453,7 @@ xfce_keyboard_settings_finalize (GObject *object)
   XfceKeyboardSettings *settings = XFCE_KEYBOARD_SETTINGS (object);
 
 #ifdef HAVE_LIBXKLAVIER
+  xkl_config_rec_reset (settings->priv->xkl_rec_config);
   /* Stop xklavier engine */
 #ifdef HAVE_LIBXKLAVIER5
   xkl_engine_stop_listen (settings->priv->xkl_engine, XKLL_TRACK_KEYBOARD_STATE);
@@ -1011,6 +1058,7 @@ xfce_keyboard_settings_update_sensitive (GtkToggleButton *toggle, XfceKeyboardSe
 {
   GObject  *xkb_model_frame;
   GObject  *xkb_layout_frame;
+  GObject  *xkb_grpkey_frame;
   gboolean  active;
 
   g_return_val_if_fail (XFCE_IS_KEYBOARD_SETTINGS (settings), FALSE);
@@ -1018,9 +1066,11 @@ xfce_keyboard_settings_update_sensitive (GtkToggleButton *toggle, XfceKeyboardSe
   active = gtk_toggle_button_get_active (toggle);
   xkb_model_frame = gtk_builder_get_object (GTK_BUILDER (settings), "xkb_model_frame");
   xkb_layout_frame = gtk_builder_get_object (GTK_BUILDER (settings), "xkb_layout_frame");
+  xkb_grpkey_frame = gtk_builder_get_object (GTK_BUILDER (settings), "xkb_grpkey_frame");
 
   gtk_widget_set_sensitive (GTK_WIDGET (xkb_model_frame), !active);
   gtk_widget_set_sensitive (GTK_WIDGET (xkb_layout_frame), !active);
+  gtk_widget_set_sensitive (GTK_WIDGET (xkb_grpkey_frame), !active);
 
   return active;
 }
@@ -1260,8 +1310,8 @@ xfce_keyboard_settings_add_model_to_combo (XklConfigRegistry    *config_registry
 
   gtk_list_store_append (store, &iter);
   gtk_list_store_set (store, &iter,
-                      XKB_COMBO_DESCRIPTION, model_name,
-                      XKB_COMBO_MODELS, config_item->name, -1);
+                      XKB_MODEL_COMBO_DESCRIPTION, model_name,
+                      XKB_MODEL_COMBO_MODELS, config_item->name, -1);
   g_free (model_name);
 }
 
@@ -1286,7 +1336,7 @@ xfce_keyboard_settings_init_model (XfceKeyboardSettings *settings)
 
   while (item && !found)
     {
-      gtk_tree_model_get (model, &iter, XKB_COMBO_MODELS, &id, -1);
+      gtk_tree_model_get (model, &iter, XKB_MODEL_COMBO_MODELS, &id, -1);
       found = !strcmp (id, xkbmodel);
       g_free (id);
 
@@ -1303,6 +1353,69 @@ xfce_keyboard_settings_init_model (XfceKeyboardSettings *settings)
 
 
 static void
+xfce_keyboard_settings_add_grpkey_to_combo (XklConfigRegistry    *config_registry,
+                                           const XklConfigItem  *config_item,
+                                           gpointer              user_data)
+{
+  GtkListStore *store = GTK_LIST_STORE (user_data);
+  GtkTreeIter   iter;
+  gchar        *grpkey_name;
+
+  grpkey_name = xfce_keyboard_settings_xkb_description ((XklConfigItem *) config_item);
+
+  gtk_list_store_append (store, &iter);
+  gtk_list_store_set (store, &iter,
+                      XKB_GRPKEY_COMBO_DESCRIPTION, grpkey_name,
+                      XKB_GRPKEY_COMBO_KEYS, config_item->name, -1);
+  g_free (grpkey_name);
+}
+
+
+
+static void
+xfce_keyboard_settings_init_grpkey (XfceKeyboardSettings *settings)
+{
+  GObject      *view;
+  GtkTreeModel *model;
+  GtkTreeIter   iter;
+  gchar        *id;
+  gchar        *xkbgrpkey;
+  gboolean      item;
+  gboolean      found = FALSE;
+
+  view = gtk_builder_get_object (GTK_BUILDER (settings), "xkb_grpkey_combo");
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (view));
+
+  // FIXME: get the default value from xklavier?
+  xkbgrpkey = xfconf_channel_get_string (settings->priv->keyboard_layout_channel, "/Default/XkbOptions/Group", NULL);
+  item = gtk_tree_model_get_iter_first (model, &iter);
+
+  if (xkbgrpkey == NULL || *xkbgrpkey == 0)
+  {
+      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (view), &iter);
+      return;
+  }
+
+  while (item && !found)
+  {
+      gtk_tree_model_get (model, &iter, XKB_GRPKEY_COMBO_KEYS, &id, -1);
+      found = !strcmp (id, xkbgrpkey);
+      g_free (id);
+
+      if (found)
+      {
+          gtk_combo_box_set_active_iter (GTK_COMBO_BOX (view), &iter);
+          break;
+      }
+      item = gtk_tree_model_iter_next (model, &iter);
+  }
+
+  g_free (xkbgrpkey);
+}
+
+
+
+static void
 xfce_keyboard_settings_active_layout_cb (GtkTreeView           *view,
                                          XfceKeyboardSettings  *settings)
 {
@@ -1331,7 +1444,7 @@ xfce_keyboard_settings_model_changed_cb (GtkComboBox          *combo,
 
   gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
   model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
-  gtk_tree_model_get (model, &iter, XKB_COMBO_MODELS, &xkbmodel, -1);
+  gtk_tree_model_get (model, &iter, XKB_MODEL_COMBO_MODELS, &xkbmodel, -1);
   xfconf_channel_set_string (settings->priv->keyboard_layout_channel, "/Default/XkbModel", xkbmodel);
   g_free (xkbmodel);
 }
@@ -1339,6 +1452,24 @@ xfce_keyboard_settings_model_changed_cb (GtkComboBox          *combo,
 
 
 static void
+xfce_keyboard_settings_grpkey_changed_cb (GtkComboBox          *combo,
+                                          XfceKeyboardSettings *settings)
+{
+  GtkTreeModel *model;
+  GtkTreeIter   iter;
+  gchar        *xkbgrpkey;
+
+  gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
+  gtk_tree_model_get (model, &iter, XKB_GRPKEY_COMBO_KEYS, &xkbgrpkey, -1);
+  xfconf_channel_set_string (settings->priv->keyboard_layout_channel,
+                             "/Default/XkbOptions/Group", xkbgrpkey);
+  g_free (xkbgrpkey);
+}
+
+
+
+static void
 xfce_keyboard_settings_update_layout_buttons (XfceKeyboardSettings *settings)
 {
   GObject      *view;
diff --git a/xfsettingsd/keyboard-layout.c b/xfsettingsd/keyboard-layout.c
index ba2b61c..6c83ca4 100644
--- a/xfsettingsd/keyboard-layout.c
+++ b/xfsettingsd/keyboard-layout.c
@@ -48,10 +48,14 @@ static void xfce_keyboard_layout_helper_process_xmodmap           (void);
 static void xfce_keyboard_layout_helper_set_model                 (XfceKeyboardLayoutHelper      *helper);
 static void xfce_keyboard_layout_helper_set_layout                (XfceKeyboardLayoutHelper      *helper);
 static void xfce_keyboard_layout_helper_set_variant               (XfceKeyboardLayoutHelper      *helper);
+static void xfce_keyboard_layout_helper_set_grpkey                (XfceKeyboardLayoutHelper      *helper);
 static void xfce_keyboard_layout_helper_channel_property_changed  (XfconfChannel                 *channel,
                                                                    const gchar                   *property_name,
                                                                    const GValue                  *value,
                                                                    XfceKeyboardLayoutHelper      *helper);
+static gchar* xfce_keyboard_layout_get_option                     (gchar                        **options,
+                                                                   gchar                         *option_name,
+                                                                   gchar                        **other_options);
 
 struct _XfceKeyboardLayoutHelperClass
 {
@@ -106,6 +110,7 @@ xfce_keyboard_layout_helper_init (XfceKeyboardLayoutHelper *helper)
     xfce_keyboard_layout_helper_set_model (helper);
     xfce_keyboard_layout_helper_set_layout (helper);
     xfce_keyboard_layout_helper_set_variant (helper);
+    xfce_keyboard_layout_helper_set_grpkey (helper);
 
     xfce_keyboard_layout_helper_process_xmodmap ();
 }
@@ -202,6 +207,96 @@ xfce_keyboard_layout_helper_set_variant (XfceKeyboardLayoutHelper *helper)
 #endif /* HAVE_LIBXKLAVIER */
 }
 
+/**
+ * @options - Xkl config options (array of strings terminated in NULL)
+ * @option_name the name of the xkb option to look for (e.g., "grp:")
+ * @_other_options if not NULL, will be set to the input option string
+ *                 excluding @option_name. Needs to be freed with g_free().
+ * @return the string in @options array corresponding to @option_name,
+ *         or NULL if not found
+ */
+static gchar*
+xfce_keyboard_layout_get_option(gchar **options,
+                                gchar *option_name,
+                                gchar **_other_options)
+{
+    gchar **iter;
+    gchar  *option_value  = NULL;
+    gchar  *other_options = NULL;
+
+    for (iter = options; iter && *iter; iter++)
+    {
+        if (g_str_has_prefix(*iter, option_name))
+        {
+            option_value = *iter;
+        }
+        else if (_other_options)
+        {
+            gchar *tmp = other_options;
+            if (other_options)
+            {
+                other_options = g_strconcat(other_options, ",", *iter, NULL);
+            }
+            else
+            {
+                other_options = g_strdup(*iter);
+            }
+            g_free(tmp);
+        }
+    }
+
+    *_other_options = other_options;
+    return option_value;
+}
+
+static void
+xfce_keyboard_layout_helper_set_grpkey (XfceKeyboardLayoutHelper *helper)
+{
+#ifdef HAVE_LIBXKLAVIER
+    if (!helper->xkb_disable_settings)
+    {
+        gchar *grpkey;
+        gchar *xkl_grpkey;
+        gchar *other_options;
+
+        xkl_grpkey = xfce_keyboard_layout_get_option (helper->config->options,
+                                                      "grp:", &other_options);
+
+        grpkey = xfconf_channel_get_string (helper->channel, "/Default/XkbOptions/Group",
+                                            xkl_grpkey);
+        if (g_strcmp0 (grpkey, xkl_grpkey) != 0)
+        {
+            gchar *options_string;
+            if (other_options == NULL)
+            {
+                options_string = g_strdup (grpkey);
+            }
+            else
+            {
+                if (strlen(grpkey) != 0)
+                {
+                    options_string = g_strconcat (grpkey, ",", other_options, NULL);
+                }
+                else
+                {
+                    options_string = strdup(other_options);
+                }
+            }
+
+            g_strfreev (helper->config->options);
+            helper->config->options = g_strsplit(options_string, ",", 0);
+            xkl_config_rec_activate (helper->config, helper->engine);
+
+            xfsettings_dbg (XFSD_DEBUG_KEYBOARD_LAYOUT, "set grpkey to \"%s\"", grpkey);
+            g_free(options_string);
+        }
+
+        g_free (other_options);
+        g_free (grpkey);
+    }
+#endif /* HAVE_LIBXKLAVIER */
+}
+
 static void
 xfce_keyboard_layout_helper_channel_property_changed (XfconfChannel      *channel,
                                                const gchar               *property_name,
@@ -217,6 +312,7 @@ xfce_keyboard_layout_helper_channel_property_changed (XfconfChannel      *channe
         xfce_keyboard_layout_helper_set_model (helper);
         xfce_keyboard_layout_helper_set_layout (helper);
         xfce_keyboard_layout_helper_set_variant (helper);
+        xfce_keyboard_layout_helper_set_grpkey (helper);
     }
     else if (strcmp (property_name, "/Default/XkbModel") == 0)
     {
@@ -230,6 +326,10 @@ xfce_keyboard_layout_helper_channel_property_changed (XfconfChannel      *channe
     {
         xfce_keyboard_layout_helper_set_variant (helper);
     }
+    else if (strcmp (property_name, "/Default/XkbOptions/Group") == 0)
+    {
+        xfce_keyboard_layout_helper_set_grpkey (helper);
+    }
 
     xfce_keyboard_layout_helper_process_xmodmap ();
 }


More information about the Xfce4-commits mailing list