aboutsummaryrefslogtreecommitdiff
path: root/lib/main.vala
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2014-03-20 12:25:34 +1300
committerWilliam Hua <william.hua@canonical.com>2014-03-20 12:25:34 +1300
commita08ab0c4f8f80366eb7c08795e9d5407aef8ecff (patch)
treee9fcc6ec33592e9408bdd8a1b62090251bf81489 /lib/main.vala
parentbe945fee7825c4852f558d6e2e77a196c184f9c5 (diff)
downloadayatana-indicator-keyboard-a08ab0c4f8f80366eb7c08795e9d5407aef8ecff.tar.gz
ayatana-indicator-keyboard-a08ab0c4f8f80366eb7c08795e9d5407aef8ecff.tar.bz2
ayatana-indicator-keyboard-a08ab0c4f8f80366eb7c08795e9d5407aef8ecff.zip
IBus panel is only available while IBus is running.
Diffstat (limited to 'lib/main.vala')
-rw-r--r--lib/main.vala82
1 files changed, 48 insertions, 34 deletions
diff --git a/lib/main.vala b/lib/main.vala
index 9e74ee84..55c46b02 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -38,6 +38,7 @@ public class Indicator.Keyboard.Service : Object {
private IBus.Bus? ibus;
private IBusPanel? ibus_panel;
+ private ulong ibus_connected_id;
private uint panel_timeout;
private Source[]? sources;
@@ -132,6 +133,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 ();
@@ -576,38 +614,12 @@ public class Indicator.Keyboard.Service : Object {
}
}
- if (ibus_panel == null && sources[i].is_ibus) {
- DBusConnection? connection = get_ibus ().get_connection ();
-
- if (connection != null) {
- 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);
- }
+ 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 ();
}
}
}
@@ -774,9 +786,11 @@ public class Indicator.Keyboard.Service : Object {
if (ibus_menu == null) {
ibus_menu = new IBusMenu (get_action_group ());
((!) ibus_menu).activate.connect ((property, state) => {
- if (ibus_panel != null) {
+ var panel = get_ibus_panel ();
+
+ if (panel != null) {
try {
- ((!) ibus_panel).activate_property (property.key, state);
+ ((!) panel).activate_property (property.key, state);
} catch (IOError error) {
warning ("error: %s", error.message);
}