[Xfce4-commits] <xfce4-settings:master> Add compose key combo configuration.

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


Updating branch refs/heads/master
         to 8717dfc2559099d7ce0fbf0a6ddf80660afd0081 (commit)
       from 60d4de469d9c7f592ce95608163aecb4c2009616 (commit)

commit 8717dfc2559099d7ce0fbf0a6ddf80660afd0081
Author: Igor Slepchin <igor.slepchin at gmail.com>
Date:   Fri Jul 27 15:30:42 2012 -0400

    Add compose key combo configuration.
    
    Bug 5487.

 dialogs/keyboard-settings/keyboard-dialog.glade    |   79 ++++++++++--
 dialogs/keyboard-settings/xfce-keyboard-settings.c |  128 ++++++++++++++++++++
 xfsettingsd/keyboard-layout.c                      |   52 ++++++---
 3 files changed, 230 insertions(+), 29 deletions(-)

diff --git a/dialogs/keyboard-settings/keyboard-dialog.glade b/dialogs/keyboard-settings/keyboard-dialog.glade
index 5a4c9e8..7eccd51 100644
--- a/dialogs/keyboard-settings/keyboard-dialog.glade
+++ b/dialogs/keyboard-settings/keyboard-dialog.glade
@@ -518,7 +518,7 @@
                     <property name="border_width">12</property>
                     <property name="spacing">6</property>
                     <child>
-                      <object class="GtkLabel" id="label16">
+                      <object class="GtkLabel" id="label14">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="xalign">0</property>
@@ -689,34 +689,85 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkFrame" id="xkb_grpkey_frame">
+                      <object class="GtkHBox" id="hbox4">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="label_xalign">0</property>
-                        <property name="shadow_type">none</property>
+                        <property name="border_width">0</property>
+                        <property name="spacing">6</property>
+                        <property name="homogeneous">True</property>
                         <child>
-                          <object class="GtkAlignment" id="alignment6">
+                          <object class="GtkFrame" id="xkb_grpkey_frame">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="border_width">6</property>
-                            <property name="left_padding">12</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">none</property>
                             <child>
-                              <object class="GtkComboBox" id="xkb_grpkey_combo">
+                              <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">0</property>
+                          </packing>
                         </child>
-                        <child type="label">
-                          <object class="GtkLabel" id="label1">
+                        <child>
+                          <object class="GtkFrame" id="xkb_composekey_frame">
                             <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>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">none</property>
+                            <child>
+                              <object class="GtkAlignment" id="alignment7">
+                                <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_composekey_combo">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                            <child type="label">
+                              <object class="GtkLabel" id="label15">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">Compose key</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">1</property>
+                          </packing>
                         </child>
                       </object>
                       <packing>
diff --git a/dialogs/keyboard-settings/xfce-keyboard-settings.c b/dialogs/keyboard-settings/xfce-keyboard-settings.c
index b2de750..61af9a8 100644
--- a/dialogs/keyboard-settings/xfce-keyboard-settings.c
+++ b/dialogs/keyboard-settings/xfce-keyboard-settings.c
@@ -77,6 +77,13 @@ enum
 
 enum
 {
+    XKB_COMPOSEKEY_COMBO_DESCRIPTION = 0,
+    XKB_COMPOSEKEY_COMBO_KEYS,
+    XKB_COMPOSEKEY_COMBO_NUM_COLUMNS
+};
+
+enum
+{
     XKB_TREE_LAYOUTS = 0,
     XKB_TREE_LAYOUTS_NAMES,
     XKB_TREE_VARIANTS,
@@ -156,6 +163,13 @@ static void                      xfce_keyboard_settings_init_grpkey           (X
 static void                      xfce_keyboard_settings_grpkey_changed_cb     (GtkComboBox               *combo,
                                                                                XfceKeyboardSettings      *settings);
 
+static void                      xfce_keyboard_settings_add_compkey_to_combo  (XklConfigRegistry         *config_registry,
+                                                                               const XklConfigItem       *config_item,
+                                                                               gpointer                   user_data);
+static void                      xfce_keyboard_settings_init_compkey          (XfceKeyboardSettings      *settings);
+static void                      xfce_keyboard_settings_compkey_changed_cb    (GtkComboBox               *combo,
+                                                                               XfceKeyboardSettings      *settings);
+
 static void                      xfce_keyboard_settings_update_layout_buttons (XfceKeyboardSettings      *settings);
 static void                      xfce_keyboard_settings_edit_layout_button_cb (GtkWidget                 *widget,
                                                                                XfceKeyboardSettings      *settings);
@@ -281,6 +295,7 @@ xfce_keyboard_settings_constructed (GObject *object)
   GObject              *xkb_tab_layout_vbox;
   GObject              *xkb_model_combo;
   GObject              *xkb_grpkey_combo;
+  GObject              *xkb_compkey_combo;
   GObject              *xkb_layout_view;
   GObject              *xkb_layout_add_button;
   GObject              *xkb_layout_edit_button;
@@ -435,6 +450,35 @@ xfce_keyboard_settings_constructed (GObject *object)
                     G_CALLBACK (xfce_keyboard_settings_grpkey_changed_cb),
                     settings);
 
+  /* Compose key combo */
+  list_store = gtk_list_store_new (XKB_COMPOSEKEY_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_COMPOSEKEY_COMBO_DESCRIPTION, "-",
+                      XKB_COMPOSEKEY_COMBO_KEYS, "", -1);
+
+  xkl_config_registry_foreach_option (settings->priv->xkl_registry,
+                                      "Compose key",
+                                      xfce_keyboard_settings_add_compkey_to_combo,
+                                      list_store);
+
+  xkb_compkey_combo = gtk_builder_get_object (GTK_BUILDER (settings), "xkb_composekey_combo");
+  gtk_combo_box_set_model (GTK_COMBO_BOX (xkb_compkey_combo), GTK_TREE_MODEL (list_store));
+  g_object_unref (G_OBJECT (list_store));
+
+  gtk_cell_layout_clear (GTK_CELL_LAYOUT (xkb_compkey_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_compkey_combo), renderer, TRUE);
+  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (xkb_compkey_combo), renderer, "text", 0);
+
+  xfce_keyboard_settings_init_compkey (settings);
+  g_signal_connect (G_OBJECT (xkb_compkey_combo), "changed",
+                    G_CALLBACK (xfce_keyboard_settings_compkey_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");
@@ -1083,6 +1127,7 @@ xfce_keyboard_settings_update_sensitive (GtkToggleButton *toggle, XfceKeyboardSe
   GObject  *xkb_model_frame;
   GObject  *xkb_layout_frame;
   GObject  *xkb_grpkey_frame;
+  GObject  *xkb_compkey_frame;
   gboolean  active;
 
   g_return_val_if_fail (XFCE_IS_KEYBOARD_SETTINGS (settings), FALSE);
@@ -1091,10 +1136,12 @@ xfce_keyboard_settings_update_sensitive (GtkToggleButton *toggle, XfceKeyboardSe
   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");
+  xkb_compkey_frame = gtk_builder_get_object (GTK_BUILDER (settings), "xkb_composekey_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);
+  gtk_widget_set_sensitive (GTK_WIDGET (xkb_compkey_frame), !active);
 
   return active;
 }
@@ -1410,6 +1457,69 @@ xfce_keyboard_settings_init_grpkey (XfceKeyboardSettings *settings)
 
 
 static void
+xfce_keyboard_settings_add_compkey_to_combo (XklConfigRegistry    *config_registry,
+                                           const XklConfigItem  *config_item,
+                                           gpointer              user_data)
+{
+  GtkListStore *store = GTK_LIST_STORE (user_data);
+  GtkTreeIter   iter;
+  gchar        *compkey_name;
+
+  compkey_name = xfce_keyboard_settings_xkb_description ((XklConfigItem *) config_item);
+
+  gtk_list_store_append (store, &iter);
+  gtk_list_store_set (store, &iter,
+                      XKB_COMPOSEKEY_COMBO_DESCRIPTION, compkey_name,
+                      XKB_COMPOSEKEY_COMBO_KEYS, config_item->name, -1);
+  g_free (compkey_name);
+}
+
+
+
+static void
+xfce_keyboard_settings_init_compkey (XfceKeyboardSettings *settings)
+{
+  GObject      *view;
+  GtkTreeModel *model;
+  GtkTreeIter   iter;
+  gchar        *id;
+  gchar        *xkbcompkey;
+  gboolean      item;
+  gboolean      found = FALSE;
+
+  view = gtk_builder_get_object (GTK_BUILDER (settings), "xkb_composekey_combo");
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (view));
+
+  // FIXME: get the default value from xklavier?
+  xkbcompkey = xfconf_channel_get_string (settings->priv->keyboard_layout_channel, "/Default/XkbOptions/Compose", NULL);
+  item = gtk_tree_model_get_iter_first (model, &iter);
+
+  if (xkbcompkey == NULL || *xkbcompkey == 0)
+  {
+      gtk_combo_box_set_active_iter (GTK_COMBO_BOX (view), &iter);
+      return;
+  }
+
+  while (item && !found)
+  {
+      gtk_tree_model_get (model, &iter, XKB_COMPOSEKEY_COMBO_KEYS, &id, -1);
+      found = !strcmp (id, xkbcompkey);
+      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 (xkbcompkey);
+}
+
+
+
+static void
 xfce_keyboard_settings_row_activated_cb (GtkTreeView          *tree_view,
                                          GtkTreePath          *path,
                                          GtkTreeViewColumn    *column,
@@ -1455,6 +1565,24 @@ xfce_keyboard_settings_grpkey_changed_cb (GtkComboBox          *combo,
 
 
 static void
+xfce_keyboard_settings_compkey_changed_cb (GtkComboBox          *combo,
+                                           XfceKeyboardSettings *settings)
+{
+  GtkTreeModel *model;
+  GtkTreeIter   iter;
+  gchar        *xkbcompkey;
+
+  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_COMPOSEKEY_COMBO_KEYS, &xkbcompkey, -1);
+  xfconf_channel_set_string (settings->priv->keyboard_layout_channel,
+                             "/Default/XkbOptions/Compose", xkbcompkey);
+  g_free (xkbcompkey);
+}
+
+
+
+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 efce20a..f89bc74 100644
--- a/xfsettingsd/keyboard-layout.c
+++ b/xfsettingsd/keyboard-layout.c
@@ -50,12 +50,13 @@ static void xfce_keyboard_layout_helper_set_model                 (XfceKeyboardL
 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_set_composekey            (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,
+                                                                   const gchar                         *option_name,
                                                                    gchar                        **other_options);
 static GdkFilterReturn handle_xevent                              (GdkXEvent                     *xev,
                                                                    GdkEvent                      *event,
@@ -125,6 +126,7 @@ xfce_keyboard_layout_helper_init (XfceKeyboardLayoutHelper *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_set_composekey (helper);
 
     xfce_keyboard_layout_helper_process_xmodmap ();
 }
@@ -263,7 +265,7 @@ xfce_keyboard_layout_helper_set_variant (XfceKeyboardLayoutHelper *helper)
  */
 static gchar*
 xfce_keyboard_layout_get_option (gchar **options,
-                                 gchar *option_name,
+                                 const gchar *option_name,
                                  gchar **_other_options)
 {
     gchar **iter;
@@ -296,32 +298,34 @@ xfce_keyboard_layout_get_option (gchar **options,
 }
 
 static void
-xfce_keyboard_layout_helper_set_grpkey (XfceKeyboardLayoutHelper *helper)
+xfce_keyboard_layout_helper_set_option (XfceKeyboardLayoutHelper *helper,
+                                        const gchar *xkb_option_name,
+                                        const gchar *xfconf_option_name)
 {
 #ifdef HAVE_LIBXKLAVIER
     if (!helper->xkb_disable_settings)
     {
-        gchar *grpkey;
-        gchar *xkl_grpkey;
+        gchar *option_value;
+        gchar *xkl_option_value;
         gchar *other_options;
 
-        xkl_grpkey = xfce_keyboard_layout_get_option (helper->config->options,
-                                                      "grp:", &other_options);
+        xkl_option_value = xfce_keyboard_layout_get_option (helper->config->options,
+                                                            xkb_option_name, &other_options);
 
-        grpkey = xfconf_channel_get_string (helper->channel, "/Default/XkbOptions/Group",
-                                            xkl_grpkey);
-        if (g_strcmp0 (grpkey, xkl_grpkey) != 0)
+        option_value = xfconf_channel_get_string (helper->channel, xfconf_option_name,
+                                                  xkl_option_value);
+        if (g_strcmp0 (option_value, xkl_option_value) != 0)
         {
             gchar *options_string;
             if (other_options == NULL)
             {
-                options_string = g_strdup (grpkey);
+                options_string = g_strdup (option_value);
             }
             else
             {
-                if (strlen(grpkey) != 0)
+                if (strlen(option_value) != 0)
                 {
-                    options_string = g_strconcat (grpkey, ",", other_options, NULL);
+                    options_string = g_strconcat (option_value, ",", other_options, NULL);
                 }
                 else
                 {
@@ -333,17 +337,30 @@ xfce_keyboard_layout_helper_set_grpkey (XfceKeyboardLayoutHelper *helper)
             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);
+            xfsettings_dbg (XFSD_DEBUG_KEYBOARD_LAYOUT, "set %s to \"%s\"",
+                            xkb_option_name, option_value);
             g_free(options_string);
         }
 
         g_free (other_options);
-        g_free (grpkey);
+        g_free (option_value);
     }
 #endif /* HAVE_LIBXKLAVIER */
 }
 
 static void
+xfce_keyboard_layout_helper_set_grpkey (XfceKeyboardLayoutHelper *helper)
+{
+    xfce_keyboard_layout_helper_set_option (helper, "grp:", "/Default/XkbOptions/Group");
+}
+
+static void
+xfce_keyboard_layout_helper_set_composekey (XfceKeyboardLayoutHelper *helper)
+{
+    xfce_keyboard_layout_helper_set_option (helper, "compose:", "/Default/XkbOptions/Compose");
+}
+
+static void
 xfce_keyboard_layout_helper_channel_property_changed (XfconfChannel      *channel,
                                                const gchar               *property_name,
                                                const GValue              *value,
@@ -376,6 +393,10 @@ xfce_keyboard_layout_helper_channel_property_changed (XfconfChannel      *channe
     {
         xfce_keyboard_layout_helper_set_grpkey (helper);
     }
+    else if (strcmp (property_name, "/Default/XkbOptions/Compose") == 0)
+    {
+        xfce_keyboard_layout_helper_set_composekey (helper);
+    }
 
     xfce_keyboard_layout_helper_process_xmodmap ();
 }
@@ -409,6 +430,7 @@ xfce_keyboard_layout_reset_xkl_config (XklEngine *xklengine,
         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_set_composekey (helper);
 
         xfce_keyboard_layout_helper_process_xmodmap ();
     }


More information about the Xfce4-commits mailing list