+/**
+ * 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);
+}
+