Skip to content

Commit

Permalink
Move the candidate window just above the cursor when the window and a…
Browse files Browse the repository at this point in the history
… preedit string overlap.

BUG=http://code.google.com/p/ibus/issues/detail?id=1106
TEST=manually done.

Review URL: http://codereview.appspot.com/2599041
  • Loading branch information
yusukes committed Oct 21, 2010
1 parent 1c2b65d commit 8c131cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
29 changes: 17 additions & 12 deletions ui/gtk/candidatepanel.py
Expand Up @@ -219,14 +219,14 @@ def __init__(self):
self.__aux_attrs = pango.AttrList()
self.__lookup_table = None

self.__cursor_location = (0, 0)
self.__cursor_location = (0, 0, 0, 0)
self.__moved_cursor_location = None

self.__recreate_ui()

def __handle_move_end_cb(self, handle):
# store moved location
self.__moved_cursor_location = self.__toplevel.get_position()
self.__moved_cursor_location = self.__toplevel.get_position() + (self.__cursor_location[2], self.__cursor_location[3])

def __recreate_ui(self):
for w in self:
Expand Down Expand Up @@ -428,10 +428,10 @@ def cursor_down_lookup_table(self):
self.__lookup_table.cursor_down()
self.__refresh_candidates()

def set_cursor_location(self, x, y):
def set_cursor_location(self, x, y, w, h):
# if cursor location is changed, we reset the moved cursor location
if self.__cursor_location != (x, y):
self.__cursor_location = (x, y)
if self.__cursor_location != (x, y, w, h):
self.__cursor_location = (x, y, w, h)
self.__moved_cursor_location = None
self.__check_position()

Expand Down Expand Up @@ -484,21 +484,26 @@ def do_size_request(self, requisition):

def __check_position(self):
cursor_location = self.__moved_cursor_location or self.__cursor_location
bx = cursor_location[0] + self.__toplevel.allocation.width
by = cursor_location[1] + self.__toplevel.allocation.height

cursor_right = cursor_location[0] + cursor_location[2]
cursor_bottom = cursor_location[1] + cursor_location[3]

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()

if bx > sx:
if window_right > sx:
x = sx - self.__toplevel.allocation.width
else:
x = cursor_location[0]
x = cursor_right

if by > sy:
y = sy - self.__toplevel.allocation.height
if window_bottom > sy:
# 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:
y = cursor_location[1]
y = cursor_bottom

self.move(x, y)

Expand Down
3 changes: 1 addition & 2 deletions ui/gtk/panel.py
Expand Up @@ -122,7 +122,7 @@ def __init__(self, bus):
# self.__bus.request_name(ibus.panel.IBUS_SERVICE_PANEL, 0)

def set_cursor_location(self, x, y, w, h):
self.__candidate_panel.set_cursor_location(x + w, y + h)
self.__candidate_panel.set_cursor_location(x, y, w, h)

def update_preedit_text(self, text, cursor_pos, visible):
self.__candidate_panel.update_preedit_text(text, cursor_pos, visible)
Expand Down Expand Up @@ -517,4 +517,3 @@ def __start_setup(self):
return
self.__setup_pid = 0
self.__setup_pid = os.spawnl(os.P_NOWAIT, self.__setup_cmd, "ibus-setup")

0 comments on commit 8c131cf

Please sign in to comment.