[gnome-terminal] profile: Add key and UI to set the width of ambiguous characters



commit 040e2cbfeb1460bd4bdbf19e3a84c4ee09e71e49
Author: Christian Persch <chpe gnome org>
Date:   Thu Apr 3 12:12:46 2014 +0200

    profile: Add key and UI to set the width of ambiguous characters
    
    When using UTF-8 encoding, there is a need to override the default of
    ambiguous-width characters being narrow, for compatibility with CJK.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=614618
    
    This requires vte commit 8b7a061714cd6050684b811c3fe5e314b302e417.

 src/org.gnome.Terminal.gschema.xml |    9 +++++
 src/profile-editor.c               |    7 ++++
 src/profile-preferences.ui         |   58 +++++++++++++++++++++++++++++++++++-
 src/terminal-enums.h               |    5 +++
 src/terminal-schemas.h             |    1 +
 src/terminal-screen.c              |    8 +++++
 6 files changed, 87 insertions(+), 1 deletions(-)
---
diff --git a/src/org.gnome.Terminal.gschema.xml b/src/org.gnome.Terminal.gschema.xml
index 9038fe0..f1e398c 100644
--- a/src/org.gnome.Terminal.gschema.xml
+++ b/src/org.gnome.Terminal.gschema.xml
@@ -41,6 +41,11 @@
     <value nick='hold' value='2'/>
   </enum>
 
+   <enum id='org.gnome.Terminal.CJKWidth'>
+    <value nick='narrow' value='1'/>
+    <value nick='wide'   value='2'/>
+  </enum>
+
   <!-- These really belong into some vte-built enums file, but
         using enums from other modules still has some
         problems. Just include a copy here for now.
@@ -325,6 +330,10 @@
       <default>'UTF-8'</default>
       <summary>Which encoding to use</summary>
     </key>
+    <key name="cjk-utf8-ambiguous-width" enum="org.gnome.Terminal.CJKWidth">
+      <default>'narrow'</default>
+      <summary>Whether ambiguous-width characters are narrow or wide when using UTF-8 encoding</summary>
+    </key>
   </schema>
 
   <!-- Keybinding settings -->
diff --git a/src/profile-editor.c b/src/profile-editor.c
index ea95320..e15cf9a 100644
--- a/src/profile-editor.c
+++ b/src/profile-editor.c
@@ -437,6 +437,7 @@ reset_compat_defaults_cb (GtkWidget *button,
   g_settings_reset (profile, TERMINAL_PROFILE_DELETE_BINDING_KEY);
   g_settings_reset (profile, TERMINAL_PROFILE_BACKSPACE_BINDING_KEY);
   g_settings_reset (profile, TERMINAL_PROFILE_ENCODING_KEY);
+  g_settings_reset (profile, TERMINAL_PROFILE_CJK_UTF8_AMBIGUOUS_WIDTH_KEY);
 }
 
 /*
@@ -1080,6 +1081,12 @@ terminal_profile_edit (GSettings  *profile,
                    w,
                    "active-id", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
 
+  w = (GtkWidget *) gtk_builder_get_object  (builder, "cjk-ambiguous-width-combobox");
+  g_settings_bind (profile, TERMINAL_PROFILE_CJK_UTF8_AMBIGUOUS_WIDTH_KEY,
+                   w,
+                   "active-id",
+                   G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+
   /* Finished! */
   terminal_util_bind_mnemonic_label_sensitivity (editor);
 
diff --git a/src/profile-preferences.ui b/src/profile-preferences.ui
index 55f3e70..1e6f084 100644
--- a/src/profile-preferences.ui
+++ b/src/profile-preferences.ui
@@ -126,6 +126,23 @@
       </row>
     </data>
   </object>
+  <object class="GtkListStore" id="cjk-ambiguous-width-model">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes" comments="ambiguous-width characers are">Narrow</col>
+        <col id="1" translatable="no">narrow</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes" comments="ambiguous-width characers are">Wide</col>
+        <col id="1" translatable="no">wide</col>
+      </row>
+    </data>
+  </object>
   <object class="GtkDialog" id="profile-editor-dialog">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -1839,7 +1856,7 @@
                   <object class="GtkTable" id="table30">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="n_rows">3</property>
+                    <property name="n_rows">4</property>
                     <property name="n_columns">3</property>
                     <property name="column_spacing">12</property>
                     <property name="row_spacing">6</property>
@@ -1944,6 +1961,45 @@
                         <property name="y_options">GTK_FILL</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkLabel" id="cjk-ambiguous-width-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Ambiguous-_width characters:</property>
+                        <property name="use_underline">True</property>
+                        <property name="justify">center</property>
+                        <property name="mnemonic_widget">cjk-ambiguous-width-combobox</property>
+                      </object>
+                      <packing>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"/>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBox" id="cjk-ambiguous-width-combobox">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="model">cjk-ambiguous-width-model</property>
+                        <property name="id-column">1</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="cjk-ambiguous-width-renderer"/>
+                          <attributes>
+                            <attribute name="text">0</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">3</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options">GTK_FILL</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>
diff --git a/src/terminal-enums.h b/src/terminal-enums.h
index 3ca76fd..6b85923 100644
--- a/src/terminal-enums.h
+++ b/src/terminal-enums.h
@@ -42,6 +42,11 @@ typedef enum {
   TERMINAL_SETTINGS_LIST_FLAG_ALLOW_EMPTY = 1 << 1
 } TerminalSettingsListFlags;
 
+typedef enum {
+  TERMINAL_CJK_WIDTH_NARROW = 1,
+  TERMINAL_CJK_WIDTH_WIDE   = 2
+} TerminalCJKWidth;
+
 G_END_DECLS
 
 #endif /* TERMINAL_ENUMS_H */
diff --git a/src/terminal-schemas.h b/src/terminal-schemas.h
index 2a41b3d..d88bf07 100644
--- a/src/terminal-schemas.h
+++ b/src/terminal-schemas.h
@@ -36,6 +36,7 @@ G_BEGIN_DECLS
 #define TERMINAL_PROFILE_BACKSPACE_BINDING_KEY          "backspace-binding"
 #define TERMINAL_PROFILE_BOLD_COLOR_KEY                 "bold-color"
 #define TERMINAL_PROFILE_BOLD_COLOR_SAME_AS_FG_KEY      "bold-color-same-as-fg"
+#define TERMINAL_PROFILE_CJK_UTF8_AMBIGUOUS_WIDTH_KEY   "cjk-utf8-ambiguous-width"
 #define TERMINAL_PROFILE_CURSOR_BLINK_MODE_KEY          "cursor-blink-mode"
 #define TERMINAL_PROFILE_CURSOR_SHAPE_KEY               "cursor-shape"
 #define TERMINAL_PROFILE_CUSTOM_COMMAND_KEY             "custom-command"
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index bfd4c61..7c501ee 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -770,6 +770,14 @@ terminal_screen_profile_changed_cb (GSettings     *profile,
       vte_terminal_set_encoding (vte_terminal, terminal_encoding_get_charset (encoding));
     }
 
+  if (!prop_name || prop_name == I_(TERMINAL_PROFILE_CJK_UTF8_AMBIGUOUS_WIDTH_KEY))
+    {
+      TerminalCJKWidth width;
+
+      width = g_settings_get_enum (profile, TERMINAL_PROFILE_CJK_UTF8_AMBIGUOUS_WIDTH_KEY);
+      vte_terminal_set_cjk_ambiguous_width (vte_terminal, (int) width);
+    }
+
   if (!prop_name ||
       prop_name == I_(TERMINAL_PROFILE_TITLE_KEY))
     {


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