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_down': '<Ctrl><Shift>Down',
'resize_left': '<Ctrl><Shift>Left', 'resize_left': '<Ctrl><Shift>Left',
'resize_right': '<Ctrl><Shift>Right', 'resize_right': '<Ctrl><Shift>Right',
'move_tab_right': '<Ctrl><Shift>Page_Up', 'move_tab_right': '<Ctrl><Shift>Page_Down',
'move_tab_left': '<Ctrl><Shift>Page_Down', 'move_tab_left': '<Ctrl><Shift>Page_Up',
'toggle_zoom': '<Ctrl><Shift>X', 'toggle_zoom': '<Ctrl><Shift>X',
'scaled_zoom': '<Ctrl><Shift>Z',
'next_tab': '<Ctrl>Page_Down', 'next_tab': '<Ctrl>Page_Down',
'prev_tab': '<Ctrl>Page_Up', 'prev_tab': '<Ctrl>Page_Up',
'go_prev': '<Ctrl><Shift>Tab', 'go_prev': '<Ctrl><Shift>Tab',
@ -49,9 +50,9 @@ class TerminatorKeybindings:
empty = {} empty = {}
def __init__(self): def __init__(self):
self._parse() self.reload()
def _parse(self): def reload(self):
self._lookup = {} self._lookup = {}
self._masks = 0 self._masks = 0
for action, binding in self.keys.items(): for action, binding in self.keys.items():
@ -65,7 +66,9 @@ class TerminatorKeybindings:
raise e raise e
else: else:
self._lookup.setdefault(mask, {}) 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 self._masks |= mask
def _parsebinding(self, binding): def _parsebinding(self, binding):
@ -88,5 +91,5 @@ class TerminatorKeybindings:
def lookup(self, event): def lookup(self, event):
mask = event.state & self._masks mask = event.state & self._masks
keyval = gtk.gdk.keyval_name(event.keyval) 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 # import our configuration loader
from terminatorlib import config from terminatorlib import config
from terminatorlib.config import dbg, err, debug from terminatorlib.config import dbg, err, debug
from terminatorlib.keybindings import TerminatorKeybindings
#import TerminatorTerm #import TerminatorTerm
from terminatorlib.terminatorterm import TerminatorTerm from terminatorlib.terminatorterm import TerminatorTerm
@ -121,8 +122,10 @@ class Terminator:
self.icon_theme = gtk.IconTheme () self.icon_theme = gtk.IconTheme ()
self.keybindings = TerminatorKeybindings()
if self.conf.f11_modifier: 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): if self.conf.handle_size in xrange (0,6):
gtk.rc_parse_string(""" gtk.rc_parse_string("""
@ -254,15 +257,14 @@ class Terminator:
* F11: toggle fullscreen state of the window. * F11: toggle fullscreen state of the window.
* CTRL - SHIFT - Q: close all terminals * CTRL - SHIFT - Q: close all terminals
""" """
keyname = gtk.gdk.keyval_name (event.keyval) mapping = self.keybindings.lookup(event)
mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK
if (keyname == 'F11' and (self._f11_modifier == False or event.state & mask)): if mapping:
self.fullscreen_toggle () dbg("on_key_press: lookup found %s" % repr(mapping))
return (True) if mapping == 'full_screen':
self.fullscreen_toggle ()
if (event.state & mask) == mask: return (True)
if keyname == 'Q': elif mapping == 'close_window':
if not self.on_delete_event (window, gtk.gdk.Event (gtk.gdk.DELETE)): if not self.on_delete_event (window, gtk.gdk.Event (gtk.gdk.DELETE)):
self.on_destroy_event (window, gtk.gdk.Event (gtk.gdk.DESTROY)) 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 #keybindings for the individual splited terminals (affects only the
#the selected terminal) #the selected terminal)
UnhandledKeybindings = ('close_window', 'full_screen')
def on_vte_key_press (self, term, event): 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 mapping and mapping not in self.UnhandledKeybindings:
if (event.state & mask) == mask: dbg("on_vte_key_press: lookup found %s" % repr(mapping))
if keyname == 'plus': getattr(self, "key_" + mapping)()
self.zoom (True) return True
return (True)
elif keyname == 'minus':
self.zoom (False)
return (True)
elif keyname == 'equal':
self.zoom_orig ()
return (True)
mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK | gtk.gdk.MOD1_MASK return False
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
# has absolutely no reference to Terminator.
# N (next) - P (previous) - O (horizontal) - E (vertical) - W (close)
mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK # Key events
if (event.state & mask) == mask: def key_zoom_in(self): self.zoom (True)
if keyname == 'N':
self.terminator.go_next (self) def key_zoom_out(self): self.zoom (False)
return (True)
elif keyname == "P": def key_copy(self): self._vte.copy_clipboard ()
self.terminator.go_prev (self)
return (True) def key_paste(self): self.paste_clipboard ()
elif keyname == 'O':
self.terminator.splitaxis (self, False) def key_toggle_scrollbar(self): self.do_scrollbar_toggle ()
return (True)
elif keyname == 'E': def key_zoom_normal(self): self.zoom_orig ()
self.terminator.splitaxis (self, True)
return (True) # bindings that should be moved to Terminator as they all just call
elif keyname == 'W': # a function of Terminator. It would be cleaner if TerminatorTerm
self.terminator.closeterm (self) # has absolutely no reference to Terminator.
return (True) # N (next) - P (previous) - O (horizontal) - E (vertical) - W (close)
elif keyname == 'C': def key_new_root_tab(self):
self._vte.copy_clipboard () self.terminator.newtab (self, True)
return (True)
elif keyname == 'V': def key_go_next(self):
self.paste_clipboard () self.terminator.go_next (self)
return (True)
elif keyname == 'S': def key_go_prev(self):
self.do_scrollbar_toggle () self.terminator.go_prev (self)
return (True)
elif keyname == 'T': def key_split_horiz(self):
self.terminator.newtab(self) self.terminator.splitaxis (self, False)
return (True)
elif keyname in ('Up', 'Down', 'Left', 'Right'): def key_split_vert(self):
self.terminator.resizeterm (self, keyname) self.terminator.splitaxis (self, True)
return (True)
elif keyname == 'Page_Down': def key_close_term(self):
self.terminator.move_tab(self, 'right') self.terminator.closeterm (self)
return (True)
elif keyname == 'Page_Up': def key_new_tab(self):
self.terminator.move_tab(self, 'left') self.terminator.newtab(self)
return (True)
elif keyname == 'Z': def key_resize_up(self):
self.terminator.toggle_zoom (self, True) self.terminator.resizeterm (self, 'Up')
return (True)
elif keyname == 'X': def key_resize_down(self):
self.terminator.toggle_zoom (self) self.terminator.resizeterm (self, 'Down')
return (True)
def key_resize_left(self):
mask = gtk.gdk.CONTROL_MASK self.terminator.resizeterm (self, 'Left')
if (event.state & mask) == mask:
if keyname == 'Page_Down': def key_resize_right(self):
self.terminator.next_tab(self) self.terminator.resizeterm (self, 'Right')
return (True)
elif keyname == 'Page_Up': def key_move_tab_right(self):
self.terminator.previous_tab(self) self.terminator.move_tab (self, 'right')
return (True)
def key_move_tab_right(self):
if keyname and (keyname == 'Tab' or keyname.endswith('_Tab')): self.terminator.move_tab (self, 'left')
mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK
if (event.state & mask) == mask: def key_toggle_zoom(self):
self.terminator.go_prev (self) self.terminator.toggle_zoom (self)
return (True)
mask = gtk.gdk.CONTROL_MASK def key_scaled_zoom(self):
if (event.state & mask) == mask: self.terminator.toggle_zoom (self, True)
self.terminator.go_next (self)
return (True) def key_go_prev(self):
# Warning, mask value is either gtk.gdk.CONTROL_MASK or gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK self.terminator.go_prev (self)
# if you intend to use it, reinit it
return (False) def key_go_next(self):
self.terminator.go_next (self)
# End key events
def zoom_orig (self): def zoom_orig (self):
self._vte.set_font (pango.FontDescription (self.conf.font)) self._vte.set_font (pango.FontDescription (self.conf.font))