diff options
author | Alexey Kotlyarov <a@koterpillar.com> | 2015-11-04 11:18:50 +0900 |
---|---|---|
committer | fujiwarat <takao.fujiwara1@gmail.com> | 2015-11-04 11:18:50 +0900 |
commit | 4a8024b0a3e5670dc5ad88a26b90b0a9801efcca (patch) | |
tree | e1175e30378f619340d66f04fcb6544cf91fcd6b | |
parent | 1d678673e18e132ed53df32502b779b0a56314d5 (diff) | |
download | ibus-4a8024b0a3e5670dc5ad88a26b90b0a9801efcca.tar.gz |
panel: Constrain the candidate area to the current monitor bounds
If the second monitor has the different size, lookup window on
the second monitor could not get the right size.
BUG=https://github.com/ibus/ibus/issues/1594
Review URL: https://codereview.appspot.com/267710043
Patch from Alexey Kotlyarov <a@koterpillar.com>.
-rw-r--r-- | ui/gtk2/candidatepanel.py | 15 | ||||
-rw-r--r-- | ui/gtk3/candidatepanel.vala | 46 |
2 files changed, 40 insertions, 21 deletions
diff --git a/ui/gtk2/candidatepanel.py b/ui/gtk2/candidatepanel.py index 374f9649..a105faa9 100644 --- a/ui/gtk2/candidatepanel.py +++ b/ui/gtk2/candidatepanel.py @@ -487,15 +487,20 @@ class CandidatePanel(gtk.VBox): window_right = cursor_right + self.__toplevel.allocation.width window_bottom = cursor_bottom + self.__toplevel.allocation.height - root_window = gdk.get_default_root_window() - sx, sy = root_window.get_size() + screen = gdk.screen_get_default() + monitor_num = screen.get_monitor_at_point(cursor_location[0], + cursor_location[1]) + monitor_area = screen.get_monitor_geometry(monitor_num) - if window_right > sx: - x = sx - self.__toplevel.allocation.width + monitor_right = monitor_area.x + monitor_area.width + monitor_bottom = monitor_area.y + monitor_area.height + + if window_right > monitor_right: + x = monitor_right - self.__toplevel.allocation.width else: x = cursor_right - if window_bottom > sy: + if window_bottom > monitor_bottom: # move the window just above the cursor so the window and a preedit string do not overlap. y = cursor_location[1] - self.__toplevel.allocation.height else: diff --git a/ui/gtk3/candidatepanel.vala b/ui/gtk3/candidatepanel.vala index 823c54af..06ed0c9d 100644 --- a/ui/gtk3/candidatepanel.vala +++ b/ui/gtk3/candidatepanel.vala @@ -306,19 +306,26 @@ public class CandidatePanel : Gtk.Box{ cursor_right_bottom.y + allocation.height }; - Gdk.Window root = Gdk.get_default_root_window(); - int root_width = root.get_width(); - int root_height = root.get_height(); + Gdk.Screen screen = Gdk.Screen.get_default(); + int monitor_num = screen.get_monitor_at_point(m_cursor_location.x, + m_cursor_location.y); + // Use get_monitor_geometry() instead of get_monitor_area(). + // get_monitor_area() excludes docks, but the lookup window should be + // shown over them. + Gdk.Rectangle monitor_area; + screen.get_monitor_geometry(monitor_num, out monitor_area); + int monitor_right = monitor_area.x + monitor_area.width; + int monitor_bottom = monitor_area.y + monitor_area.height; int x, y; - if (window_right_bottom.x > root_width) - x = root_width - allocation.width; + if (window_right_bottom.x > monitor_right) + x = monitor_right - allocation.width; else x = cursor_right_bottom.x; if (x < 0) x = 0; - if (window_right_bottom.y > root_height) + if (window_right_bottom.y > monitor_bottom) y = m_cursor_location.y - allocation.height; else y = cursor_right_bottom.y; @@ -352,31 +359,38 @@ public class CandidatePanel : Gtk.Box{ m_cursor_location.y + allocation.height }; - Gdk.Window root = Gdk.get_default_root_window(); - int root_width = root.get_width(); - int root_height = root.get_height(); + Gdk.Screen screen = Gdk.Screen.get_default(); + int monitor_num = screen.get_monitor_at_point(m_cursor_location.x, + m_cursor_location.y); + // Use get_monitor_geometry() instead of get_monitor_area(). + // get_monitor_area() excludes docks, but the lookup window should be + // shown over them. + Gdk.Rectangle monitor_area; + screen.get_monitor_geometry(monitor_num, out monitor_area); + int monitor_right = monitor_area.x + monitor_area.width; + int monitor_bottom = monitor_area.y + monitor_area.height; int x, y; if (!m_candidate_area.get_vertical()) { - if (hwindow_right_bottom.x > root_width) - x = root_width - allocation.width; + if (hwindow_right_bottom.x > monitor_right) + x = monitor_right - allocation.width; else x = m_cursor_location.x; - if (hwindow_right_bottom.y > root_height) + if (hwindow_right_bottom.y > monitor_bottom) y = m_cursor_location.y - allocation.height; else y = cursor_right_bottom.y; } else { - if (vwindow_left_bottom.x > root_width) - x = root_width - allocation.width; + if (vwindow_left_bottom.x > monitor_right) + x = monitor_right - allocation.width; else if (vwindow_left_bottom.x < 0) x = cursor_right_bottom.x; else x = vwindow_left_bottom.x; - if (vwindow_left_bottom.y > root_height) - y = root_height - allocation.height; + if (vwindow_left_bottom.y > monitor_bottom) + y = monitor_bottom - allocation.height; else y = m_cursor_location.y; } |