Hook up new keybinding code. Making them configurable shouldn't be far away...

This commit is contained in:
Thomas Hurst 2008-08-11 19:02:14 +01:00
parent d1787e576d
commit e65e396d32
3 changed files with 95 additions and 103 deletions

View File

@ -30,9 +30,10 @@ class TerminatorKeybindings:
'resize_down': '<Ctrl><Shift>Down',
'resize_left': '<Ctrl><Shift>Left',
'resize_right': '<Ctrl><Shift>Right',
'move_tab_right': '<Ctrl><Shift>Page_Up',
'move_tab_left': '<Ctrl><Shift>Page_Down',
'move_tab_right': '<Ctrl><Shift>Page_Down',
'move_tab_left': '<Ctrl><Shift>Page_Up',
'toggle_zoom': '<Ctrl><Shift>X',
'scaled_zoom': '<Ctrl><Shift>Z',
'next_tab': '<Ctrl>Page_Down',
'prev_tab': '<Ctrl>Page_Up',
'go_prev': '<Ctrl><Shift>Tab',
@ -49,9 +50,9 @@ class TerminatorKeybindings:
empty = {}
def __init__(self):
self._parse()
self.reload()
def _parse(self):
def reload(self):
self._lookup = {}
self._masks = 0
for action, binding in self.keys.items():
@ -65,7 +66,9 @@ class TerminatorKeybindings:
raise e
else:
self._lookup.setdefault(mask, {})
self._lookup[mask][key] = action
self._lookup[mask][keyval] = action
if key == 'Tab':
self._lookup[mask][gtk.gdk.keyval_from_name('ISO_Left_Tab')] = action
self._masks |= mask
def _parsebinding(self, binding):
@ -88,5 +91,5 @@ class TerminatorKeybindings:
def lookup(self, event):
mask = event.state & self._masks
keyval = gtk.gdk.keyval_name(event.keyval)
return self._lookup.get(mask, self.empty).get(keyval, None)
return self._lookup.get(mask, self.empty).get(event.keyval, None)

View File

@ -26,6 +26,7 @@ from terminatorlib.version import *
# import our configuration loader
from terminatorlib import config
from terminatorlib.config import dbg, err, debug
from terminatorlib.keybindings import TerminatorKeybindings
#import TerminatorTerm
from terminatorlib.terminatorterm import TerminatorTerm
@ -121,8 +122,10 @@ class Terminator:
self.icon_theme = gtk.IconTheme ()
self.keybindings = TerminatorKeybindings()
if self.conf.f11_modifier:
self._f11_modifier = True
self.keybindings.keys['full_screen'] = '<Ctrl><Shift>F11'
self.keybindings.reload()
if self.conf.handle_size in xrange (0,6):
gtk.rc_parse_string("""
@ -254,15 +257,14 @@ class Terminator:
* F11: toggle fullscreen state of the window.
* CTRL - SHIFT - Q: close all terminals
"""
keyname = gtk.gdk.keyval_name (event.keyval)
mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK
mapping = self.keybindings.lookup(event)
if (keyname == 'F11' and (self._f11_modifier == False or event.state & mask)):
if mapping:
dbg("on_key_press: lookup found %s" % repr(mapping))
if mapping == 'full_screen':
self.fullscreen_toggle ()
return (True)
if (event.state & mask) == mask:
if keyname == 'Q':
elif mapping == 'close_window':
if not self.on_delete_event (window, gtk.gdk.Event (gtk.gdk.DELETE)):
self.on_destroy_event (window, gtk.gdk.Event (gtk.gdk.DESTROY))

View File

@ -668,98 +668,85 @@ text/plain
#keybindings for the individual splited terminals (affects only the
#the selected terminal)
UnhandledKeybindings = ('close_window', 'full_screen')
def on_vte_key_press (self, term, event):
keyname = gtk.gdk.keyval_name (event.keyval)
mapping = self.terminator.keybindings.lookup(event)
mask = gtk.gdk.CONTROL_MASK
if (event.state & mask) == mask:
if keyname == 'plus':
self.zoom (True)
return (True)
elif keyname == 'minus':
self.zoom (False)
return (True)
elif keyname == 'equal':
self.zoom_orig ()
return (True)
if mapping and mapping not in self.UnhandledKeybindings:
dbg("on_vte_key_press: lookup found %s" % repr(mapping))
getattr(self, "key_" + mapping)()
return True
return False
# Key events
def key_zoom_in(self): self.zoom (True)
def key_zoom_out(self): self.zoom (False)
def key_copy(self): self._vte.copy_clipboard ()
def key_paste(self): self.paste_clipboard ()
def key_toggle_scrollbar(self): self.do_scrollbar_toggle ()
def key_zoom_normal(self): self.zoom_orig ()
mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK | gtk.gdk.MOD1_MASK
if (event.state & mask) == mask:
#Top level tab
if keyname == 'T':
self.terminator.newtab (self, True)
return (True)
# bindings that should be moved to Terminator as they all just call
# a function of Terminator. It would be cleaner is TerminatorTerm
# a function of Terminator. It would be cleaner if TerminatorTerm
# has absolutely no reference to Terminator.
# N (next) - P (previous) - O (horizontal) - E (vertical) - W (close)
def key_new_root_tab(self):
self.terminator.newtab (self, True)
mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK
if (event.state & mask) == mask:
if keyname == 'N':
def key_go_next(self):
self.terminator.go_next (self)
return (True)
elif keyname == "P":
def key_go_prev(self):
self.terminator.go_prev (self)
return (True)
elif keyname == 'O':
def key_split_horiz(self):
self.terminator.splitaxis (self, False)
return (True)
elif keyname == 'E':
def key_split_vert(self):
self.terminator.splitaxis (self, True)
return (True)
elif keyname == 'W':
def key_close_term(self):
self.terminator.closeterm (self)
return (True)
elif keyname == 'C':
self._vte.copy_clipboard ()
return (True)
elif keyname == 'V':
self.paste_clipboard ()
return (True)
elif keyname == 'S':
self.do_scrollbar_toggle ()
return (True)
elif keyname == 'T':
def key_new_tab(self):
self.terminator.newtab(self)
return (True)
elif keyname in ('Up', 'Down', 'Left', 'Right'):
self.terminator.resizeterm (self, keyname)
return (True)
elif keyname == 'Page_Down':
def key_resize_up(self):
self.terminator.resizeterm (self, 'Up')
def key_resize_down(self):
self.terminator.resizeterm (self, 'Down')
def key_resize_left(self):
self.terminator.resizeterm (self, 'Left')
def key_resize_right(self):
self.terminator.resizeterm (self, 'Right')
def key_move_tab_right(self):
self.terminator.move_tab (self, 'right')
return (True)
elif keyname == 'Page_Up':
def key_move_tab_right(self):
self.terminator.move_tab (self, 'left')
return (True)
elif keyname == 'Z':
self.terminator.toggle_zoom (self, True)
return (True)
elif keyname == 'X':
def key_toggle_zoom(self):
self.terminator.toggle_zoom (self)
return (True)
mask = gtk.gdk.CONTROL_MASK
if (event.state & mask) == mask:
if keyname == 'Page_Down':
self.terminator.next_tab(self)
return (True)
elif keyname == 'Page_Up':
self.terminator.previous_tab(self)
return (True)
def key_scaled_zoom(self):
self.terminator.toggle_zoom (self, True)
if keyname and (keyname == 'Tab' or keyname.endswith('_Tab')):
mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK
if (event.state & mask) == mask:
def key_go_prev(self):
self.terminator.go_prev (self)
return (True)
mask = gtk.gdk.CONTROL_MASK
if (event.state & mask) == mask:
def key_go_next(self):
self.terminator.go_next (self)
return (True)
# Warning, mask value is either gtk.gdk.CONTROL_MASK or gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK
# if you intend to use it, reinit it
return (False)
# End key events
def zoom_orig (self):
self._vte.set_font (pango.FontDescription (self.conf.font))