static VALUE rg_initialize(VALUE self, VALUE flags_or_fd) { VtePty *pty = NULL; GError *error = NULL; if (TYPE(flags_or_fd) == T_FIXNUM) { pty = vte_pty_new_foreign(NUM2INT(flags_or_fd), &error); } else { pty = vte_pty_new(RVAL2VTEPTYFLAGS(flags_or_fd), &error); } if (error) RAISE_GERROR(error); G_INITIALIZE(self, pty); return Qnil; }
void conterm_init(void) { GtkWidget *console; #ifdef G_OS_UNIX gchar *error = NULL; int pty_master; char *pty_name; #endif conterm_load_config(); #ifdef G_OS_UNIX program_window = get_widget("program_window"); console = vte_terminal_new(); gtk_widget_show(console); program_terminal = VTE_TERMINAL(console); g_object_ref(program_terminal); gtk_container_add(GTK_CONTAINER(program_window), console); g_signal_connect_after(program_terminal, "realize", G_CALLBACK(on_vte_realize), NULL); terminal_parent = get_widget("terminal_parent"); g_signal_connect(terminal_parent, "delete-event", G_CALLBACK(on_terminal_parent_delete), NULL); terminal_window = get_widget("terminal_window"); terminal_show = GTK_CHECK_MENU_ITEM(get_widget("terminal_show")); if (pref_terminal_padding) { gint vte_border_x, vte_border_y; #if GTK_CHECK_VERSION(3, 4, 0) GtkStyleContext *context; GtkBorder border; context = gtk_widget_get_style_context (console); gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL, &border); vte_border_x = border.left + border.right; vte_border_y = border.top + border.bottom; #elif VTE_CHECK_VERSION(0, 24, 0) GtkBorder *border = NULL; gtk_widget_style_get(console, "inner-border", &border, NULL); if (border) { vte_border_x = border->left + border->right; vte_border_y = border->top + border->bottom; gtk_border_free(border); } else vte_border_x = vte_border_y = 2; #else /* VTE 0.24.0 */ /* VTE manual says "deprecated since 0.26", but it's since 0.24 */ vte_terminal_get_padding(program_terminal, &vte_border_x, &vte_border_y); #endif /* VTE 0.24.0 */ pref_terminal_width += vte_border_x; pref_terminal_height += vte_border_y; pref_terminal_padding = FALSE; } if (openpty(&pty_master, &pty_slave, NULL, NULL, NULL) == 0 && grantpt(pty_master) == 0 && unlockpt(pty_master) == 0 && (pty_name = ttyname(pty_slave)) != NULL) { #if VTE_CHECK_VERSION(0, 25, 0) GError *gerror = NULL; VtePty *pty = vte_pty_new_foreign(pty_master, &gerror); if (pty) { vte_terminal_set_pty_object(program_terminal, pty); slave_pty_name = g_strdup(pty_name); } else { error = g_strdup(gerror->message); g_error_free(gerror); } #else /* VTE 0.25.0 */ vte_terminal_set_pty(program_terminal, pty_master); slave_pty_name = g_strdup(pty_name); #endif /* VTE 0.25.0 */ } else error = g_strdup_printf("pty: %s", g_strerror(errno)); if (error) { gtk_widget_set_sensitive(program_window, FALSE); gtk_widget_set_sensitive(GTK_WIDGET(terminal_show), FALSE); msgwin_status_add(_("Scope: %s."), error); g_free(error); } else menu_connect("terminal_menu", &terminal_menu_info, GTK_WIDGET(program_terminal)); #else /* G_OS_UNIX */ gtk_widget_hide(get_widget("program_window")); #endif /* G_OS_UNIX */ #ifdef G_OS_UNIX if (pref_debug_console_vte) { console = vte_terminal_new(); gtk_widget_show(console); debug_console = VTE_TERMINAL(console); dc_output = console_output; dc_output_nl = console_output_nl; g_signal_connect_after(debug_console, "realize", G_CALLBACK(on_vte_realize), NULL); menu_connect("console_menu", &console_menu_info, console); } else #endif /* G_OS_UNIX */ { static const char *const colors[NFD] = { "#00C0C0", "#C0C0C0", "#C00000", "#C0C0C0", "#C000C0" }; guint i; console = get_widget("debug_context"); context_apply_config(console); debug_context = GTK_TEXT_VIEW(console); dc_output = context_output; dc_output_nl = context_output_nl; context = gtk_text_view_get_buffer(debug_context); for (i = 0; i < NFD; i++) { fd_tags[i] = gtk_text_buffer_create_tag(context, NULL, "foreground", colors[i], NULL); } g_signal_connect(console, "button-press-event", G_CALLBACK(on_console_button_3_press), menu_connect("console_menu", &console_menu_info, NULL)); } gtk_container_add(GTK_CONTAINER(get_widget("debug_window")), console); g_signal_connect(console, "key-press-event", G_CALLBACK(on_console_key_press), NULL); }