ibus-daemon: trigger engine to send RegisterProperties when panel appears
authorDaiki Ueno <ueno@unixuser.org>
Wed, 12 Sep 2012 01:06:57 +0000 (10:06 +0900)
committerDaiki Ueno <ueno@unixuser.org>
Wed, 12 Sep 2012 01:06:57 +0000 (10:06 +0900)
BUG=none

Review URL: https://codereview.appspot.com/6506094

bus/engineproxy.c
bus/engineproxy.h
bus/ibusimpl.c

index 417b47c..4d8c18b 100644 (file)
@@ -55,11 +55,16 @@ struct _BusEngineProxy {
     IBusText *surrounding_text;
     guint     surrounding_cursor_pos;
     guint     selection_anchor_pos;
+
+    /* cached properties */
+    IBusPropList *prop_list;
 };
 
 struct _BusEngineProxyClass {
     IBusProxyClass parent;
     /* class members */
+    void (* register_properties) (IBusPropList *prop_list);
+    void (* update_property) (IBusProperty *prop);
 };
 
 enum {
@@ -103,6 +108,12 @@ static void     bus_engine_proxy_get_property   (BusEngineProxy      *engine,
                                                  guint                prop_id,
                                                  GValue              *value,
                                                  GParamSpec          *pspec);
+static void     bus_engine_proxy_real_register_properties
+                                                (BusEngineProxy      *engine,
+                                                 IBusPropList        *prop_list);
+static void     bus_engine_proxy_real_update_property
+                                                (BusEngineProxy      *engine,
+                                                 IBusProperty        *prop);
 static void     bus_engine_proxy_real_destroy   (IBusProxy           *proxy);
 static void     bus_engine_proxy_g_signal       (GDBusProxy          *proxy,
                                                  const gchar         *sender_name,
@@ -125,6 +136,9 @@ bus_engine_proxy_class_init (BusEngineProxyClass *class)
     gobject_class->set_property = (GObjectSetPropertyFunc)bus_engine_proxy_set_property;
     gobject_class->get_property = (GObjectGetPropertyFunc)bus_engine_proxy_get_property;
 
+    class->register_properties = bus_engine_proxy_real_register_properties;
+    class->update_property = bus_engine_proxy_real_update_property;
+
     IBUS_PROXY_CLASS (class)->destroy = bus_engine_proxy_real_destroy;
     G_DBUS_PROXY_CLASS (class)->g_signal = bus_engine_proxy_g_signal;
 
@@ -334,7 +348,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *class)
         g_signal_new (I_("register-properties"),
             G_TYPE_FROM_CLASS (class),
             G_SIGNAL_RUN_LAST,
-            0,
+            G_STRUCT_OFFSET (BusEngineProxyClass, register_properties),
             NULL, NULL,
             bus_marshal_VOID__OBJECT,
             G_TYPE_NONE,
@@ -345,7 +359,7 @@ bus_engine_proxy_class_init (BusEngineProxyClass *class)
         g_signal_new (I_("update-property"),
             G_TYPE_FROM_CLASS (class),
             G_SIGNAL_RUN_LAST,
-            0,
+            G_STRUCT_OFFSET (BusEngineProxyClass, update_property),
             NULL, NULL,
             bus_marshal_VOID__OBJECT,
             G_TYPE_NONE,
@@ -395,6 +409,24 @@ bus_engine_proxy_get_property (BusEngineProxy *engine,
 }
 
 static void
+bus_engine_proxy_real_register_properties (BusEngineProxy *engine,
+                                           IBusPropList   *prop_list)
+{
+    if (engine->prop_list)
+        g_object_unref (engine->prop_list);
+    engine->prop_list = (IBusPropList *) g_object_ref_sink (prop_list);
+}
+
+static void
+bus_engine_proxy_real_update_property (BusEngineProxy *engine,
+                                       IBusProperty   *prop)
+{
+    g_return_if_fail (prop);
+    if (engine->prop_list)
+        ibus_prop_list_update_property (engine->prop_list, prop);
+}
+
+static void
 bus_engine_proxy_real_destroy (IBusProxy *proxy)
 {
     BusEngineProxy *engine = (BusEngineProxy *)proxy;
@@ -414,6 +446,11 @@ bus_engine_proxy_real_destroy (IBusProxy *proxy)
         engine->surrounding_text = NULL;
     }
 
+    if (engine->prop_list) {
+        g_object_unref (engine->prop_list);
+        engine->prop_list = NULL;
+    }
+
     IBUS_PROXY_CLASS (bus_engine_proxy_parent_class)->destroy ((IBusProxy *)engine);
 }
 
@@ -1203,6 +1240,14 @@ bus_engine_proxy_get_desc (BusEngineProxy *engine)
     return engine->desc;
 }
 
+IBusPropList *
+bus_engine_proxy_get_properties (BusEngineProxy *engine)
+{
+    g_assert (BUS_IS_ENGINE_PROXY (engine));
+
+    return engine->prop_list;
+}
+
 gboolean
 bus_engine_proxy_is_enabled (BusEngineProxy *engine)
 {
index f61fc34..b050724 100644 (file)
@@ -243,5 +243,12 @@ void             bus_engine_proxy_cancel_hand_writing
                                                     (BusEngineProxy        *engine,
                                                      guint                  n_strokes);
 
+/**
+ * bus_engine_proxy_get_properties:
+ *
+ * Get an IBusPropList object associated with the engine.
+ */
+IBusPropList    *bus_engine_proxy_get_properties    (BusEngineProxy        *engine);
+
 G_END_DECLS
 #endif
index 650aace..25d2523 100644 (file)
@@ -248,6 +248,7 @@ _dbus_name_owner_changed_cb (BusDBusImpl   *dbus,
         if (g_strcmp0 (new_name, "") != 0) {
             /* a Panel process is started. */
             BusConnection *connection;
+            BusInputContext *context = NULL;
 
             if (ibus->panel != NULL) {
                 ibus_proxy_destroy ((IBusProxy *) ibus->panel);
@@ -266,10 +267,24 @@ _dbus_name_owner_changed_cb (BusDBusImpl   *dbus,
                               ibus);
 
             if (ibus->focused_context != NULL) {
-                bus_panel_proxy_focus_in (ibus->panel, ibus->focused_context);
+                context = ibus->focused_context;
             }
             else if (ibus->use_global_engine) {
-                bus_panel_proxy_focus_in (ibus->panel, ibus->fake_context);
+                context = ibus->fake_context;
+            }
+
+            if (context != NULL) {
+                BusEngineProxy *engine;
+
+                bus_panel_proxy_focus_in (ibus->panel, context);
+
+                engine = bus_input_context_get_engine (context);
+                if (engine != NULL) {
+                    IBusPropList *prop_list =
+                        bus_engine_proxy_get_properties (engine);
+                    bus_panel_proxy_register_properties (ibus->panel,
+                                                         prop_list);
+                }
             }
         }
     }