aboutsummaryrefslogtreecommitdiff
path: root/lib/main.vala
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2014-04-02 10:24:25 +1300
committerWilliam Hua <william.hua@canonical.com>2014-04-02 10:24:25 +1300
commit414d5d9f8a41805ecec5808ace466c37d03fa9f3 (patch)
tree8dc12f064501b1a8ad44a8e99515c19878102399 /lib/main.vala
parent8c6fd2e9daff0d486ab71c50413dadff6d1c12d8 (diff)
downloadayatana-indicator-keyboard-414d5d9f8a41805ecec5808ace466c37d03fa9f3.tar.gz
ayatana-indicator-keyboard-414d5d9f8a41805ecec5808ace466c37d03fa9f3.tar.bz2
ayatana-indicator-keyboard-414d5d9f8a41805ecec5808ace466c37d03fa9f3.zip
Switch to non-IBus input source when screen is locked.
Diffstat (limited to 'lib/main.vala')
-rw-r--r--lib/main.vala54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/main.vala b/lib/main.vala
index 55c46b02..7cfb5fac 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -49,6 +49,9 @@ public class Indicator.Keyboard.Service : Object {
private Menu? sources_menu;
private IBusMenu? ibus_menu;
+ private UnitySession? unity_session;
+ private uint session_current;
+
private UnityGreeter? unity_greeter;
private string? greeter_user;
private uint lightdm_current;
@@ -96,6 +99,12 @@ public class Indicator.Keyboard.Service : Object {
}
} else {
Bus.watch_name (BusType.SESSION,
+ "com.canonical.Unity",
+ BusNameWatcherFlags.NONE,
+ handle_unity_name_appeared,
+ handle_unity_name_vanished);
+
+ Bus.watch_name (BusType.SESSION,
"com.canonical.Unity.WindowStack",
BusNameWatcherFlags.NONE,
handle_window_stack_name_appeared,
@@ -924,6 +933,51 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
+ private void handle_unity_name_appeared (DBusConnection connection, string name, string name_owner) {
+ try {
+ unity_session = Bus.get_proxy_sync (BusType.SESSION, name, "/com/canonical/Unity/Session");
+ ((!) unity_session).locked.connect (() => {
+ session_current = source_settings.get_uint ("current");
+
+ var sources = get_sources ();
+
+ if (session_current < 0) {
+ session_current = 0;
+ } else if (session_current >= sources.length) {
+ session_current = sources.length - 1;
+ }
+
+ if (0 <= session_current && session_current < sources.length) {
+ var source = sources[session_current];
+
+ if (source.is_ibus) {
+ for (var i = 0; i < sources.length; i++) {
+ if (!sources[i].is_ibus) {
+ source_settings.set_uint ("current", i);
+ break;
+ }
+ }
+ }
+ }
+ });
+ ((!) unity_session).unlocked.connect (() => {
+ var locked_current = source_settings.get_uint ("current");
+
+ if (locked_current != session_current) {
+ source_settings.set_uint ("current", session_current);
+ }
+ });
+ } catch (IOError error) {
+ warning ("error: %s", error.message);
+ }
+ }
+
+ [DBus (visible = false)]
+ private void handle_unity_name_vanished (DBusConnection connection, string name) {
+ unity_session = null;
+ }
+
+ [DBus (visible = false)]
private void handle_window_stack_name_appeared (DBusConnection connection, string name, string name_owner) {
try {
window_stack = Bus.get_proxy_sync (BusType.SESSION, name, "/com/canonical/Unity/WindowStack");