diff options
author | fujiwarat <takao.fujiwara1@gmail.com> | 2014-02-12 12:48:46 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2014-02-12 12:48:46 +0900 |
commit | 644a749ec444fcccff7dc5c0dff04c567dc0433c (patch) | |
tree | 4c18924f6692c4cdc84eb66735558f5b8cb3a445 | |
parent | c5d86760da26cbce469b3ca4ed48fb6159613251 (diff) |
Do not let property panel follow cursor when it's always shown.
Review URL: https://codereview.appspot.com/60560043
-rw-r--r-- | data/ibus.schemas.in | 13 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | po/POTFILES.skip | 1 | ||||
-rw-r--r-- | ui/gtk3/panel.vala | 17 | ||||
-rw-r--r-- | ui/gtk3/propertypanel.vala | 98 |
5 files changed, 126 insertions, 4 deletions
diff --git a/data/ibus.schemas.in b/data/ibus.schemas.in index d256cbb1..ca4a0e29 100644 --- a/data/ibus.schemas.in +++ b/data/ibus.schemas.in @@ -201,6 +201,19 @@ </schema> --> <schema> + <key>/schemas/desktop/ibus/panel/follow-input-cursor-when-always-shown</key> + <applyto>/desktop/ibus/panel/follow-input-cursor-when-always-shown</applyto> + <owner>ibus</owner> + <type>bool</type> + <default>false</default> + <locale name="C"> + <short>Follow the input cursor in case the panel is always shown</short> + <long>If true, the panel follows the input cursor in case the + panel is always shown. If false, the panel is shown at + a fixed location.</long> + </locale> + </schema> + <schema> <key>/schemas/desktop/ibus/panel/auto-hide-timeout</key> <applyto>/desktop/ibus/panel/auto-hide-timeout</applyto> <owner>ibus</owner> diff --git a/po/POTFILES.in b/po/POTFILES.in index 29b3b760..1c2ab0be 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -60,5 +60,6 @@ ui/gtk3/keybindingmanager.vala ui/gtk3/panel.vala ui/gtk3/pango.vala ui/gtk3/property.vala +ui/gtk3/propertypanel.vala ui/gtk3/separator.vala ui/gtk3/switcher.vala diff --git a/po/POTFILES.skip b/po/POTFILES.skip index 87082315..1d122934 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -17,5 +17,6 @@ ui/gtk3/keybindingmanager.c ui/gtk3/panel.c ui/gtk3/pango.c ui/gtk3/property.c +ui/gtk3/propertypanel.c ui/gtk3/separator.c ui/gtk3/switcher.c diff --git a/ui/gtk3/panel.vala b/ui/gtk3/panel.vala index a7a0c409..aecaae8d 100644 --- a/ui/gtk3/panel.vala +++ b/ui/gtk3/panel.vala @@ -2,7 +2,7 @@ * * ibus - The Input Bus * - * Copyright(c) 2011-2013 Peng Huang <shawn.p.huang@gmail.com> + * Copyright(c) 2011-2014 Peng Huang <shawn.p.huang@gmail.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -166,6 +166,11 @@ class Panel : IBus.PanelService { m_settings_panel.changed["timeout"].connect((key) => { set_timeout_property_panel(); }); + + m_settings_panel.changed["follow-input-cursor-when-always-shown"] + .connect((key) => { + set_follow_input_cursor_when_always_shown_property_panel(); + }); } private void keybinding_manager_bind(KeybindingManager keybinding_manager, @@ -361,6 +366,15 @@ class Panel : IBus.PanelService { (uint) m_settings_panel.get_int("auto-hide-timeout")); } + private void set_follow_input_cursor_when_always_shown_property_panel() { + if (m_property_panel == null) + return; + + m_property_panel.set_follow_input_cursor_when_always_shown( + m_settings_panel.get_boolean( + "follow-input-cursor-when-always-shown")); + } + private int compare_versions(string version1, string version2) { string[] version1_list = version1.split("."); string[] version2_list = version2.split("."); @@ -459,6 +473,7 @@ class Panel : IBus.PanelService { set_lookup_table_orientation(); set_show_property_panel(); set_timeout_property_panel(); + set_follow_input_cursor_when_always_shown_property_panel(); set_version(); } diff --git a/ui/gtk3/propertypanel.vala b/ui/gtk3/propertypanel.vala index 9ea6bad6..e6a192f9 100644 --- a/ui/gtk3/propertypanel.vala +++ b/ui/gtk3/propertypanel.vala @@ -37,6 +37,7 @@ public class PropertyPanel : Gtk.Box { private int m_show = PanelShow.AUTO_HIDE; private uint m_auto_hide_timeout = 10000; private uint m_auto_hide_timeout_id = 0; + private bool m_follow_input_cursor_when_always_shown = false; public PropertyPanel() { /* Chain up base class constructor */ @@ -53,6 +54,16 @@ public class PropertyPanel : Gtk.Box { pack_start(handle, false, false, 0); m_toplevel.add(this); + + m_toplevel.size_allocate.connect((w, a) => { + if (!m_follow_input_cursor_when_always_shown && + m_show == PanelShow.ALWAYS && m_items.length > 0 && + m_cursor_location.x == -1 && m_cursor_location.y == -1) { + set_default_location(); + m_cursor_location.x = 0; + m_cursor_location.y = 0; + } + }); } public void set_properties(IBus.PropList props) { @@ -98,6 +109,10 @@ public class PropertyPanel : Gtk.Box { } public void set_cursor_location(int x, int y, int width, int height) { + if (!m_follow_input_cursor_when_always_shown && + m_show == PanelShow.ALWAYS) + return; + /* FIXME: set_cursor_location() has a different behavior * in embedded preedit by applications. * GtkTextView applications, e.g. gedit, always call @@ -173,7 +188,9 @@ public class PropertyPanel : Gtk.Box { } public new void show() { - if (m_show == PanelShow.DO_NOT_SHOW || m_items.length == 0) { + /* m_items.length is not checked here because set_properties() + * is not called yet when set_show() is called. */ + if (m_show == PanelShow.DO_NOT_SHOW) { m_toplevel.hide(); return; } @@ -200,7 +217,9 @@ public class PropertyPanel : Gtk.Box { * focus is changed. * E.g. Two tabs on gnome-terminal can keep the cursor position. */ - m_cursor_location = { -1, -1, 0, 0 }; + if (m_follow_input_cursor_when_always_shown || + m_show != PanelShow.ALWAYS) + m_cursor_location = { -1, -1, 0, 0 }; /* set_cursor_location() will be called later. */ } @@ -214,6 +233,10 @@ public class PropertyPanel : Gtk.Box { m_auto_hide_timeout = timeout; } + public void set_follow_input_cursor_when_always_shown(bool is_follow) { + m_follow_input_cursor_when_always_shown = is_follow; + } + public override void get_preferred_width(out int minimum_width, out int natural_width) { base.get_preferred_width(out minimum_width, out natural_width); @@ -297,9 +320,78 @@ public class PropertyPanel : Gtk.Box { move(x, y); } + private void set_default_location() { + Gtk.Allocation allocation; + m_toplevel.get_allocation(out allocation); + + unowned Gdk.Window root = Gdk.get_default_root_window(); + int root_width = root.get_width(); + int root_x = 0; + int root_y = 0; + int ws_num = 0; + + unowned Gdk.Display display = root.get_display(); + unowned X.Display xdisplay = Gdk.X11Display.get_xdisplay(display); + X.Window xwindow = Gdk.X11Window.get_xid(root); + + X.Atom _net_current_desktop = + xdisplay.intern_atom("_NET_CURRENT_DESKTOP", false); + X.Atom type = X.None; + int format; + ulong nitems = 0; + ulong bytes_after; + void *prop; + xdisplay.get_window_property(xwindow, + _net_current_desktop, + 0, 32, false, X.XA_CARDINAL, + out type, out format, + out nitems, out bytes_after, + out prop); + + if (type != X.None && nitems >= 1) + ws_num = (int) ((ulong *)prop)[0]; + + X.Atom _net_workarea = + xdisplay.intern_atom("_NET_WORKAREA", false); + type = X.None; + nitems = 0; + + xdisplay.get_window_property(xwindow, + _net_workarea, + 0, 32, false, X.XA_CARDINAL, + out type, out format, + out nitems, out bytes_after, + out prop); + + if (type != X.None && nitems >= 2) { + root_x = (int) ((ulong *)prop)[ws_num * 4]; + root_y = (int) ((ulong *)prop)[ws_num * 4 + 1]; + } + + int x, y; + /* Translators: If your locale is RTL, the msgstr is "default:RTL". + * Otherwise the msgstr is "default:LTR". */ + if (_("default:LTR") != "default:RTL") { + x = root_width - allocation.width; + y = root_y; + } else { + x = root_x; + y = root_y; + } + + move(x, y); + } + private void show_with_auto_hide_timer() { - if (m_show != PanelShow.AUTO_HIDE || m_items.length == 0) + if (m_items.length == 0) { + m_toplevel.hide(); + return; + } + + if (m_show != PanelShow.AUTO_HIDE) { + show(); return; + } if (m_auto_hide_timeout_id != 0) GLib.Source.remove(m_auto_hide_timeout_id); |