Skip to content

Commit

Permalink
Add some milliseconds interval before IME switcher is shown.
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiwarat committed Nov 5, 2012
1 parent 1e6c42f commit 4b044a0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
11 changes: 11 additions & 0 deletions data/ibus.schemas.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
<long>Saved engines order in input method list</long>
</locale>
</schema>
<schema>
<key>/schemas/desktop/ibus/general/switcher-delay-time</key>
<applyto>/desktop/ibus/general/switcher-delay-time</applyto>
<owner>ibus</owner>
<type>int</type>
<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>
</locale>
</schema>
<schema>
<key>/schemas/desktop/ibus/general/hotkey/trigger</key>
<applyto>/desktop/ibus/general/hotkey/trigger</applyto>
Expand Down
3 changes: 3 additions & 0 deletions ui/gtk3/panel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class Panel : IBus.PanelService {
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);
} else {
update_engines(null, null);
}
Expand Down
50 changes: 39 additions & 11 deletions ui/gtk3/switcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ 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 int m_root_x;
private int m_root_y;

public Switcher() {
GLib.Object(
Expand Down Expand Up @@ -153,19 +157,19 @@ 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);
show_all();

if (is_composited()) {
// Hide the window by set the opactiy to 0.0, because real hiden
// window can not grab keyboard and pointer.
get_window().set_opacity(0.0);

// Show window after 1/10 secound
GLib.Timeout.add(100, ()=> {
get_window().set_opacity(1.0);
return false;
});
}
// 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
Expand Down Expand Up @@ -295,6 +299,19 @@ class Switcher : Gtk.Window {
set_focus(m_buttons[m_selected_engine]);
}

private void restore_window_position(string debug_str) {
debug("restore_window_position %s: (%ld, %ld)\n",
debug_str, m_root_x, m_root_y);

if (m_popup_delay_time_id == 0) {
return;
}

GLib.Source.remove(m_popup_delay_time_id);
m_popup_delay_time_id = 0;
move(m_root_x, m_root_y);
}

/* override virtual functions */
public override void show() {
base.show();
Expand All @@ -305,6 +322,8 @@ class Switcher : Gtk.Window {
bool retval = true;
Gdk.EventKey *pe = &e;

restore_window_position("pressed");

do {
uint modifiers = KeybindingManager.MODIFIER_FILTER & pe->state;

Expand Down Expand Up @@ -357,8 +376,17 @@ 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;
}

m_loop.quit();
m_result = (int)m_selected_engine;
return true;
}

public void set_popup_delay_time(uint popup_delay_time) {
m_popup_delay_time = popup_delay_time;
}
}

0 comments on commit 4b044a0

Please sign in to comment.