take full geometry of the terminals into account

This commit is contained in:
Kees Cook 2008-12-19 15:17:43 -08:00
parent 5c3d3c5c2e
commit 04cecacdbb
2 changed files with 144 additions and 76 deletions

View File

@ -834,102 +834,157 @@ class Terminator:
def _select_direction (self, term, matcher): def _select_direction (self, term, matcher):
current = self.term_list.index (term) current = self.term_list.index (term)
current_x, current_y = term.get_cursor_xy () current_geo = term.get_geometry ()
best_index = None best_index = None
best_x = None best_geo = None
best_y = None
for i in range(0,len(self.term_list)): for i in range(0,len(self.term_list)):
if i == current: if i == current:
continue continue
possible = self.term_list[i] possible = self.term_list[i]
possible_x, possible_y = possible.get_cursor_xy() possible_geo = possible.get_geometry ()
print "I am %d %d:%d, saw %d %d:%d" % (current, current_x, current_y, i, possible_x, possible_y)
if matcher (current_x, current_y, possible_x, possible_y, \ #import pprint
best_x, best_y): #print "I am %d" % (current)
#pprint.pprint(current_geo)
#print "I saw %d" % (i)
#pprint.pprint(possible_geo)
if matcher (current_geo, possible_geo, best_geo):
best_index = i best_index = i
best_x = possible_x best_geo = possible_geo
best_y = possible_y #if best_index is None:
if best_index is None: # print "nothing best"
print "nothing best" #else:
else: # print "sending %d" % (best_index)
print "sending %d" % (best_index)
return best_index return best_index
def _match_up (self, current_x, current_y, possible_x, possible_y, \ def _match_up (self, current_geo, possible_geo, best_geo):
best_x, best_y): '''We want to find terminals that are fully above the top
print "matching up..." border, but closest in the y direction, breaking ties via
if possible_y < current_y: the closest cursor x position.'''
print "possible_y < current_y" #print "matching up..."
if best_x is None or best_y is None: # top edge of the current terminal
print "first thing up" edge = current_geo['origin_y']
# botoom edge of the possible target
new_edge = possible_geo['origin_y']+possible_geo['span_y']
if new_edge < edge:
#print "new_edge < edge"
if best_geo is None:
#print "first thing left"
return True return True
if possible_y < best_y: best_edge = best_geo['origin_y']+best_geo['span_y']
print "closer y" if new_edge > best_edge:
#print "closer y"
return True return True
if possible_y == best_y: if new_edge == best_edge:
print "same y" #print "same y"
if abs(possible_x) < abs(best_x - current_x):
print "closer x" cursor = current_geo['origin_x'] + current_geo['cursor_x']
new_cursor = possible_geo['origin_x'] + possible_geo['cursor_x']
best_cursor = best_geo['origin_x'] + best_geo['cursor_x']
if abs(new_cursor - cursor) < abs(best_cursor - cursor):
#print "closer x"
return True return True
print "fail" #print "fail"
return False return False
def _match_down (self, current_x, current_y, possible_x, possible_y, \ def _match_down (self, current_geo, possible_geo, best_geo):
best_x, best_y): '''We want to find terminals that are fully below the bottom
print "matching down..." border, but closest in the y direction, breaking ties via
if possible_y > current_y: the closest cursor x position.'''
print "possible_y > current_y" #print "matching down..."
if best_x is None or best_y is None: # bottom edge of the current terminal
print "first thing down" edge = current_geo['origin_y']+current_geo['span_y']
# top edge of the possible target
new_edge = possible_geo['origin_y']
#print "edge: %d new_edge: %d" % (edge, new_edge)
if new_edge > edge:
#print "new_edge > edge"
if best_geo is None:
#print "first thing right"
return True return True
if possible_y > best_y: best_edge = best_geo['origin_y']
print "closer y" #print "best_edge: %d" % (best_edge)
if new_edge < best_edge:
#print "closer y"
return True return True
if possible_y == best_y: if new_edge == best_edge:
print "same y" #print "same y"
if abs(possible_x) < abs(best_x - current_x):
print "closer x" cursor = current_geo['origin_x'] + current_geo['cursor_x']
new_cursor = possible_geo['origin_x'] + possible_geo['cursor_x']
best_cursor = best_geo['origin_x'] + best_geo['cursor_x']
if abs(new_cursor - cursor) < abs(best_cursor - cursor):
#print "closer x"
return True return True
print "fail" #print "fail"
return False return False
def _match_left (self, current_x, current_y, possible_x, possible_y, \ def _match_left (self, current_geo, possible_geo, best_geo):
best_x, best_y): '''We want to find terminals that are fully to the left of
print "matching left..." the left-side border, but closest in the x direction, breaking
if possible_x < current_x: ties via the closest cursor y position.'''
print "possible_x < current_x" #print "matching left..."
if best_x is None or best_y is None: # left-side edge of the current terminal
print "first thing left" edge = current_geo['origin_x']
# right-side edge of the possible target
new_edge = possible_geo['origin_x']+possible_geo['span_x']
if new_edge < edge:
#print "new_edge(%d) < edge(%d)" % (new_edge, edge)
if best_geo is None:
#print "first thing left"
return True return True
if possible_x > best_x: best_edge = best_geo['origin_x']+best_geo['span_x']
print "closer x" if new_edge > best_edge:
#print "closer x (new_edge(%d) > best_edge(%d))" % (new_edge, best_edge)
return True return True
if possible_x == best_x: if new_edge == best_edge:
print "same x" #print "same x"
if abs(possible_y) < abs(best_y - current_y):
print "closer y" cursor = current_geo['origin_y'] + current_geo['cursor_y']
new_cursor = possible_geo['origin_y'] + possible_geo['cursor_y']
best_cursor = best_geo['origin_y'] + best_geo['cursor_y']
if abs(new_cursor - cursor) < abs(best_cursor - cursor):
#print "closer y"
return True return True
print "fail" #print "fail"
return False return False
def _match_right (self, current_x, current_y, possible_x, possible_y, \ def _match_right (self, current_geo, possible_geo, best_geo):
best_x, best_y): '''We want to find terminals that are fully to the right of
print "matching right..." the right-side border, but closest in the x direction, breaking
if possible_x > current_x: ties via the closest cursor y position.'''
print "possible_x > current_x" #print "matching right..."
if best_x is None or best_y is None: # right-side edge of the current terminal
print "first thing right" edge = current_geo['origin_x']+current_geo['span_x']
# left-side edge of the possible target
new_edge = possible_geo['origin_x']
#print "edge: %d new_edge: %d" % (edge, new_edge)
if new_edge > edge:
#print "new_edge > edge"
if best_geo is None:
#print "first thing right"
return True return True
if possible_x < best_x: best_edge = best_geo['origin_x']
print "closer x" #print "best_edge: %d" % (best_edge)
if new_edge < best_edge:
#print "closer x"
return True return True
if possible_x == best_x: if new_edge == best_edge:
print "same x" #print "same x"
if abs(possible_y) < abs(best_y - current_y):
print "closer y" cursor = current_geo['origin_y'] + current_geo['cursor_y']
new_cursor = possible_geo['origin_y'] + possible_geo['cursor_y']
best_cursor = best_geo['origin_y'] + best_geo['cursor_y']
if abs(new_cursor - cursor) < abs(best_cursor - cursor):
#print "closer y"
return True return True
print "fail" #print "fail"
return False return False
def _select_up (self, term): def _select_up (self, term):

View File

@ -884,15 +884,28 @@ text/plain
startrow = max(0, endrow - self.conf.scrollback_lines) startrow = max(0, endrow - self.conf.scrollback_lines)
return(startrow, endrow) return(startrow, endrow)
def get_cursor_xy (self): def get_geometry (self):
'''Returns Gdk.Window.get_position(), pixel-based cursor position,
and Gdk.Window.get_geometry()'''
reply = dict()
x, y = self._vte.window.get_origin ()
reply.setdefault('origin_x',x)
reply.setdefault('origin_y',y)
column, row = self._vte.get_cursor_position () column, row = self._vte.get_cursor_position ()
cursor_x = column * self._vte.get_char_width () cursor_x = column * self._vte.get_char_width ()
cursor_y = row * self._vte.get_char_height () cursor_y = row * self._vte.get_char_height ()
x, y = self._vte.window.get_position () reply.setdefault('cursor_x', cursor_x)
#dbg("origin at %d:%d, cursor at %d:%d (%d:%d)" % (x, y, column, row, cursor_x, cursor_y)) reply.setdefault('cursor_y', cursor_y)
x = x + cursor_x
y = y + cursor_y geometry = self._vte.window.get_geometry()
return (x, y) reply.setdefault('offset_x', geometry[0])
reply.setdefault('offset_y', geometry[1])
reply.setdefault('span_x', geometry[2])
reply.setdefault('span_y', geometry[3])
reply.setdefault('depth', geometry[4])
return reply
def create_popup_menu (self, widget, event = None): def create_popup_menu (self, widget, event = None):
menu = gtk.Menu () menu = gtk.Menu ()