+/**
+ * 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)
+{
+ 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)
+ {
+#if DEBUG
+ g_print ("Got a Ctrl+Left Click -- Matched: `%s' (%d)\n", match, tag);
+#endif
+ web_browser_cmd = g_strescape (self->web_browser, NULL);
+ cmd = g_strdup_printf ("%s %s", web_browser_cmd, match);
+#if DEBUG
+ g_print ("Launching command: `%s'\n", cmd);
+#endif
+ 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;
+}
+