From f00c265f4cb34c48e83ead29b74a9b4e365ac1c9 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Wed, 2 Sep 2009 21:10:28 +0100 Subject: [PATCH] Make the window title update with the terminal title --- terminatorlib/terminal.py | 21 ++++++++++++++++++++- terminatorlib/titlebar.py | 6 ++++++ terminatorlib/window.py | 8 ++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index fda7e3f4..96599595 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -29,6 +29,8 @@ class Terminal(gtk.VBox): __gsignals__ = { 'close-term': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), + 'title-change': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, + (gobject.TYPE_STRING,)), } TARGET_TYPE_VTE = 8 @@ -39,6 +41,7 @@ class Terminal(gtk.VBox): searchbar = None cwd = None + command = None clipboard = None matches = None @@ -221,6 +224,10 @@ class Terminal(gtk.VBox): """Reconfigure our settings""" pass + def get_window_title(self): + """Return the window title""" + return(self.vte.get_window_title() or str(self.command)) + def on_group_button_press(self): """Handler for the group button""" pass @@ -252,7 +259,18 @@ class Terminal(gtk.VBox): pass def on_vte_title_change(self, vte): - pass + title = self.get_window_title() + if title == self.titlebar.oldtitle: + # Title hasn't changed, don't do anything + return + self.titlebar.oldtitle = title + + if self.config['titletips']: + vte.set_property('has-tooltip', True) + vte.set_property('tooltip-text', title) + + self.titlebar.set_terminal_title(title) + self.emit('title-change', title) def on_vte_focus(self, vte): pass @@ -312,6 +330,7 @@ class Terminal(gtk.VBox): self.pid = self.vte.fork_command(command=shell, argv=args, envv=[], loglastlog=login, logwtmp=update_records, logutmp=update_records, directory=self.cwd) + self.command = shell self.on_vte_title_change(self.vte) self.titlebar.update() diff --git a/terminatorlib/titlebar.py b/terminatorlib/titlebar.py index 5283499c..cf0ad1b0 100755 --- a/terminatorlib/titlebar.py +++ b/terminatorlib/titlebar.py @@ -10,6 +10,8 @@ import gobject class Titlebar(gtk.EventBox): """Class implementing the Titlebar widget""" + oldtitle = None + def __init__(self): """Class initialiser""" gtk.EventBox.__init__(self) @@ -29,4 +31,8 @@ class Titlebar(gtk.EventBox): """Update the displayed terminal size""" pass + def set_terminal_title(self, title): + """Update the terminal title""" + pass + gobject.type_register(Titlebar) diff --git a/terminatorlib/window.py b/terminatorlib/window.py index bb787ba1..fd654f14 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -45,6 +45,9 @@ class Window(Container, gtk.Window): self.register_callbacks() self.apply_config() + self.title = WindowTitle(self) + self.title.update() + def register_callbacks(self): """Connect the GTK+ signals we care about""" self.connect('key-press-event', self.on_key_press) @@ -158,6 +161,7 @@ class Window(Container, gtk.Window): def add(self, widget): """Add a widget to the window by way of gtk.Window.add()""" widget.connect('close-term', self.closeterm) + widget.connect('title-change', self.title.set_title) gtk.Window.add(self, widget) def remove(self, widget): @@ -177,10 +181,10 @@ class WindowTitle(object): self.window = window self.forced = False - def set_title(self, newtext): + def set_title(self, widget, text): """Set the title""" if not self.forced: - self.text = newtext + self.text = text self.update() def force_title(self, newtext):