Disable IME switcher window when switcher-delay-time is less than 0 1.4.99.20121109
authorfujiwarat <takao.fujiwara1@gmail.com>
Fri, 9 Nov 2012 01:26:23 +0000 (10:26 +0900)
committerfujiwarat <takao.fujiwara1@gmail.com>
Fri, 9 Nov 2012 01:26:23 +0000 (10:26 +0900)
Review URL: https://codereview.appspot.com/6818102

data/ibus.schemas.in
ui/gtk3/panel.vala
ui/gtk3/switcher.vala

index d692e67..a8c7d7f 100644 (file)
       <default>400</default>
       <locale name="C">
         <short>Popup delay milliseconds for IME switcher window</short>
-            <long>Set popup delay milliseconds to show IME switcher window</long>
+            <long>Set popup delay milliseconds to show IME switcher window.
+                  The default is 400.
+                  0 = Show the window immediately.
+                  0 &lt; Delay milliseconds.
+                  0 &gt; Do not show the window and switch prev/next engines.
+            </long>
       </locale>
     </schema>
     <schema>
index 0361131..c159693 100644 (file)
@@ -33,6 +33,7 @@ class Panel : IBus.PanelService {
     private GLib.Pid m_setup_pid = 0;
     private Gtk.AboutDialog m_about_dialog;
     private Gtk.CssProvider m_css_provider;
+    private int m_switcher_delay_time = 400;
     private const string ACCELERATOR_SWITCH_IME_FOREWARD = "<Control>space";
 
     private uint m_switch_keysym = 0;
@@ -61,6 +62,10 @@ class Panel : IBus.PanelService {
         m_switcher = new Switcher();
         bind_switch_shortcut();
 
+        if (m_switcher_delay_time >= 0) {
+            m_switcher.set_popup_delay_time((uint) m_switcher_delay_time);
+        }
+
         m_property_manager = new PropertyManager();
         m_property_manager.property_activate.connect((k, s) => {
             property_activate(k, s);
@@ -188,6 +193,25 @@ class Panel : IBus.PanelService {
                                                  Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
     }
 
+    private void set_switcher_delay_time(Variant? variant) {
+        Variant var_switcher_delay_time = variant;
+
+        if (var_switcher_delay_time == null) {
+            var_switcher_delay_time = m_config.get_value("general",
+                                                         "switcher-delay-time");
+        }
+
+        if (var_switcher_delay_time == null) {
+            return;
+        }
+
+        m_switcher_delay_time = var_switcher_delay_time.get_int32();
+
+        if (m_switcher_delay_time >= 0) {
+            m_switcher.set_popup_delay_time((uint) m_switcher_delay_time);
+        }
+    }
+
     public void set_config(IBus.Config config) {
         if (m_config != null) {
             m_config.value_changed.disconnect(config_value_changed_cb);
@@ -200,13 +224,12 @@ class Panel : IBus.PanelService {
             m_config.value_changed.connect(config_value_changed_cb);
             m_config.watch("general", "preload_engines");
             m_config.watch("general", "engines_order");
+            m_config.watch("general", "switcher_delay_time");
             m_config.watch("panel", "custom_font");
             m_config.watch("panel", "use_custom_font");
             update_engines(m_config.get_value("general", "preload_engines"),
                            m_config.get_value("general", "engines_order"));
-            uint delay_time = (uint) m_config.get_value(
-                    "general", "switcher-delay-time").get_int32();
-            m_switcher.set_popup_delay_time(delay_time);
+            set_switcher_delay_time(null);
         } else {
             update_engines(null, null);
         }
@@ -290,6 +313,10 @@ class Panel : IBus.PanelService {
             set_custom_font();
             return;
         }
+
+        if (section == "general" && name == "switcher_delay_time") {
+            set_switcher_delay_time(variant);
+        }
     }
 
     private void handle_engine_switch(Gdk.Event event, bool revert) {
@@ -302,7 +329,7 @@ class Panel : IBus.PanelService {
 
         bool pressed = KeybindingManager.primary_modifier_still_pressed(
                 event, primary_modifiers);
-        if (pressed) {
+        if (pressed && m_switcher_delay_time >= 0) {
             int i = revert ? m_engines.length - 1 : 1;
             i = m_switcher.run(m_switch_keysym, m_switch_modifiers, event,
                     m_engines, i);
index bec50c6..494fab9 100644 (file)
@@ -73,8 +73,8 @@ class Switcher : Gtk.Window {
     private Gdk.ModifierType m_primary_modifier;
     private GLib.MainLoop m_loop;
     private int m_result;
-    private uint m_popup_delay_time = 400;
-    private uint m_popup_delay_time_id;
+    private uint m_popup_delay_time = 0;
+    private uint m_popup_delay_time_id = 0;
     private int m_root_x;
     private int m_root_y;
 
@@ -157,19 +157,25 @@ class Switcher : Gtk.Window {
             keyboard = device.get_associated_device();
         }
 
-        get_position(out m_root_x, out m_root_y);
-        // Pull the window from the screen so that the window gets
-        // the key press and release events but mouse does not select
-        // an IME unexpectedly.
-        move(-1000, -1000);
+        // Avoid regressions.
+        if (m_popup_delay_time > 0) {
+            get_position(out m_root_x, out m_root_y);
+            // Pull the window from the screen so that the window gets
+            // the key press and release events but mouse does not select
+            // an IME unexpectedly.
+            move(-1000, -1000);
+        }
+
         show_all();
 
-        // Restore the window position after m_popup_delay_time
-        m_popup_delay_time_id = GLib.Timeout.add(m_popup_delay_time,
-                                                 () => {
-            restore_window_position("timeout");
-            return false;
-        });
+        if (m_popup_delay_time > 0) {
+            // Restore the window position after m_popup_delay_time
+            m_popup_delay_time_id = GLib.Timeout.add(m_popup_delay_time,
+                                                     () => {
+                restore_window_position("timeout");
+                return false;
+            });
+        }
 
         Gdk.GrabStatus status;
         // Grab all keyboard events
@@ -322,7 +328,9 @@ class Switcher : Gtk.Window {
         bool retval = true;
         Gdk.EventKey *pe = &e;
 
-        restore_window_position("pressed");
+        if (m_popup_delay_time > 0) {
+            restore_window_position("pressed");
+        }
 
         do {
             uint modifiers = KeybindingManager.MODIFIER_FILTER & pe->state;
@@ -376,9 +384,11 @@ class Switcher : Gtk.Window {
             return false;
         }
 
-        if (m_popup_delay_time_id != 0) {
-            GLib.Source.remove(m_popup_delay_time_id);
-            m_popup_delay_time_id = 0;
+        if (m_popup_delay_time > 0) {
+            if (m_popup_delay_time_id != 0) {
+                GLib.Source.remove(m_popup_delay_time_id);
+                m_popup_delay_time_id = 0;
+            }
         }
 
         m_loop.quit();