struct tilda_term_ *tilda_term_init (struct tilda_window_ *tw) { DEBUG_FUNCTION ("tilda_term_init"); DEBUG_ASSERT (tw != NULL); int ret; struct tilda_term_ *term; GError *error = NULL; tilda_term *current_tt; gint current_tt_index; char *current_tt_dir = NULL; term = g_malloc (sizeof (struct tilda_term_)); /* Add to GList list of tilda_term structures in tilda_window structure */ tw->terms = g_list_append (tw->terms, term); /* Check for a failed allocation */ if (!term) return NULL; /* Set the PID to unset value */ term->pid = -1; /* Add the parent window reference */ term->tw = tw; /* Create a non-homogenous hbox, with 0px spacing between members */ term->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); /* Create the terminal */ term->vte_term = vte_terminal_new (); /* Create the scrollbar for the terminal */ term->scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (VTE_TERMINAL(term->vte_term)))); /* Initialize to false, we have not yet dropped to the default shell */ term->dropped_to_default_shell = FALSE; /* Set properties of the terminal */ tilda_term_config_defaults (term); /* Update the font scale because the newly created terminal uses the default font size */ tilda_term_adjust_font_scale(term, tw->current_scale_factor); /* Pack everything into the hbox */ gtk_box_pack_end (GTK_BOX(term->hbox), term->scrollbar, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX(term->hbox), term->vte_term, TRUE, TRUE, 0); gtk_widget_show (term->scrollbar); /* Set the scrollbar position */ tilda_term_set_scrollbar_position (term, config_getint ("scrollbar_pos")); /** Signal Connection **/ g_signal_connect (G_OBJECT(term->vte_term), "child-exited", G_CALLBACK(child_exited_cb), term); g_signal_connect (G_OBJECT(term->vte_term), "window-title-changed", G_CALLBACK(window_title_changed_cb), term); g_signal_connect (G_OBJECT(term->vte_term), "eof", G_CALLBACK(child_exited_cb), term); g_signal_connect (G_OBJECT(term->vte_term), "status-line-changed", G_CALLBACK(status_line_changed_cb), term); g_signal_connect (G_OBJECT(term->vte_term), "button-press-event", G_CALLBACK(button_press_cb), term); g_signal_connect (G_OBJECT(term->vte_term), "key-press-event", G_CALLBACK(key_press_cb), term); //needs GDK_KEY_PRESS_MASK /* Connect to application request signals. */ g_signal_connect (G_OBJECT(term->vte_term), "iconify-window", G_CALLBACK(iconify_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "deiconify-window", G_CALLBACK(deiconify_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "raise-window", G_CALLBACK(raise_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "lower-window", G_CALLBACK(lower_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "maximize-window", G_CALLBACK(maximize_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "restore-window", G_CALLBACK(restore_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "refresh-window", G_CALLBACK(refresh_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "move-window", G_CALLBACK(move_window_cb), tw->window); g_signal_connect (G_OBJECT (tw->notebook), "switch-page", G_CALLBACK (tilda_terminal_switch_page_cb), tw); /* Match URL's, etc */ term->http_regexp=g_regex_new(HTTP_REGEXP, G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY, &error); ret = vte_terminal_match_add_gregex(VTE_TERMINAL(term->vte_term), term->http_regexp,0); vte_terminal_match_set_cursor_type (VTE_TERMINAL(term->vte_term), ret, GDK_HAND2); /* Show the child widgets */ gtk_widget_show (term->vte_term); gtk_widget_show (term->hbox); /* Get current term's working directory */ current_tt_index = gtk_notebook_get_current_page (GTK_NOTEBOOK(tw->notebook)); current_tt = g_list_nth_data (tw->terms, current_tt_index); if (current_tt != NULL) { current_tt_dir = tilda_term_get_cwd(current_tt); } /* Fork the appropriate command into the terminal */ ret = start_shell (term, FALSE, current_tt_dir); g_free(current_tt_dir); if (ret) goto err_fork; return term; err_fork: g_free (term); return NULL; }
struct tilda_term_ *tilda_term_init (struct tilda_window_ *tw) { DEBUG_FUNCTION ("tilda_term_init"); DEBUG_ASSERT (tw != NULL); int ret; struct tilda_term_ *term; GError *error = NULL; term = g_malloc (sizeof (struct tilda_term_)); /* Check for a failed allocation */ if (!term) return NULL; /* Add the parent window reference */ term->tw = tw; /* Create a non-homogenous hbox, with 0px spacing between members */ term->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); /* Create the terminal */ term->vte_term = vte_terminal_new (); /* Create the scrollbar for the terminal */ term->scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (VTE_TERMINAL(term->vte_term)))); /* Set properties of the terminal */ tilda_term_config_defaults (term); /* Pack everything into the hbox */ gtk_box_pack_end (GTK_BOX(term->hbox), term->scrollbar, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX(term->hbox), term->vte_term, TRUE, TRUE, 0); gtk_widget_show (term->scrollbar); /* Set the scrollbar position */ tilda_term_set_scrollbar_position (term, config_getint ("scrollbar_pos")); /** Signal Connection **/ g_signal_connect (G_OBJECT(term->vte_term), "child-exited", G_CALLBACK(child_exited_cb), term); g_signal_connect (G_OBJECT(term->vte_term), "window-title-changed", G_CALLBACK(window_title_changed_cb), term); g_signal_connect (G_OBJECT(term->vte_term), "eof", G_CALLBACK(child_exited_cb), term); g_signal_connect (G_OBJECT(term->vte_term), "status-line-changed", G_CALLBACK(status_line_changed_cb), term); g_signal_connect (G_OBJECT(term->vte_term), "button-press-event", G_CALLBACK(button_press_cb), term); /* Connect to application request signals. */ g_signal_connect (G_OBJECT(term->vte_term), "iconify-window", G_CALLBACK(iconify_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "deiconify-window", G_CALLBACK(deiconify_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "raise-window", G_CALLBACK(raise_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "lower-window", G_CALLBACK(lower_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "maximize-window", G_CALLBACK(maximize_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "restore-window", G_CALLBACK(restore_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "refresh-window", G_CALLBACK(refresh_window_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "move-window", G_CALLBACK(move_window_cb), tw->window); /* Connect to font tweakage. */ g_signal_connect (G_OBJECT(term->vte_term), "increase-font-size", G_CALLBACK(increase_font_size_cb), tw->window); g_signal_connect (G_OBJECT(term->vte_term), "decrease-font-size", G_CALLBACK(decrease_font_size_cb), tw->window); /* Match URL's, etc */ term->http_regexp=g_regex_new(HTTP_REGEXP, G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY, &error); ret = vte_terminal_match_add_gregex(VTE_TERMINAL(term->vte_term), term->http_regexp,0); vte_terminal_match_set_cursor_type (VTE_TERMINAL(term->vte_term), ret, GDK_HAND2); /* Show the child widgets */ gtk_widget_show (term->vte_term); gtk_widget_show (term->hbox); /* Fork the appropriate command into the terminal */ ret = start_shell (term); if (ret) goto err_fork; return term; err_fork: g_free (term); return NULL; }