From cb87e86bf9a0411d7c279a0535e602d43ec69ec8 Mon Sep 17 00:00:00 2001 From: Thomas Meire Date: Mon, 14 Jan 2008 16:41:52 +0100 Subject: [PATCH 1/4] make F11 toggle fullscreen (fixes bug #182863) --- terminator | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/terminator b/terminator index 9cc00b0e..6141dab1 100755 --- a/terminator +++ b/terminator @@ -92,7 +92,7 @@ class TerminatorTerm: matches = {} - def __init__ (self, term, profile): + def __init__ (self, term, profile, pwd=None): self.defaults['profile_dir'] = self.defaults['_profile_dir']%(self.defaults['gt_dir']) self.defaults['link_user'] = self.defaults['_link_user']%(self.defaults['link_userchars'], self.defaults['link_passchars']) @@ -161,9 +161,9 @@ class TerminatorTerm: self.matches['path'] = self._vte.match_add ('((%s://(%s@)?)|(www|ftp)[%s]*\\.)[%s.]+(:[0-9]+)?/[-A-Za-z0-9_$.+!*(),;:@&=?/~#%%]*[^]\'.}>) \t\r\n,\\\]'%(self.defaults['link_scheme'], self.defaults['link_userchars'], self.defaults['link_hostchars'], self.defaults['link_hostchars'])) self.matches['email'] = self._vte.match_add ('(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+') - self.spawn_child () + self.spawn_child (pwd) - def spawn_child (self, event=None): + def spawn_child (self, dir=None, event=None): update_records = self.gconf_client.get_bool (self.profile + "/update_records") or True login = self.gconf_client.get_bool (self.profile + "/login_shell") or False @@ -173,6 +173,8 @@ class TerminatorTerm: else: shell = pwd.getpwuid (os.getuid ())[6] args = [os.path.basename (shell)] + if dir: + args.append(dir) self._vte.fork_command (command = shell, argv = args, envv = [], loglastlog = login, logwtmp = update_records, logutmp = update_records) @@ -518,6 +520,10 @@ class Terminator: keyname = gtk.gdk.keyval_name (event.keyval) mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK + if (keyname == 'F11'): + self.toggle_fullscreen () + return (True) + if (event.state & mask) == mask: if keyname == 'F': self.toggle_fullscreen () @@ -587,7 +593,7 @@ class Terminator: # insert the term reference into the list index = self.term_list.index (widget) self.term_list.insert (index + 1, term2) - widget._vte.grab_focus () + term2._vte.grab_focus () return (term2) From 77acf827de09e8b2b1ab943003eb62921fd3e8ce Mon Sep 17 00:00:00 2001 From: Thomas Meire Date: Mon, 14 Jan 2008 18:04:13 +0100 Subject: [PATCH 2/4] reverted all changes related to the pwd (not ready for trunk yet) --- terminator | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/terminator b/terminator index 6141dab1..61904ef0 100755 --- a/terminator +++ b/terminator @@ -92,7 +92,7 @@ class TerminatorTerm: matches = {} - def __init__ (self, term, profile, pwd=None): + def __init__ (self, term, profile): self.defaults['profile_dir'] = self.defaults['_profile_dir']%(self.defaults['gt_dir']) self.defaults['link_user'] = self.defaults['_link_user']%(self.defaults['link_userchars'], self.defaults['link_passchars']) @@ -161,9 +161,9 @@ class TerminatorTerm: self.matches['path'] = self._vte.match_add ('((%s://(%s@)?)|(www|ftp)[%s]*\\.)[%s.]+(:[0-9]+)?/[-A-Za-z0-9_$.+!*(),;:@&=?/~#%%]*[^]\'.}>) \t\r\n,\\\]'%(self.defaults['link_scheme'], self.defaults['link_userchars'], self.defaults['link_hostchars'], self.defaults['link_hostchars'])) self.matches['email'] = self._vte.match_add ('(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+') - self.spawn_child (pwd) + self.spawn_child () - def spawn_child (self, dir=None, event=None): + def spawn_child (self, event=None): update_records = self.gconf_client.get_bool (self.profile + "/update_records") or True login = self.gconf_client.get_bool (self.profile + "/login_shell") or False @@ -173,8 +173,6 @@ class TerminatorTerm: else: shell = pwd.getpwuid (os.getuid ())[6] args = [os.path.basename (shell)] - if dir: - args.append(dir) self._vte.fork_command (command = shell, argv = args, envv = [], loglastlog = login, logwtmp = update_records, logutmp = update_records) From 6d79b2d80a1469e662c173372c4bddfbe05f450e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Valc=C3=A1rcel?= Date: Mon, 14 Jan 2008 15:52:28 -0500 Subject: [PATCH 3/4] added some documentation to the code and clean some algorithms --- terminator | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/terminator b/terminator index 61904ef0..630a38f6 100755 --- a/terminator +++ b/terminator @@ -295,6 +295,8 @@ class TerminatorTerm: self._vte.set_size (self._vte.get_column_count () - int(math.ceil(self._scrollbar.allocation.width / self._vte.get_char_width ())), self._vte.get_row_count ()) self._scrollbar.show () +#keybindings for the individual splited terminals (affects only the +#the selected terminal) def on_vte_key_press (self, term, event): keyname = gtk.gdk.keyval_name (event.keyval) mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK @@ -324,10 +326,7 @@ class TerminatorTerm: elif keyname == 'plus': self.zoom (True) return (True) - - mask = gtk.gdk.CONTROL_MASK - if keyname and (keyname == 'minus'): - if (event.state & mask) == mask: + elif keyname == 'minus': self.zoom (False) if keyname and (keyname == 'Tab' or keyname.endswith('_Tab')): @@ -510,6 +509,8 @@ class Terminator: def on_destroy_event (self, widget, data=None): gtk.main_quit () +#keybindingd for the whole terminal window (affects the main +#windows containing the splited terminals) def on_key_press (self, window, event): """ Callback for the window to determine what to do with special keys. Currently handled key-combo's: From 3bb1299f47a8d050cc00c0a1c3e0e8184612295d Mon Sep 17 00:00:00 2001 From: Thomas Meire Date: Mon, 14 Jan 2008 23:45:43 +0100 Subject: [PATCH 4/4] removed the computations from splitaxis and do_scrollbar_toggle as they were obsolete. Removed the ctrl-shft-f binding for fullscreen state. Cleaned up the splitaxis function, and commented it. --- terminator | 94 ++++++++++++++++++++++++------------------------------ 1 file changed, 42 insertions(+), 52 deletions(-) diff --git a/terminator b/terminator index 630a38f6..cfd0ef9c 100755 --- a/terminator +++ b/terminator @@ -291,16 +291,28 @@ class TerminatorTerm: if self._scrollbar.get_property ('visible'): self._scrollbar.hide () else: - # We need to make the terminal narrower by the width of the scrollbar - self._vte.set_size (self._vte.get_column_count () - int(math.ceil(self._scrollbar.allocation.width / self._vte.get_char_width ())), self._vte.get_row_count ()) self._scrollbar.show () -#keybindings for the individual splited terminals (affects only the -#the selected terminal) + #keybindings for the individual splited terminals (affects only the + #the selected terminal) def on_vte_key_press (self, term, event): keyname = gtk.gdk.keyval_name (event.keyval) - mask = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK + 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) + + # 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 if (event.state & mask) == mask: if keyname == 'N': self.term.go_next (self) @@ -323,11 +335,6 @@ class TerminatorTerm: elif keyname == 'V': self._vte.paste_clipboard () return (True) - elif keyname == 'plus': - self.zoom (True) - return (True) - elif keyname == 'minus': - self.zoom (False) if keyname and (keyname == 'Tab' or keyname.endswith('_Tab')): if event.state == gtk.gdk.CONTROL_MASK: @@ -509,12 +516,13 @@ class Terminator: def on_destroy_event (self, widget, data=None): gtk.main_quit () -#keybindingd for the whole terminal window (affects the main -#windows containing the splited terminals) + # keybindings for the whole terminal window (affects the main + # windows containing the splited terminals) def on_key_press (self, window, event): """ Callback for the window to determine what to do with special keys. Currently handled key-combo's: - * CTRL - SHIFT - F : toggle fullscreen state of the window. + * 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 @@ -524,58 +532,35 @@ class Terminator: return (True) if (event.state & mask) == mask: - if keyname == 'F': - self.toggle_fullscreen () - return (True) if keyname == 'Q': if not self.on_delete_event (window, gtk.gdk.Event (gtk.gdk.DELETE)): self.on_destroy_event (window, gtk.gdk.Event (gtk.gdk.DESTROY)) - def splitaxis (self, widget, vert=True): - term2 = TerminatorTerm (self, self.profile) + def splitaxis (self, widget, vertical=True): + """ Split the provided widget on the horizontal or vertical axis. """ - parent = widget.get_box ().get_parent () + # create a new terminal and parent pane. + terminal = TerminatorTerm (self, self.profile) + pane = (vertical) and gtk.VPaned () or gtk.HPaned () - if vert: - pane = gtk.VPaned () - else: - pane = gtk.HPaned () - - # VTE doesn't seem to cope well with being resized by the window manager. I expect I am supposed to send some kind of WINCH, or just generally connect window resizing events to a callback that will often tell vte about the new size. For now, cheat. Badly. - cols = widget._vte.get_column_count () - rows = widget._vte.get_row_count () - allowance = widget._scrollbar.allocation.width + pane.style_get_property ('handle-size') - - if vert: - width = cols - height = (rows / 2) - (allowance / widget._vte.get_char_height ()) - else: - width = (cols / 2) - (allowance / widget._vte.get_char_width ()) - height = rows - - widget._vte.set_size (width, height) - term2._vte.set_size (width, height) + # get the parent of the provided terminal + parent = widget.get_box ().get_parent () if isinstance (parent, gtk.Window): # We have just one term - if vert: - newpos = parent.allocation.height / 2 - else: - newpos = parent.allocation.width / 2 - widget.get_box ().reparent (pane) pane.pack1 (widget.get_box (), True, True) - pane.pack2 (term2.get_box (), True, True) + pane.pack2 (terminal.get_box (), True, True) parent.add (pane) - pane.set_position (newpos) + + position = (vertical) and parent.allocation.height or parent.allocation.width if isinstance (parent, gtk.Paned): # We are inside a split term - if vert: - term2._vte.set_size (cols, (rows / 2) - 1) + position = (vertical) and widget.get_box().allocation.height or widget.get_box().allocation.width if (widget.get_box () == parent.get_child1 ()): widget.get_box ().reparent (pane) @@ -585,16 +570,21 @@ class Terminator: parent.pack2 (pane, True, True) pane.pack1 (widget.get_box (), True, True) - pane.pack2 (term2.get_box (), True, True) + pane.pack2 (terminal.get_box (), True, True) + # show all, set position of the divider pane.show () - term2.get_box ().show () + pane.set_position (position / 2) + terminal.get_box ().show () + # insert the term reference into the list index = self.term_list.index (widget) - self.term_list.insert (index + 1, term2) - term2._vte.grab_focus () + self.term_list.insert (index + 1, terminal) + + # make the new terminal grab the focus + terminal._vte.grab_focus () - return (term2) + return (terminal) def closeterm (self, widget): parent = widget.get_box ().get_parent ()