set_capabilities when frontend establishs ibus connection.
authorHuang Peng <shawn.p.huang@gmail.com>
Sat, 20 Sep 2008 03:14:36 +0000 (11:14 +0800)
committerHuang Peng <shawn.p.huang@gmail.com>
Sat, 20 Sep 2008 03:14:36 +0000 (11:14 +0800)
client/gtk2/ibusimcontext.c
client/qt4/ibus-input-context.cpp
client/qt4/ibus-input-context.h

index 9923c43..78f6788 100644 (file)
@@ -1,4 +1,4 @@
-/* vim:set et ts=4: */
+/* vim:set et sts=4: */
 /* ibus - The Input Bus
  * Copyright (C) 2008-2009 Huang Peng <shawn.p.huang@gmail.com>
  *
@@ -43,6 +43,8 @@ struct _IBusIMContextPrivate {
 
     GdkRectangle     cursor_area;
     gboolean         has_focus;
+
+    gint             caps;
 };
 
 static guint    _signal_commit_id = 0;
@@ -237,6 +239,7 @@ ibus_im_context_init     (IBusIMContext *obj)
 
     priv->ic = NULL;
     priv->has_focus = FALSE;
+    priv->caps = IBUS_CAP_PREEDIT | IBUS_CAP_FOCUS;
 
 
     // Create slave im context
@@ -499,11 +502,12 @@ ibus_im_context_set_use_preedit (GtkIMContext *context, gboolean use_preedit)
 
     if(priv->ic) {
         if (use_preedit) {
-            ibus_im_client_set_capabilities (_client, priv->ic, IBUS_CAP_FOCUS | IBUS_CAP_PREEDIT);
+            priv->caps |= IBUS_CAP_PREEDIT;
         }
         else {
-            ibus_im_client_set_capabilities (_client, priv->ic, IBUS_CAP_FOCUS);
+            priv->caps &= ~IBUS_CAP_PREEDIT;
         }
+        ibus_im_client_set_capabilities (_client, priv->ic, priv->caps);
     }
     gtk_im_context_set_use_preedit (priv->slave, use_preedit);
 }
@@ -799,8 +803,11 @@ ibus_im_context_set_ic (IBusIMContext *context, const gchar *ic)
     if (priv->ic == NULL) {
         priv->enable = FALSE;
     }
-    else if (priv->has_focus) {
-        ibus_im_context_focus_in (GTK_IM_CONTEXT (context));
+    else {
+        ibus_im_client_set_capabilities (_client, priv->ic, priv->caps);
+        if (priv->has_focus) {
+            ibus_im_context_focus_in (GTK_IM_CONTEXT (context));
+        }
     }
 }
 
index ed06baa..869c9f3 100644 (file)
@@ -33,7 +33,8 @@ IBusInputContext::IBusInputContext (QObject *parent, IBusClient *client, QString
          client (client),
          ic (ic),
          preedit_visible (false),
-         has_focus (false)
+         has_focus (false),
+         caps (IBUS_CAP_PREEDIT | IBUS_CAP_FOCUS)
 {
 }
 
@@ -136,11 +137,12 @@ IBusInputContext::setFocusWidget (QWidget *widget)
        else {
                /* KateView can not support preedit well. */
                if (widget->inherits("KateViewInternal")) {
-                       client->setCapabilities (this, IBUS_CAP_FOCUS);
+                       caps &= ~IBUS_CAP_PREEDIT;
                }
                else {
-                       client->setCapabilities (this, IBUS_CAP_FOCUS | IBUS_CAP_PREEDIT);
+                       caps |= IBUS_CAP_PREEDIT;
                }
+               client->setCapabilities (this, caps);
 
                has_focus = true;
                client->focusIn (this);
@@ -175,7 +177,11 @@ void
 IBusInputContext::setIC (QString ic)
 {
        this->ic = ic;
-       if (has_focus && !ic.isEmpty ()) {
+       if (ic.isEmpty ())
+               return;
+
+       client->setCapabilities (this, caps);
+       if (has_focus) {
                client->focusIn (this);
        }
 }
index a17e594..01545b0 100644 (file)
@@ -64,6 +64,7 @@ private:
        bool preedit_visible;
        int preedit_cursor_pos;
        bool has_focus;
+       int caps;
        QList <QList <quint32> > preedit_attrs;
 };