Hook up new keybinding code. Making them configurable shouldn't be far away...
This commit is contained in:
parent
d1787e576d
commit
e65e396d32
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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:
|
||||||
|
dbg("on_key_press: lookup found %s" % repr(mapping))
|
||||||
|
if mapping == 'full_screen':
|
||||||
self.fullscreen_toggle ()
|
self.fullscreen_toggle ()
|
||||||
return (True)
|
return (True)
|
||||||
|
elif mapping == 'close_window':
|
||||||
if (event.state & mask) == mask:
|
|
||||||
if keyname == 'Q':
|
|
||||||
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))
|
||||||
|
|
||||||
|
|
|
@ -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':
|
return False
|
||||||
self.zoom (False)
|
|
||||||
return (True)
|
# Key events
|
||||||
elif keyname == 'equal':
|
def key_zoom_in(self): self.zoom (True)
|
||||||
self.zoom_orig ()
|
|
||||||
return (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
|
# 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.
|
# has absolutely no reference to Terminator.
|
||||||
# N (next) - P (previous) - O (horizontal) - E (vertical) - W (close)
|
# 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
|
def key_go_next(self):
|
||||||
if (event.state & mask) == mask:
|
|
||||||
if keyname == 'N':
|
|
||||||
self.terminator.go_next (self)
|
self.terminator.go_next (self)
|
||||||
return (True)
|
|
||||||
elif keyname == "P":
|
def key_go_prev(self):
|
||||||
self.terminator.go_prev (self)
|
self.terminator.go_prev (self)
|
||||||
return (True)
|
|
||||||
elif keyname == 'O':
|
def key_split_horiz(self):
|
||||||
self.terminator.splitaxis (self, False)
|
self.terminator.splitaxis (self, False)
|
||||||
return (True)
|
|
||||||
elif keyname == 'E':
|
def key_split_vert(self):
|
||||||
self.terminator.splitaxis (self, True)
|
self.terminator.splitaxis (self, True)
|
||||||
return (True)
|
|
||||||
elif keyname == 'W':
|
def key_close_term(self):
|
||||||
self.terminator.closeterm (self)
|
self.terminator.closeterm (self)
|
||||||
return (True)
|
|
||||||
elif keyname == 'C':
|
def key_new_tab(self):
|
||||||
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':
|
|
||||||
self.terminator.newtab(self)
|
self.terminator.newtab(self)
|
||||||
return (True)
|
|
||||||
elif keyname in ('Up', 'Down', 'Left', 'Right'):
|
def key_resize_up(self):
|
||||||
self.terminator.resizeterm (self, keyname)
|
self.terminator.resizeterm (self, 'Up')
|
||||||
return (True)
|
|
||||||
elif keyname == 'Page_Down':
|
def key_resize_down(self):
|
||||||
self.terminator.move_tab(self, 'right')
|
self.terminator.resizeterm (self, 'Down')
|
||||||
return (True)
|
|
||||||
elif keyname == 'Page_Up':
|
def key_resize_left(self):
|
||||||
self.terminator.move_tab(self, 'left')
|
self.terminator.resizeterm (self, 'Left')
|
||||||
return (True)
|
|
||||||
elif keyname == 'Z':
|
def key_resize_right(self):
|
||||||
self.terminator.toggle_zoom (self, True)
|
self.terminator.resizeterm (self, 'Right')
|
||||||
return (True)
|
|
||||||
elif keyname == 'X':
|
def key_move_tab_right(self):
|
||||||
|
self.terminator.move_tab (self, 'right')
|
||||||
|
|
||||||
|
def key_move_tab_right(self):
|
||||||
|
self.terminator.move_tab (self, 'left')
|
||||||
|
|
||||||
|
def key_toggle_zoom(self):
|
||||||
self.terminator.toggle_zoom (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)
|
||||||
if keyname == 'Page_Down':
|
|
||||||
self.terminator.next_tab(self)
|
|
||||||
return (True)
|
|
||||||
elif keyname == 'Page_Up':
|
|
||||||
self.terminator.previous_tab(self)
|
|
||||||
return (True)
|
|
||||||
|
|
||||||
if keyname and (keyname == 'Tab' or keyname.endswith('_Tab')):
|
def key_go_prev(self):
|
||||||
mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK
|
|
||||||
if (event.state & mask) == mask:
|
|
||||||
self.terminator.go_prev (self)
|
self.terminator.go_prev (self)
|
||||||
return (True)
|
|
||||||
mask = gtk.gdk.CONTROL_MASK
|
def key_go_next(self):
|
||||||
if (event.state & mask) == mask:
|
|
||||||
self.terminator.go_next (self)
|
self.terminator.go_next (self)
|
||||||
return (True)
|
# End key events
|
||||||
# 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)
|
|
||||||
|
|
||||||
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))
|
||||||
|
|
Loading…
Reference in New Issue