Directional navigation. Only works for going left yet, see included FIXME
This commit is contained in:
parent
36631b20e4
commit
db7b0cc0a0
|
@ -1077,6 +1077,13 @@ for %s (%s)' % (name, urlplugin.__class__.__name__))
|
||||||
self.vte.set_font(pango.FontDescription(self.config['font']))
|
self.vte.set_font(pango.FontDescription(self.config['font']))
|
||||||
self.custom_font_size = None
|
self.custom_font_size = None
|
||||||
|
|
||||||
|
def get_cursor_position(self):
|
||||||
|
"""Return the co-ordinates of our cursor"""
|
||||||
|
col, row = self.vte.get_cursor_position()
|
||||||
|
width = self.vte.get_char_width()
|
||||||
|
height = self.vte.get_char_height()
|
||||||
|
return((col * width, row * height))
|
||||||
|
|
||||||
# There now begins a great list of keyboard event handlers
|
# There now begins a great list of keyboard event handlers
|
||||||
# FIXME: Probably a bunch of these are wrong. TEST!
|
# FIXME: Probably a bunch of these are wrong. TEST!
|
||||||
def key_zoom_in(self):
|
def key_zoom_in(self):
|
||||||
|
|
|
@ -8,7 +8,8 @@ import gtk
|
||||||
from borg import Borg
|
from borg import Borg
|
||||||
from config import Config
|
from config import Config
|
||||||
from keybindings import Keybindings
|
from keybindings import Keybindings
|
||||||
from util import dbg, get_top_window
|
from util import dbg, err, get_top_window
|
||||||
|
import util
|
||||||
|
|
||||||
class Terminator(Borg):
|
class Terminator(Borg):
|
||||||
"""master object for the application"""
|
"""master object for the application"""
|
||||||
|
@ -122,13 +123,48 @@ class Terminator(Borg):
|
||||||
next = current - 1
|
next = current - 1
|
||||||
if next < 0:
|
if next < 0:
|
||||||
next = length - 1
|
next = length - 1
|
||||||
else:
|
elif direction in ['left', 'right', 'up', 'down']:
|
||||||
|
print direction
|
||||||
window = get_top_window(terminal)
|
window = get_top_window(terminal)
|
||||||
layout = window.get_visible_terminals()
|
layout = window.get_visible_terminals()
|
||||||
# FIXME: Do the directional navigation, don't just print the layout
|
|
||||||
import pprint
|
allocation = terminal.get_allocation()
|
||||||
pprint.pprint(layout)
|
possibles = []
|
||||||
raise NotImplementedError
|
|
||||||
|
# left
|
||||||
|
edge = util.get_edge(allocation, direction)
|
||||||
|
for term in layout:
|
||||||
|
rect = layout[term]
|
||||||
|
if util.get_nav_possible(edge, rect, direction):
|
||||||
|
possibles.append(term)
|
||||||
|
|
||||||
|
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
|
||||||
|
offsets = {}
|
||||||
|
for term in possibles:
|
||||||
|
rect = layout[term]
|
||||||
|
offset = edge - (rect.x + rect.width)
|
||||||
|
offsets[term] = offset
|
||||||
|
keys = offsets.values()
|
||||||
|
keys.sort()
|
||||||
|
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 cursor_y >= rect.y and cursor_y <= (rect.y + rect.height):
|
||||||
|
next = self.terminals.index(term)
|
||||||
|
break;
|
||||||
|
else:
|
||||||
|
err('Unknown navigation direction: %s' % direction)
|
||||||
|
|
||||||
if next is not None:
|
if next is not None:
|
||||||
self.terminals[next].grab_focus()
|
self.terminals[next].grab_focus()
|
||||||
|
|
|
@ -170,3 +170,35 @@ def dict_diff(reference, working):
|
||||||
result[key] = working[key]
|
result[key] = working[key]
|
||||||
|
|
||||||
return(result)
|
return(result)
|
||||||
|
|
||||||
|
# Helper functions for directional navigation
|
||||||
|
def get_edge(allocation, direction):
|
||||||
|
"""Return the edge of the supplied allocation that we will care about for
|
||||||
|
directional navigation"""
|
||||||
|
if direction == 'left':
|
||||||
|
edge = allocation.x
|
||||||
|
elif direction == 'up':
|
||||||
|
edge = allocation.y
|
||||||
|
elif direction == 'right':
|
||||||
|
edge = allocation.x + allocation.width
|
||||||
|
elif direction == 'down':
|
||||||
|
edge = allocation.y + allocation.height
|
||||||
|
else:
|
||||||
|
raise ValueError('unknown direction %s' % direction)
|
||||||
|
|
||||||
|
return(edge)
|
||||||
|
|
||||||
|
def get_nav_possible(edge, allocation, direction):
|
||||||
|
"""Check if the supplied allocation is in the right direction of the
|
||||||
|
supplied edge"""
|
||||||
|
if direction == 'left':
|
||||||
|
return((allocation.x + allocation.width) < edge)
|
||||||
|
elif direction == 'right':
|
||||||
|
return(allocation.x > edge)
|
||||||
|
elif direction == 'up':
|
||||||
|
return((allocation.y + allocation.height) < edge)
|
||||||
|
elif direction == 'down':
|
||||||
|
return(allocation.y > edge)
|
||||||
|
else:
|
||||||
|
raise ValueError('Unknown direction: %s' % direction)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue