+/**
+ * Called when the child process running in the VteTerminal exits.
+ */
+static void
+tilda_terminal_child_exited_cb (GtkWidget *widget, gpointer data)
+{
+ debug_enter ();
+ debug_assert (GTK_IS_WIDGET(widget));
+ debug_assert (TILDA_IS_TERMINAL(data));
+
+ TildaTerminal *self = TILDA_TERMINAL(data);
+
+ /* These can stay here. They don't need to go into a header because
+ * they are only used at this point in the code. */
+ enum exit_actions { HOLD_TERMINAL_OPEN, RESTART_COMMAND, EXIT_TERMINAL };
+
+ /* Check the user's preference for what to do when the child terminal
+ * is closed. Take the appropriate action */
+ switch (self->exit_action)
+ {
+ case EXIT_TERMINAL:
+ tilda_window_remove_terminal (TILDA_WINDOW(self->parent_window), self->number);
+ break;
+ case RESTART_COMMAND:
+ vte_terminal_feed (VTE_TERMINAL(self->vte_term), "\r\n\r\n", 4);
+ tilda_terminal_start_shell (self);
+ break;
+ case HOLD_TERMINAL_OPEN:
+ break;
+ default:
+ break;
+ }
+}
+
+/**
+ * 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)
+{
+ debug_enter ();
+ debug_assert (GTK_IS_WIDGET(widget));
+ debug_assert (TILDA_IS_TERMINAL(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;
+
+ default:
+ debug_printf ("ERROR: Bad value of self->dynamic_title\n");
+ case NOT_DISPLAYED:
+ new_title = g_strdup(self->title);
+ break;
+ }
+
+ gtk_label_set_text (GTK_LABEL(label), new_title);
+ g_free (new_title);
+}
+
+/**
+ * Gets called whenever there is a button-press event in the VteTerminal. It
+ * is used to open the user's web browser, for example.
+ */
+static gint
+tilda_terminal_button_press_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer data)
+{
+ debug_enter ();
+ debug_assert (GTK_IS_WIDGET(widget));
+ debug_assert (TILDA_IS_TERMINAL(data));
+ debug_printf ("event->button = %d\n", event->button);
+
+ GError *error = NULL;
+ TildaTerminal *self = TILDA_TERMINAL(data);
+ VteTerminal *terminal = VTE_TERMINAL(self->vte_term);
+ gint tag, xpad, ypad;
+ gchar *match, *cmd, *web_browser_cmd;
+ gboolean ret = FALSE;
+
+ switch (event->button)
+ {
+ case 3: /* Right Click */
+ // FIXME: need to add this
+ //popup_menu (tt->tw, tt);
+ g_print ("FIXME: popup_menu() here\n");
+ break;
+
+ case 2: /* Middle Click */
+ break;
+
+ case 1: /* Left Click */
+ vte_terminal_get_padding (terminal, &xpad, &ypad);
+ match = vte_terminal_match_check (terminal,
+ (event->x - ypad) / terminal->char_width,
+ (event->y - ypad) / terminal->char_height,
+ &tag);
+
+ /* Check if we can launch a web browser, and do so if possible */
+ if ((event->state & GDK_CONTROL_MASK) && match != NULL)
+ {
+ web_browser_cmd = g_strescape (self->web_browser, NULL);
+ cmd = g_strdup_printf ("%s %s", web_browser_cmd, match);
+
+ debug_printf ("Got a Ctrl+Left-Click -- match: '%s' tag: %d\n", match, tag);
+ debug_printf ("Launching command: '%s'\n", cmd);
+
+ ret = g_spawn_command_line_async(cmd, &error);
+
+ /* Check that the command launched */
+ if (!ret)
+ {
+ g_printerr (_("Failed to launch web browser command: `%s'\n"), cmd);
+ g_printerr (_("Error message: %s\n"), error->message);
+ }
+
+ /* Free allocated memory */
+ g_free (web_browser_cmd);
+ g_free (cmd);
+ }
+
+ /* Always free match if it is non NULL */
+ g_free (match);
+ break;
+
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+/**
+ * Set the given TildaTerminal to the appropriate transparency level
+ * based on the self->transparency_percent member. */
+static void
+tilda_terminal_set_transparent (TildaTerminal *self)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_TERMINAL(self));
+
+ TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
+ gdouble temp;
+
+ /* Convert the transparency to VTE's format */
+ temp = ((gdouble) self->transparency_percent) / 100.0;
+
+ if (self->transparency_percent > 0)
+ {
+ vte_terminal_set_background_saturation (VTE_TERMINAL(self->vte_term), temp);
+ vte_terminal_set_opacity (VTE_TERMINAL(self->vte_term), (1.0 - temp) * 0xffff);
+
+ /* Use fake transparency if necessary */
+ vte_terminal_set_background_transparent (VTE_TERMINAL(self->vte_term),
+ !parent_window->have_real_transparency);
+ return;
+ }
+
+ /* Turn off transparency */
+ vte_terminal_set_background_saturation (VTE_TERMINAL(self->vte_term), 0);
+ vte_terminal_set_opacity (VTE_TERMINAL(self->vte_term), 0xffff);
+ vte_terminal_set_background_transparent (VTE_TERMINAL(self->vte_term), FALSE);
+}
+
+/**
+ * Set the scrollbar position of the given TildaTerminal to
+ * the value in self->scrollbar_position.
+ */
+static void
+tilda_terminal_set_scrollbar_position (TildaTerminal *self)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_TERMINAL(self));
+
+ enum scrollbar_positions { DISABLED, LEFT, RIGHT };
+ switch (self->scrollbar_position)
+ {
+ case LEFT:
+ gtk_box_reorder_child (GTK_BOX(self->hbox), self->scrollbar, 0);
+ gtk_widget_show (self->scrollbar);
+ break;
+
+ case RIGHT:
+ gtk_box_reorder_child (GTK_BOX(self->hbox), self->scrollbar, 1);
+ gtk_widget_show (self->scrollbar);
+ break;
+
+ default:
+ debug_printf ("ERROR: Bad scrollbar position\n");
+ case DISABLED:
+ gtk_widget_hide (self->scrollbar);
+ break;
+ }
+}
+