Add embed_preedit support to ibus.
authorPeng Wu <epico@dhcp-65-116.nay.redhat.com>
Tue, 9 Feb 2010 02:26:20 +0000 (10:26 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Sat, 20 Feb 2010 02:43:13 +0000 (10:43 +0800)
bus/ibusimpl.c
bus/ibusimpl.h
bus/inputcontext.c
data/ibus.schemas.in
setup/main.py
setup/setup.ui

index 9a59f7c..050d734 100644 (file)
@@ -61,6 +61,10 @@ static void     bus_ibus_impl_set_preload_engines
 static void     bus_ibus_impl_set_use_sys_layout
                                                 (BusIBusImpl        *ibus,
                                                  GValue             *value);
+static void     bus_ibus_impl_set_embed_preedit_text
+                                                (BusIBusImpl        *ibus,
+                                                 GValue             *value);
+
 static void     bus_ibus_impl_set_use_global_engine
                                                 (BusIBusImpl        *ibus,
                                                  GValue             *value);
@@ -229,6 +233,15 @@ bus_ibus_impl_set_use_sys_layout (BusIBusImpl *ibus,
 }
 
 static void
+bus_ibus_impl_set_embed_preedit_text (BusIBusImpl        *ibus,
+                                                            GValue             *value){
+    if (value != NULL && G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) {
+        ibus->embed_preedit_text = g_value_get_boolean (value);
+    }
+
+}
+
+static void
 bus_ibus_impl_set_use_global_engine (BusIBusImpl *ibus,
                                      GValue      *value)
 {
@@ -343,6 +356,7 @@ bus_ibus_impl_reload_config (BusIBusImpl *ibus)
         { "general", "preload_engines", bus_ibus_impl_set_preload_engines },
         { "general", "use_system_keyboard_layout", bus_ibus_impl_set_use_sys_layout },
         { "general", "use_global_engine", bus_ibus_impl_set_use_global_engine },
+        { "general", "embed_preedit_text", bus_ibus_impl_set_embed_preedit_text },
         { NULL, NULL, NULL },
     };
 
@@ -387,6 +401,7 @@ _config_value_changed_cb (IBusConfig  *config,
         { "general", "preload_engines",    bus_ibus_impl_set_preload_engines },
         { "general", "use_system_keyboard_layout", bus_ibus_impl_set_use_sys_layout },
         { "general", "use_global_engine", bus_ibus_impl_set_use_global_engine },
+        { "general", "embed_preedit_text", bus_ibus_impl_set_embed_preedit_text },
         { NULL, NULL, NULL },
     };
 
@@ -535,6 +550,7 @@ bus_ibus_impl_init (BusIBusImpl *ibus)
     ibus->keymap = ibus_keymap_get ("us");
 
     ibus->use_sys_layout = FALSE;
+    ibus->embed_preedit_text = TRUE;
     ibus->use_global_engine = TRUE;
     ibus->global_engine_enabled = FALSE;
     ibus->global_engine = NULL;
index 1027dc4..4fa7c29 100644 (file)
@@ -74,6 +74,7 @@ struct _BusIBusImpl {
     GList *component_list;
 
     gboolean use_sys_layout;
+    gboolean embed_preedit_text;
 
     BusRegistry     *registry;
 
index 01a2450..fb67220 100644 (file)
@@ -128,6 +128,17 @@ static IBusPropList    *props_empty = NULL;
 
 G_DEFINE_TYPE (BusInputContext, bus_input_context, IBUS_TYPE_SERVICE)
 
+static inline gboolean is_embed_preedit_text(){
+    BusIBusImpl * ibusimpl = BUS_DEFAULT_IBUS;
+    return ibusimpl->embed_preedit_text;
+}
+
+#define IS_CLIENT_CAPABLE_PREEDIT(context)                     \
+    ((context->capabilities & IBUS_CAP_PREEDIT_TEXT) == IBUS_CAP_PREEDIT_TEXT)
+
+#define IS_CLIENT_FORCE_PREEDIT(context)                       \
+  (IS_CLIENT_CAPABLE_PREEDIT(context) && (context->capabilities & IBUS_CAP_FOCUS) == 0)
+
 static void
 _connection_destroy_cb (BusConnection   *connection,
                         BusInputContext *context)
@@ -1177,7 +1188,7 @@ bus_input_context_focus_in (BusInputContext *context)
     if (context->capabilities & IBUS_CAP_FOCUS) {
         g_signal_emit (context, context_signals[FOCUS_IN], 0);
         if (context->engine && context->enabled) {
-            if (context->preedit_visible && (context->capabilities & IBUS_CAP_PREEDIT_TEXT) == 0) {
+          if (context->preedit_visible && !(is_embed_preedit_text() && IS_CLIENT_CAPABLE_PREEDIT(context)) && !IS_CLIENT_FORCE_PREEDIT(context)) {
                 g_signal_emit (context,
                                context_signals[UPDATE_PREEDIT_TEXT],
                                0,
@@ -1218,7 +1229,7 @@ bus_input_context_focus_out (BusInputContext *context)
     context->has_focus = FALSE;
 
     if (context->capabilities & IBUS_CAP_FOCUS) {
-        if (context->preedit_visible && (context->capabilities & IBUS_CAP_PREEDIT_TEXT) == 0) {
+         if (context->preedit_visible && !(is_embed_preedit_text() && IS_CLIENT_CAPABLE_PREEDIT(context)) && !IS_CLIENT_FORCE_PREEDIT(context) ) {
             g_signal_emit (context, context_signals[HIDE_PREEDIT_TEXT], 0);
         }
         if (context->auxiliary_visible && (context->capabilities & IBUS_CAP_AUXILIARY_TEXT) == 0) {
@@ -1293,7 +1304,7 @@ bus_input_context_update_preedit_text (BusInputContext *context,
     context->preedit_cursor_pos = cursor_pos;
     context->preedit_visible = visible;
 
-    if (context->capabilities & IBUS_CAP_PREEDIT_TEXT) {
+    if ((is_embed_preedit_text() && IS_CLIENT_CAPABLE_PREEDIT(context)) || IS_CLIENT_FORCE_PREEDIT(context)) {
         bus_input_context_send_signal (context,
                                        "UpdatePreeditText",
                                        IBUS_TYPE_TEXT, &(context->preedit_text),
@@ -1322,7 +1333,7 @@ bus_input_context_show_preedit_text (BusInputContext *context)
 
     context->preedit_visible = TRUE;
 
-    if ((context->capabilities & IBUS_CAP_PREEDIT_TEXT) == IBUS_CAP_PREEDIT_TEXT) {
+    if ((is_embed_preedit_text() && IS_CLIENT_CAPABLE_PREEDIT(context)) || IS_CLIENT_FORCE_PREEDIT(context)) {
         bus_input_context_send_signal (context,
                                        "ShowPreeditText",
                                        G_TYPE_INVALID);
@@ -1345,7 +1356,7 @@ bus_input_context_hide_preedit_text (BusInputContext *context)
 
     context->preedit_visible = FALSE;
 
-    if ((context->capabilities & IBUS_CAP_PREEDIT_TEXT) == IBUS_CAP_PREEDIT_TEXT) {
+    if (is_embed_preedit_text() && (context->capabilities & IBUS_CAP_PREEDIT_TEXT) == IBUS_CAP_PREEDIT_TEXT) {
         bus_input_context_send_signal (context,
                                        "HidePreeditText",
                                        G_TYPE_INVALID);
index c5ce128..bd734b3 100644 (file)
       </locale>
     </schema>
     <schema>
+      <key>/schemas/desktop/ibus/general/embed_preedit_text</key>
+      <applyto>/desktop/ibus/general/embed_preedit_text</applyto>
+      <owner>ibus</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+        <short>Embed Preedit Text</short>
+           <long>Embed Preedit Text in Application Window</long>
+      </locale>
+    </schema>
+    <schema>
       <key>/schemas/desktop/ibus/general/use_global_engine</key>
       <applyto>/desktop/ibus/general/use_global_engine</applyto>
       <owner>ibus</owner>
index 14eb278..d342f1e 100644 (file)
@@ -175,6 +175,12 @@ class Setup(object):
             self.__config.get_value("panel", "show_im_name", False))
         self.__checkbutton_show_im_name.connect("toggled", self.__checkbutton_show_im_name_toggled_cb)
 
+        # embed preedit text
+        self.__checkbutton_embed_preedit_text = self.__builder.get_object("checkbutton_embed_preedit_text")
+        self.__checkbutton_embed_preedit_text.set_active(
+            self.__config.get_value("general", "embed_preedit_text", True))
+        self.__checkbutton_embed_preedit_text.connect("toggled", self.__checkbutton_embed_preedit_text_toggled_cb)
+
         # use system keyboard layout setting
         self.__checkbutton_use_sys_layout = self.__builder.get_object("checkbutton_use_sys_layout")
         self.__checkbutton_use_sys_layout.set_active(
@@ -426,6 +432,10 @@ class Setup(object):
         value = self.__checkbutton_show_im_name.get_active()
         self.__config.set_value("panel", "show_im_name", value)
 
+    def __checkbutton_embed_preedit_text_toggled_cb(self, button):
+        value = self.__checkbutton_embed_preedit_text.get_active()
+        self.__config.set_value("general", "embed_preedit_text", value)
+
     def __checkbutton_use_sys_layout_toggled_cb(self, button):
         value = self.__checkbutton_use_sys_layout.get_active()
         self.__config.set_value("general", "use_system_keyboard_layout", value)
index aa2b44f..c22b137 100644 (file)
                                   </packing>
                                 </child>
                                 <child>
+                                  <object class="GtkCheckButton" id="checkbutton_embed_preedit_text">
+                                    <property name="label" translatable="yes">Embed preedit text in application window</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="tooltip_text" translatable="yes">Embed the preedit text of input method in the application window</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="position">5</property>
+                                  </packing>
+                                </child>
+                                <child>
                                   <object class="GtkHBox" id="hbox9">
                                     <property name="visible">True</property>
                                     <property name="homogeneous">True</property>
                                     </child>
                                   </object>
                                   <packing>
-                                    <property name="position">5</property>
+                                    <property name="position">6</property>
                                   </packing>
                                 </child>
                               </object>