From b0d43570029fca1176f76d0be90652c3af5c103d Mon Sep 17 00:00:00 2001 From: Stephen Boddy Date: Sat, 20 Jun 2015 21:02:41 +0200 Subject: [PATCH] (trunk-1554/1561) Final fix for moving between terminals, checks for overlap. So far never selects wrong terminal. --- terminatorlib/util.py | 24 +++++++++++++++--------- terminatorlib/window.py | 7 ++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/terminatorlib/util.py b/terminatorlib/util.py index 4122fe17..254f78c4 100755 --- a/terminatorlib/util.py +++ b/terminatorlib/util.py @@ -190,28 +190,34 @@ def get_edge(allocation, direction): directional navigation""" if direction == 'left': edge = allocation.x + p1, p2 = allocation.y, allocation.y + allocation.height elif direction == 'up': edge = allocation.y + p1, p2 = allocation.x, allocation.x + allocation.width elif direction == 'right': edge = allocation.x + allocation.width + p1, p2 = allocation.y, allocation.y + allocation.height elif direction == 'down': edge = allocation.y + allocation.height + p1, p2 = allocation.x, allocation.x + allocation.width else: 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 supplied edge""" + x1, x2 = allocation.x, allocation.x + allocation.width + y1, y2 = allocation.y, allocation.y + allocation.height if direction == 'left': - return((allocation.x + allocation.width) <= edge) + return(x2 <= edge and y1 <= p2 and y2 >= p1) elif direction == 'right': - return(allocation.x >= edge) + return(x1 >= edge and y1 <= p2 and y2 >= p1) elif direction == 'up': - return((allocation.y + allocation.height) <= edge) + return(y2 <= edge and x1 <= p2 and x2 >= p1) elif direction == 'down': - return(allocation.y >= edge) + return(y1 >= edge and x1 <= p2 and x2 >= p1) else: raise ValueError('Unknown direction: %s' % direction) @@ -221,11 +227,11 @@ def get_nav_offset(edge, allocation, direction): if direction == 'left': return(edge - (allocation.x + allocation.width)) elif direction == 'right': - return(edge + allocation.x) + return(allocation.x - edge) elif direction == 'up': - return(edge - (allocation.y - allocation.height)) + return(edge - (allocation.y + allocation.height)) elif direction == 'down': - return(edge + allocation.y) + return(allocation.y - edge) else: raise ValueError('Unknown direction: %s' % direction) diff --git a/terminatorlib/window.py b/terminatorlib/window.py index 9c35a0c5..fc153d62 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -811,12 +811,13 @@ class Window(Container, Gtk.Window): possibles = [] # 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 - # direction we want to move + # direction we want to move, and are at least partially spanning + # p1 to p2 for term in layout: rect = layout[term] - if util.get_nav_possible(edge, rect, direction): + if util.get_nav_possible(edge, rect, direction, p1, p2): possibles.append(term) if len(possibles) == 0: