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