From 021f5cef98dc65d79adfbd611faf3d8dcb42fd17 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 20 Jan 2010 19:57:16 +0000 Subject: [PATCH] remove the silly old comments in the directional navigation section and add some better ones describing how it works --- terminatorlib/terminator.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index 790ae03d..da8bb7f8 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -130,8 +130,10 @@ class Terminator(Borg): allocation = terminal.get_allocation() possibles = [] - # left + # Get the co-ordinate of the appropriate edge for this direction edge = util.get_edge(allocation, direction) + # Find all visible terminals which are, in their entirity, in the + # direction we want to move for term in layout: rect = layout[term] if util.get_nav_possible(edge, rect, direction): @@ -140,9 +142,9 @@ class Terminator(Borg): if len(possibles) == 0: return - # FIXME: Check if the selection of winners and the tie-break need - # helper functions to make them direction agnostic. Likely the - # offset calculation will + # Find out how far away each of the possible terminals is, then + # find the smallest distance. The winning terminals are all of + # those who are that distance away. offsets = {} for term in possibles: rect = layout[term] @@ -152,15 +154,16 @@ class Terminator(Borg): winners = [k for k, v in offsets.iteritems() if v == keys[0]] next = self.terminals.index(winners[0]) - # Break an n-way tie - cursor_x, cursor_y = terminal.get_cursor_position() - cursor_x = cursor_x + allocation.x - cursor_y = cursor_y + allocation.y - for term in winners: - rect = layout[term] - if util.get_nav_tiebreak(direction, cursor_x, cursor_y, rect): - next = self.terminals.index(term) - break; + if len(winners) > 1: + # Break an n-way tie with the cursor position + cursor_x, cursor_y = terminal.get_cursor_position() + cursor_x = cursor_x + allocation.x + cursor_y = cursor_y + allocation.y + for term in winners: + rect = layout[term] + if util.get_nav_tiebreak(direction, cursor_x, cursor_y, rect): + next = self.terminals.index(term) + break; else: err('Unknown navigation direction: %s' % direction)