From 8800a05d7dbdfb8ba5c6ce40fba69cad7a885920 Mon Sep 17 00:00:00 2001 From: William Hua Date: Fri, 13 Jun 2014 14:13:25 -0400 Subject: Pick IBus or Fcitx. --- lib/indicator-menu.vala | 7 +++++-- lib/main.vala | 45 ++++++++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/indicator-menu.vala b/lib/indicator-menu.vala index 8e5661e2..115adc5f 100644 --- a/lib/indicator-menu.vala +++ b/lib/indicator-menu.vala @@ -22,7 +22,8 @@ public class Indicator.Keyboard.IndicatorMenu : MenuModel { NONE = 0x0, DCONF = 0x1, IBUS = 0x2, - SETTINGS = 0x4 + FCITX = 0x4, + SETTINGS = 0x8 } private Options options; @@ -76,7 +77,9 @@ public class Indicator.Keyboard.IndicatorMenu : MenuModel { sources_section.remove_all (); for (var i = 0; i < sources.length; i++) { - if (!sources[i].is_ibus || (options & Options.IBUS) != Options.NONE) { + if (sources[i].is_xkb || + (sources[i].is_ibus && (options & Options.IBUS) != Options.NONE) || + (sources[i].is_fcitx && (options & Options.FCITX) != Options.NONE)) { string action; if ((options & Options.DCONF) != Options.NONE) { diff --git a/lib/main.vala b/lib/main.vala index 8d39d757..9f007170 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -145,6 +145,18 @@ public class Indicator.Keyboard.Service : Object { return Environment.get_user_name () == "lightdm"; } + [DBus (visible = false)] + private static bool is_ibus_active () { + var module = Environment.get_variable ("GTK_IM_MODULE"); + return module != null && (!) module == "ibus"; + } + + [DBus (visible = false)] + private static bool is_fcitx_active () { + var module = Environment.get_variable ("GTK_IM_MODULE"); + return module != null && (!) module == "fcitx"; + } + [DBus (visible = false)] private IBus.Bus get_ibus () { if (ibus == null) { @@ -788,30 +800,30 @@ public class Indicator.Keyboard.Service : Object { private void handle_scroll_wheel_when_locked (Variant? parameter) { if (parameter != null) { var sources = get_sources (); - var non_ibus_length = 0; + var xkb_length = 0; - /* Figure out how many non-IBus sources we have. */ + /* Figure out how many Xkb sources we have. */ foreach (var source in sources) { - if (!source.is_ibus) { - non_ibus_length++; + if (source.is_xkb) { + xkb_length++; } } - if (non_ibus_length > 1) { + if (xkb_length > 1) { var active_action = get_active_action (); var active = active_action.state.get_uint32 (); - var offset = -((!) parameter).get_int32 () % non_ibus_length; + var offset = -((!) parameter).get_int32 () % xkb_length; - /* Make offset positive modulo non_ibus_length. */ + /* Make offset positive modulo xkb_length. */ if (offset < 0) { - offset += non_ibus_length; + offset += xkb_length; } - /* We need to cycle through non-IBus sources only. */ + /* We need to cycle through Xkb sources only. */ while (offset > 0) { do { active = (active + 1) % sources.length; - } while (sources[active].is_ibus); + } while (!sources[active].is_xkb); offset--; } @@ -882,9 +894,16 @@ public class Indicator.Keyboard.Service : Object { public IndicatorMenu get_desktop_menu () { if (desktop_menu == null) { var options = IndicatorMenu.Options.DCONF - | IndicatorMenu.Options.IBUS | IndicatorMenu.Options.SETTINGS; + if (is_ibus_active ()) { + options |= IndicatorMenu.Options.IBUS; + } + + if (is_fcitx_active ()) { + options |= IndicatorMenu.Options.FCITX; + } + desktop_menu = new IndicatorMenu (get_action_group (), options); ((!) desktop_menu).set_sources (get_sources ()); ((!) desktop_menu).activate.connect ((property, state) => { @@ -1040,9 +1059,9 @@ public class Indicator.Keyboard.Service : Object { if (sources.length > 0) { var current = source_settings.get_uint ("current"); - if (current < sources.length && sources[current].is_ibus) { + if (current < sources.length && !sources[current].is_xkb) { for (var i = 0; i < sources.length; i++) { - if (!sources[i].is_ibus) { + if (sources[i].is_xkb) { get_active_action ().change_state (new Variant.uint32 (i)); break; } -- cgit v1.2.3