Final fix for moving between terminals, checks for overlap. So far never selects wrong terminal.

This commit is contained in:
Stephen Boddy 2015-06-20 20:50:42 +02:00
parent 7cd7c73c53
commit 1d08a1840f
2 changed files with 16 additions and 9 deletions

View File

@ -193,28 +193,34 @@ def get_edge(allocation, direction):
directional navigation""" directional navigation"""
if direction == 'left': if direction == 'left':
edge = allocation.x edge = allocation.x
p1, p2 = allocation.y, allocation.y + allocation.height
elif direction == 'up': elif direction == 'up':
edge = allocation.y edge = allocation.y
p1, p2 = allocation.x, allocation.x + allocation.width
elif direction == 'right': elif direction == 'right':
edge = allocation.x + allocation.width edge = allocation.x + allocation.width
p1, p2 = allocation.y, allocation.y + allocation.height
elif direction == 'down': elif direction == 'down':
edge = allocation.y + allocation.height edge = allocation.y + allocation.height
p1, p2 = allocation.x, allocation.x + allocation.width
else: else:
raise ValueError('unknown direction %s' % direction) raise ValueError('unknown direction %s' % direction)
return(edge) return(edge, p1, p2)
def get_nav_possible(edge, allocation, direction): def get_nav_possible(edge, allocation, direction, p1, p2):
"""Check if the supplied allocation is in the right direction of the """Check if the supplied allocation is in the right direction of the
supplied edge""" supplied edge"""
x1, x2 = allocation.x, allocation.x + allocation.width
y1, y2 = allocation.y, allocation.y + allocation.height
if direction == 'left': if direction == 'left':
return((allocation.x + allocation.width) <= edge) return(x2 <= edge and y1 <= p2 and y2 >= p1)
elif direction == 'right': elif direction == 'right':
return(allocation.x >= edge) return(x1 >= edge and y1 <= p2 and y2 >= p1)
elif direction == 'up': elif direction == 'up':
return((allocation.y + allocation.height) <= edge) return(y2 <= edge and x1 <= p2 and x2 >= p1)
elif direction == 'down': elif direction == 'down':
return(allocation.y >= edge) return(y1 >= edge and x1 <= p2 and x2 >= p1)
else: else:
raise ValueError('Unknown direction: %s' % direction) raise ValueError('Unknown direction: %s' % direction)

View File

@ -811,12 +811,13 @@ class Window(Container, gtk.Window):
possibles = [] possibles = []
# Get the co-ordinate of the appropriate edge for this direction # Get the co-ordinate of the appropriate edge for this direction
edge = util.get_edge(allocation, direction) edge, p1, p2 = util.get_edge(allocation, direction)
# Find all visible terminals which are, in their entirity, in the # Find all visible terminals which are, in their entirity, in the
# direction we want to move # direction we want to move, and are at least partially spanning
# p1 to p2
for term in layout: for term in layout:
rect = layout[term] rect = layout[term]
if util.get_nav_possible(edge, rect, direction): if util.get_nav_possible(edge, rect, direction, p1, p2):
possibles.append(term) possibles.append(term)
if len(possibles) == 0: if len(possibles) == 0: