aboutsummaryrefslogtreecommitdiff
path: root/lib/main.vala
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2014-03-27 23:41:17 +1300
committerWilliam Hua <william.hua@canonical.com>2014-03-27 23:41:17 +1300
commitf49c94edd2444a5b852772419be72463c4a1571a (patch)
tree288c76a8995d60bf30077c90cbff47b933bd7736 /lib/main.vala
parentc6cd63badf80dd5e04de088e531faf9fe9c26097 (diff)
parenta08ab0c4f8f80366eb7c08795e9d5407aef8ecff (diff)
downloadayatana-indicator-keyboard-f49c94edd2444a5b852772419be72463c4a1571a.tar.gz
ayatana-indicator-keyboard-f49c94edd2444a5b852772419be72463c4a1571a.tar.bz2
ayatana-indicator-keyboard-f49c94edd2444a5b852772419be72463c4a1571a.zip
Merge 1290881.
Diffstat (limited to 'lib/main.vala')
-rw-r--r--lib/main.vala65
1 files changed, 55 insertions, 10 deletions
diff --git a/lib/main.vala b/lib/main.vala
index 473c52d1..8d8c213f 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -37,7 +37,8 @@ public class Indicator.Keyboard.Service : Object {
private uint focused_window_id;
private IBus.Bus? ibus;
- private IBus.PanelService? panel_service;
+ private IBusPanel? ibus_panel;
+ private ulong ibus_connected_id;
private uint panel_timeout;
private Source[]? sources;
@@ -135,6 +136,43 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
+ private IBusPanel? get_ibus_panel () {
+ if (ibus_panel == null && get_ibus ().is_connected ()) {
+ var connection = get_ibus ().get_connection ();
+ var name = "org.freedesktop.IBus.Panel";
+ var path = "/org/freedesktop/IBus/Panel";
+
+ try {
+ ibus_panel = connection.get_proxy_sync (name, path);
+
+ ((!) ibus_panel).properties_registered.connect ((variant) => {
+ var properties = new IBus.PropList ();
+ properties.deserialize (variant);
+
+ if (properties is IBus.PropList) {
+ handle_properties_registered ((!) (properties as IBus.PropList));
+ }
+ });
+ ((!) ibus_panel).property_updated.connect ((variant) => {
+ var type = IBus.PropType.NORMAL;
+ var state = IBus.PropState.INCONSISTENT;
+ var text = new IBus.Text.from_static_string ("");
+ var property = new IBus.Property ("", type, text, null, text, false, false, state, null);
+ property.deserialize (variant);
+
+ if (property is IBus.Property) {
+ handle_property_updated ((!) (property as IBus.Property));
+ }
+ });
+ } catch (IOError error) {
+ warning ("error: %s", error.message);
+ }
+ }
+
+ return ibus_panel;
+ }
+
+ [DBus (visible = false)]
public void up () {
if (loop == null) {
loop = new MainLoop ();
@@ -579,11 +617,12 @@ public class Indicator.Keyboard.Service : Object {
}
}
- if (panel_service == null && sources[i].is_ibus) {
- if (get_ibus ().request_name (IBus.SERVICE_PANEL, IBus.BusNameFlag.REPLACE_EXISTING) > 0) {
- panel_service = new IBus.PanelService (get_ibus ().get_connection ());
- ((!) panel_service).register_properties.connect (handle_registered_properties);
- ((!) panel_service).update_property.connect (handle_updated_property);
+ if (ibus_connected_id == 0 && sources[i].is_ibus) {
+ ibus_connected_id = get_ibus ().connected.connect (() => { get_ibus_panel (); });
+ get_ibus ().disconnected.connect (() => { ibus_panel = null; });
+
+ if (get_ibus ().is_connected ()) {
+ get_ibus_panel ();
}
}
}
@@ -593,7 +632,7 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
- private void handle_registered_properties (IBus.PropList list) {
+ private void handle_properties_registered (IBus.PropList list) {
if (panel_timeout > 0) {
GLib.Source.remove (panel_timeout);
panel_timeout = 0;
@@ -607,7 +646,7 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
- private void handle_updated_property (IBus.Property property) {
+ private void handle_property_updated (IBus.Property property) {
get_desktop_menu ().update_property (property);
}
@@ -713,8 +752,14 @@ public class Indicator.Keyboard.Service : Object {
desktop_menu = new IndicatorMenu (get_action_group ());
((!) desktop_menu).set_sources (get_sources ());
((!) desktop_menu).activate.connect ((property, state) => {
- if (panel_service != null) {
- ((!) panel_service).property_activate (property.key, state);
+ var panel = get_ibus_panel ();
+
+ if (panel != null) {
+ try {
+ ((!) panel).activate_property (property.key, state);
+ } catch (IOError error) {
+ warning ("error: %s", error.message);
+ }
}
});
}