From 17121308d98b5d09b890f14d3e17b22909703516 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Sun, 13 Jan 2008 23:47:10 -0800 Subject: [PATCH] [Terminal] Make dynamic titles work properly Dynamic title generation was not working at all before, now it is handled by tilda_terminal_window_title_changed_cb(). --- tilda-terminal.c | 61 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/tilda-terminal.c b/tilda-terminal.c index 87b081a..d1533db 100644 --- a/tilda-terminal.c +++ b/tilda-terminal.c @@ -96,7 +96,7 @@ launch_default_shell: * Called when the child process running in the VteTerminal exits. */ static void -child_exited_cb (GtkWidget *widget, gpointer data) +tilda_terminal_child_exited_cb (GtkWidget *widget, gpointer data) { TildaTerminal *self = TILDA_TERMINAL(data); @@ -122,6 +122,59 @@ child_exited_cb (GtkWidget *widget, gpointer data) } } +/** + * Called when the child window title changes. Determines if a new + * title needs to be put into the notebook's tab label. + */ +static void +tilda_terminal_window_title_changed_cb (GtkWidget *widget, gpointer data) +{ + TildaTerminal *self = TILDA_TERMINAL(data); + TildaWindow *parent_window = TILDA_WINDOW(self->parent_window); + GtkWidget *label; + const gchar *vte_title; + gchar *new_title; + + enum dynamic_titles { NOT_DISPLAYED, AFTER_INITIAL, BEFORE_INITIAL, REPLACE_INITIAL }; + label = gtk_notebook_get_tab_label (GTK_NOTEBOOK(parent_window->notebook), self->hbox); + + /* If we aren't using a dynamic title -- NOT_DISPLAYED -- then just + * set it to the static title and exit */ + if (!self->dynamic_title) + { + gtk_label_set_text (GTK_LABEL(label), self->title); + return; + } + + /* Get the title from VTE */ + vte_title = vte_terminal_get_window_title (VTE_TERMINAL (widget)); + + /* Take the appropriate action */ + switch (self->dynamic_title) + { + case REPLACE_INITIAL: + new_title = g_strdup (vte_title); + break; + + case BEFORE_INITIAL: + new_title = g_strdup_printf ("%s - %s", vte_title, self->title); + break; + + case AFTER_INITIAL: + new_title = g_strdup_printf ("%s - %s", self->title, vte_title); + break; + + case NOT_DISPLAYED: + default: + g_printerr (_("FIXME: Bad value of self->dynamic_title\n")); + new_title = g_strdup(self->title); + break; + } + + gtk_label_set_text (GTK_LABEL(label), new_title); + g_free (new_title); +} + /******************************************************************************* * All GObject stuff is below. You probably don't need to change this... ******************************************************************************/ @@ -480,9 +533,11 @@ tilda_terminal_constructor (GType type, /* Connect Signals */ g_signal_connect (G_OBJECT(self->vte_term), "child-exited", - G_CALLBACK(child_exited_cb), self); + G_CALLBACK(tilda_terminal_child_exited_cb), self); g_signal_connect (G_OBJECT(self->vte_term), "eof", - G_CALLBACK(child_exited_cb), self); + G_CALLBACK(tilda_terminal_child_exited_cb), self); + g_signal_connect (G_OBJECT(self->vte_term), "window-title-changed", + G_CALLBACK(tilda_terminal_window_title_changed_cb), self); tilda_terminal_start_shell (self); tilda_terminal_dbus_register_object (self); -- 2.25.1