static GtkWidget * create_terminal (TerminalPlugin *term_plugin) { GtkWidget *term; /* Create new terminal. */ term = vte_terminal_new (); gtk_widget_set_size_request (GTK_WIDGET (term), 10, 10); vte_terminal_set_size (VTE_TERMINAL (term), 50, 1); g_signal_connect (G_OBJECT (term), "focus-in-event", G_CALLBACK (terminal_focus_cb), term_plugin); g_signal_connect (G_OBJECT (term), "button-press-event", G_CALLBACK (terminal_click_cb), term_plugin); #if OLD_VTE == 1 g_signal_connect (G_OBJECT (term), "realize", G_CALLBACK (terminal_realize_cb), term_plugin); g_signal_connect (G_OBJECT (term), "unrealize", G_CALLBACK (terminal_unrealize_cb), term_plugin); #endif return term; }
console_t *uimon_window_open(void) { GtkWidget *scrollbar, *horizontal_container; if (fixed.window == NULL) { fixed.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(fixed.window), "VICE monitor"); gtk_window_set_position(GTK_WINDOW(fixed.window), GTK_WIN_POS_CENTER); gtk_widget_set_app_paintable(fixed.window, TRUE); gtk_window_set_deletable(GTK_WINDOW(fixed.window), TRUE); fixed.term = vte_terminal_new(); vte_terminal_set_scrollback_lines (VTE_TERMINAL(fixed.term), 1000); vte_terminal_set_scroll_on_output (VTE_TERMINAL(fixed.term), TRUE); scrollbar = gtk_vscrollbar_new(vte_terminal_get_adjustment (VTE_TERMINAL(fixed.term))); horizontal_container = gtk_hbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(fixed.window), horizontal_container); gtk_container_add(GTK_CONTAINER(horizontal_container), fixed.term); gtk_container_add(GTK_CONTAINER(horizontal_container), scrollbar); g_signal_connect(G_OBJECT(fixed.window), "delete-event", G_CALLBACK(close_window), &fixed.input_buffer); g_signal_connect(G_OBJECT(fixed.term), "key-press-event", G_CALLBACK(key_press_event), &fixed.input_buffer); g_signal_connect(G_OBJECT(fixed.term), "button-press-event", G_CALLBACK(button_press_event), &fixed.input_buffer); vte_console.console_xres = vte_terminal_get_column_count(VTE_TERMINAL(fixed.term)); vte_console.console_yres = vte_terminal_get_row_count(VTE_TERMINAL(fixed.term)); vte_console.console_can_stay_open = 1; } return uimon_window_resume(); }
GtkWidget *terminal_create (GError **error) { GtkWidget *self = vte_terminal_new(); VtePty *self_pty = vte_pty_new(0, error); if (!self_pty){ g_free(self); return NULL; } else { GPid c_pid = 0; char *c_argv[] = { "dmesg", NULL }; vte_terminal_set_pty_object(VTE_TERMINAL(self), self_pty); c_argv[0] = getenv("SHELL"); if(g_spawn_async(getenv("HOME"), c_argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, (GSpawnChildSetupFunc) vte_pty_child_setup, (void *) self_pty, &c_pid, error)){ g_child_watch_add(c_pid, terminal_child_exited, self); } else { vte_pty_close(self_pty); g_object_unref(self_pty); g_object_unref(self); return NULL; } } vte_terminal_set_opacity(VTE_TERMINAL(self), 0); vte_terminal_set_scrollback_lines(VTE_TERMINAL(self), 255); return self; }
/* * Implementation for a VteTerminal widget. */ static void terminal_init_vte(GtkWidget **terminal) { *terminal = vte_terminal_new(); g_signal_connect(G_OBJECT(*terminal), "eof", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(G_OBJECT(*terminal), "child-exited", G_CALLBACK(gtk_main_quit), NULL); }
Terminal::Terminal() { dock_hint = GdkRectangle{0, 0, 0, 0}; vte = vte_terminal_new(); char *argv[] = { vte_get_user_shell(), NULL }; vte_terminal_spawn_sync(VTE_TERMINAL(vte), VTE_PTY_DEFAULT, NULL, argv, NULL, (GSpawnFlags)0, NULL, NULL, &child_pid, NULL, NULL); set_orientation(Gtk::ORIENTATION_VERTICAL); scrollbox.set_orientation(Gtk::ORIENTATION_HORIZONTAL); scrollbar.set_orientation(Gtk::ORIENTATION_VERTICAL); eventbox.add(label); eventbox.signal_button_press_event().connect(mem_fun(this, &Terminal::header_button_press)); VteRegex *regex = vte_regex_new_for_match("(https?://|www\\.)[^\\s]*", -1, PCRE2_MULTILINE, NULL); vte_terminal_match_add_regex(VTE_TERMINAL(vte), regex, 0); vte_terminal_set_scrollback_lines(VTE_TERMINAL(vte), 10000); g_signal_connect(vte, "bell", G_CALLBACK(Terminal::vte_beep), this); g_signal_connect(vte, "child-exited", G_CALLBACK(Terminal::vte_child_exited), this); g_signal_connect(vte, "button-press-event", G_CALLBACK(Terminal::vte_click), this); g_signal_connect(vte, "focus-in-event", G_CALLBACK(Terminal::vte_got_focus), this); g_signal_connect(vte, "focus-out-event", G_CALLBACK(Terminal::vte_lost_focus), this); g_signal_connect(vte, "selection-changed", G_CALLBACK(Terminal::vte_selection_changed), this); g_signal_connect(vte, "window-title-changed", G_CALLBACK(Terminal::vte_title_changed), this); searchbar.add(searchentry); searchbar.connect_entry(searchentry); searchentry.signal_focus_out_event().connect(mem_fun(this, &Terminal::searchentry_lost_focus)); searchentry.signal_key_release_event().connect(mem_fun(this, &Terminal::searchentry_keypress)); pack_start(eventbox, false, false, 0); pack_start(scrollbox, true, true, 0); pack_start(searchbar, false, false, 0); gtk_box_pack_start(GTK_BOX(scrollbox.gobj()), vte, true, true, 0); scrollbox.pack_start(scrollbar, false, false, 0); gtk_range_set_adjustment(GTK_RANGE(scrollbar.gobj()), gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vte))); show_all_children(); find_label.terminal = this; find_label.set_alignment(0.0, 0.5); find_window->list_box.prepend(find_label); std::vector<Gtk::TargetEntry> listTargets; listTargets.push_back(Gtk::TargetEntry("SvanTerminal", Gtk::TARGET_SAME_APP, 0)); eventbox.drag_source_set(listTargets); drag_dest_set(listTargets); eventbox.signal_drag_begin().connect(sigc::mem_fun(this, &Terminal::on_my_drag_begin)); eventbox.signal_drag_failed().connect(sigc::mem_fun(this, &Terminal::on_my_drag_failed)); eventbox.signal_drag_end().connect(sigc::mem_fun(this, &Terminal::on_my_drag_end)); signal_drag_motion().connect(sigc::mem_fun(this, &Terminal::on_my_drag_motion)); signal_drag_drop().connect(sigc::mem_fun(this, &Terminal::on_my_drag_drop)); signal_drag_leave().connect(sigc::mem_fun(this, &Terminal::on_my_drag_leave)); }
int main (int argc, char **argv) { GtkWidget *window; GtkWidget *vbox; //container GtkWidget *entry1, *button1, *label1; //widgets diversos GList *dados = NULL; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 1); gtk_widget_set_size_request (window, 640, 480); gtk_window_set_icon_name (GTK_WINDOW (window), "gtk-home"); label1 = gtk_label_new ("Meu primeiro hello world em C"); button1 = gtk_button_new_with_label ("Definir titulo"); entry1 = gtk_entry_new_with_max_length (200); vbox = gtk_vbox_new (FALSE, 1); warning_label1 = gtk_label_new (""); //terminal hack terminal = vte_terminal_new (); initialize_vte (terminal); gtk_box_pack_start ((GtkBox *) vbox, label1, FALSE, FALSE, 5); gtk_box_pack_start ((GtkBox *) vbox, entry1, FALSE, FALSE, 2); gtk_box_pack_start ((GtkBox *) vbox, button1, FALSE, FALSE, 2); gtk_box_pack_start ((GtkBox *) vbox, terminal, TRUE, TRUE, 2); gtk_box_pack_start ((GtkBox *) vbox, warning_label1, FALSE, FALSE, 2); gtk_widget_hide ((GtkWidget *) warning_label1); gtk_window_set_title (GTK_WINDOW (window), "Meu Hello World com terminal"); dados = g_list_append (dados, GTK_ENTRY (entry1)); dados = g_list_append (dados, GTK_WINDOW (window)); g_signal_connect (G_OBJECT (terminal), "child-exited", G_CALLBACK (initialize_vte), NULL); g_signal_connect_swapped (G_OBJECT (button1), "clicked", G_CALLBACK (on_button1_clicked), G_OBJECT (dados)); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_widget_show (vbox); gtk_widget_show (entry1); gtk_widget_show (button1); gtk_widget_show (window); gtk_widget_show_all (window); gtk_main (); return 0; }
void terminal::create_vte_terminal() { if ( m_terminal_widget == NULL ) { m_terminal_widget = vte_terminal_new(); m_terminal = VTE_TERMINAL( m_terminal_widget ); g_signal_connect(G_OBJECT(m_terminal_widget), "destroy", G_CALLBACK(gtk_widget_destroyed), &m_terminal_widget); } if ( m_configuration != NULL ) this->setup_terminal(); }
PUSS_EXPORT void* puss_plugin_create(Puss* app) { PussVConsole* self; GtkWindow* window; GModule* module; bindtextdomain(TEXT_DOMAIN, app->get_locale_path()); bind_textdomain_codeset(TEXT_DOMAIN, "UTF-8"); window = puss_get_main_window(app); module = (GModule*)g_object_get_data(G_OBJECT(window), LIBVTE_KEEP_KEY); if( !module ) { module = g_module_open("libvte", G_MODULE_BIND_LAZY); if( !module ) { g_printerr("warning(puss_vconsole) : keep libvte failed! reload plugin will cause error!\n"); } else { g_object_set_data_full(G_OBJECT(window), LIBVTE_KEEP_KEY, module, (GDestroyNotify)g_module_close); } } self = g_new0(PussVConsole, 1); self->app = app; self->vte = vte_terminal_new(); { GtkWidget* hbox = gtk_hbox_new(FALSE, 4); GtkWidget* sbar = gtk_vscrollbar_new( vte_terminal_get_adjustment(VTE_TERMINAL(self->vte)) ); gtk_box_pack_start(GTK_BOX(hbox), self->vte, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), sbar, FALSE, FALSE, 0); g_signal_connect(self->vte, "child-exited", G_CALLBACK(on_quit), self); vte_terminal_fork_command( VTE_TERMINAL(self->vte) , 0, 0 , 0, 0 , FALSE , FALSE , FALSE ); vte_terminal_set_size(VTE_TERMINAL(self->vte), vte_terminal_get_column_count(VTE_TERMINAL(self->vte)), 5); vte_terminal_set_audible_bell(VTE_TERMINAL(self->vte), FALSE); gtk_widget_set_size_request(self->vte, 200, 50); gtk_widget_show_all(hbox); self->panel = hbox; app->panel_append(self->panel, gtk_label_new(_("Terminal")), "puss_vconsole_plugin_panel", PUSS_PANEL_POS_BOTTOM); } return self; }
GtkWidget* build_term(void) { if(!popupmenu) build_popupmenu(); GtkWidget* term = vte_terminal_new(); term_fork_command(VTE_TERMINAL(term), conf_get_shell()); if (conf_get_bg_image() != NULL) vte_terminal_set_background_image_file(VTE_TERMINAL(term), conf_get_bg_image()); GdkColor fore, back; fore = conf_get_fg(); back = conf_get_bg(); GdkColor *palette = conf_get_color_palette(); if(palette == NULL) vte_terminal_set_colors(VTE_TERMINAL(term), &fore, &back, NULL, 0); else vte_terminal_set_colors(VTE_TERMINAL(term), &fore, &back, palette, 16); #if VTE_CHECK_VERSION(0,25,0) vte_pty_set_term(vte_terminal_get_pty_object(VTE_TERMINAL(term)), conf_get_emulation()); #endif vte_terminal_set_background_tint_color(VTE_TERMINAL(term), &back); vte_terminal_set_allow_bold(VTE_TERMINAL(term), conf_get_allow_bold()); vte_terminal_set_scroll_on_output(VTE_TERMINAL(term), conf_get_scroll_on_output()); vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(term), TRUE); vte_terminal_set_font_from_string(VTE_TERMINAL(term), conf_get_font()); vte_terminal_set_scrollback_lines(VTE_TERMINAL(term), conf_get_lines()); vte_terminal_set_backspace_binding(VTE_TERMINAL(term), VTE_ERASE_ASCII_DELETE); vte_terminal_set_word_chars(VTE_TERMINAL(term), "-A-Za-z0-9_$.+!*(),;:@&=?/~#%"); GdkColor cursor = conf_get_cursor_color(); vte_terminal_set_cursor_blink_mode(VTE_TERMINAL(term), conf_get_cursor_blink() ? VTE_CURSOR_BLINK_ON : VTE_CURSOR_BLINK_OFF); vte_terminal_set_cursor_shape(VTE_TERMINAL(term), conf_get_cursor_shape()); vte_terminal_set_color_cursor(VTE_TERMINAL(term), &cursor); term_connect_signals(term); return term; }
/** * create a new page for a guest */ static page_t* create_page(guest_t *guest) { GtkWidget *label; page_t *page; page = g_new(page_t, 1); page->guest = guest; page->vte = vte_terminal_new(); label = gtk_label_new(guest->get_name(guest)); page->num = gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page->vte, label); gtk_widget_show(page->vte); pages->insert_last(pages, page); return page; }
void add_vte(){ struct v *temp = (struct v *)malloc(sizeof(struct v)); temp-> vte = vte_terminal_new(); vte_terminal_fork_command(VTE_TERMINAL(temp-> vte), "bash" , NULL, NULL, ".", FALSE, FALSE, FALSE); vte_terminal_set_size(VTE_TERMINAL(temp-> vte), 80, 5); gtk_box_pack_start (GTK_BOX (box_vte), temp-> vte, FALSE, TRUE, 5); gtk_widget_show (temp-> vte); set_data(temp); temp -> next = list -> next; (list -> next) -> prev = temp; list -> next = temp; temp -> prev = list; list = list -> next; c++; }
static void hotssh_tab_init (HotSshTab *self) { HotSshTabPrivate *priv = hotssh_tab_get_instance_private (self); priv->settings = g_settings_new ("org.gnome.hotssh"); gtk_widget_init_template (GTK_WIDGET (self)); gtk_notebook_set_show_tabs ((GtkNotebook*)self, FALSE); g_signal_connect (priv->create_and_connect_button, "clicked", G_CALLBACK (on_create_and_connect), self); g_signal_connect (priv->add_new_connection_button, "clicked", G_CALLBACK (on_add_new_connection), self); g_signal_connect (priv->connect_cancel_button, "clicked", G_CALLBACK (on_connect_cancel), self); g_signal_connect (priv->error_disconnect, "clicked", G_CALLBACK (on_connect_cancel), self); g_signal_connect (priv->auth_cancel_button, "clicked", G_CALLBACK (on_connect_cancel), self); g_signal_connect (priv->approve_hostkey_button, "clicked", G_CALLBACK (on_approve_hostkey_clicked), self); g_signal_connect (priv->disapprove_hostkey_button, "clicked", G_CALLBACK (on_connect_cancel), self); g_signal_connect_swapped (priv->password_entry, "activate", G_CALLBACK (submit_password), self); g_signal_connect_swapped (priv->password_submit, "clicked", G_CALLBACK (submit_password), self); g_signal_connect (priv->connections_treeview, "row-activated", G_CALLBACK (on_connection_row_activated), self); priv->password_interaction = hotssh_password_interaction_new ((GtkEntry*)priv->password_entry); priv->terminal = vte_terminal_new (); g_signal_connect (priv->terminal, "realize", G_CALLBACK (on_vte_realize), self); vte_terminal_set_audible_bell ((VteTerminal*)priv->terminal, FALSE); /* Audible bell is a terrible idea */ g_signal_connect ((GObject*)priv->terminal, "size-allocate", G_CALLBACK (on_terminal_size_allocate), self); g_signal_connect ((GObject*)priv->terminal, "commit", G_CALLBACK (on_terminal_commit), self); gtk_box_pack_start ((GtkBox*)priv->terminal_box, priv->terminal, TRUE, TRUE, 0); gtk_range_set_adjustment ((GtkRange*)priv->terminal_vscrollbar, gtk_scrollable_get_vadjustment ((GtkScrollable*)priv->terminal)); gtk_widget_show_all (priv->terminal_box); g_queue_init (&priv->write_queue); { gs_unref_object HotSshHostDB *hostdb = hotssh_hostdb_get_instance (); gs_unref_object GtkTreeModel *hostdb_model = hotssh_hostdb_get_model (hostdb); priv->host_completion = gtk_entry_completion_new (); gtk_entry_completion_set_match_func (priv->host_completion, host_entry_match, self, NULL); gtk_entry_completion_set_model (priv->host_completion, hostdb_model); gtk_entry_completion_set_text_column (priv->host_completion, 0); gtk_entry_completion_set_inline_completion (priv->host_completion, TRUE); gtk_entry_set_completion ((GtkEntry*)priv->host_entry, priv->host_completion); } }
int uart_init(int argc, char **argv) { lowmark=highmark=0; vte = vte_terminal_new(); gui_append_new_tab("UART",vte); //vte_terminal_set_pty(VTE_TERMINAL(vte), ptyslave); g_signal_connect(vte,"commit",(GCallback)&vte_uart_data,NULL); //poll_add(ptymaster, POLL_IN, &uart_incoming_data); socket_initialize(); return 0; }
GtkWidget* create_horst_window(void) { GtkWidget *horst_window, *horst_term; char *envs[2]; char *params[] = {horstpath}; envs[0] = strdup(environments); envs[1] = NULL; VtePtyFlags pty_flags = 0; GSpawnFlags spawn_flags = 0; char horst_title[24]; params[0] = strdup(horstpath); params[1] = strdup("-c"); params[2] = strdup("192.168.1.125"); params[3] = NULL; /* params[0] = strdup(horstpath); params[1] = strdup("-i"); params[2] = strdup(wificards[chan_detail]); params[3] = NULL; */ horst_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); sprintf(horst_title, "channel %d signal details", horst_chans[chan_detail]); gtk_window_set_title (GTK_WINDOW(horst_window), strdup(horst_title)); gtk_container_set_border_width(GTK_CONTAINER(horst_window), 0); horst_term = vte_terminal_new(); gtk_container_add(GTK_CONTAINER(horst_window), horst_term); vte_terminal_set_size(VTE_TERMINAL(horst_term), 100, 50); gtk_widget_show(horst_term); gtk_widget_set_visible (GTK_WIDGET(horst_term), TRUE); vte_terminal_fork_command_full (VTE_TERMINAL(horst_term), pty_flags, kislogdir , params, envs, spawn_flags, NULL, NULL, NULL, NULL); vte_terminal_set_scrollback_lines(VTE_TERMINAL(horst_term), 1024); gtk_widget_grab_focus(horst_term); g_signal_connect(G_OBJECT(horst_window), "destroy", G_CALLBACK(horst_delete), horst_window); return horst_window; }
gboolean term_new(gpointer data) { GtkWidget *term, *win; struct term_options *to = (struct term_options *)data; win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(win), to->title); gtk_window_set_wmclass(GTK_WINDOW(win), to->wm_name, to->wm_class); term = vte_terminal_new(); gtk_container_add(GTK_CONTAINER(win), term); if (!setup_term(win, term, to)) gtk_widget_destroy(win); if (to->argv != NULL) free(to->argv); free(to->message); free(to); /* Remove this source. */ return FALSE; }
static int window_create_show() { char *tmp; // window m_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); tmp = get_res_path(ICON_APP); gtk_window_set_icon_from_file(GTK_WINDOW(m_window), tmp, NULL); free(tmp); gtk_window_set_title(GTK_WINDOW(m_window), "jnXssh"); gtk_window_maximize(GTK_WINDOW(m_window)); gtk_widget_set_events(m_window, GDK_BUTTON_PRESS_MASK|GDK_KEY_PRESS_MASK); g_signal_connect(G_OBJECT(m_window), "key-press-event", G_CALLBACK(on_window_key_press), NULL); g_signal_connect(G_OBJECT(m_window), "destroy", G_CALLBACK (gtk_main_quit), NULL); // vbox GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER(m_window), vbox); // notebook GtkWidget *notebook = page_get_notebook(); gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0); // pty + vte GtkWidget *vte = vte_terminal_new(); gtk_box_pack_start(GTK_BOX(vbox), vte, FALSE, FALSE, 1); vte_terminal_set_size((VteTerminal*)vte, 1, 1); VtePty *pty = vte_pty_new(VTE_PTY_DEFAULT, NULL); vte_terminal_set_pty_object((VteTerminal*)vte, pty); pthread_t tid; pthread_create(&tid, NULL, proc_allvte, pty); gtk_widget_show_all(m_window); return 0; }
GtkWidget* build_term(void) { if (!popupmenu) build_popupmenu(); GtkWidget* term = vte_terminal_new(); vte_terminal_fork_command(VTE_TERMINAL(term), conf_get_shell(), NULL, NULL, "", TRUE, TRUE, TRUE); if (conf_get_bg_image() != NULL) vte_terminal_set_background_image_file(VTE_TERMINAL(term), conf_get_bg_image()); GdkColor fore, back; fore = conf_get_fg(); back = conf_get_bg(); GdkColor *palette = conf_get_color_palette(); if (palette == NULL) vte_terminal_set_colors(VTE_TERMINAL(term), &fore, &back, NULL, 0); else vte_terminal_set_colors(VTE_TERMINAL(term), &fore, &back, palette, 16); vte_terminal_set_background_tint_color(VTE_TERMINAL(term), &back); vte_terminal_set_allow_bold(VTE_TERMINAL(term), conf_get_allow_bold()); vte_terminal_set_scroll_on_output(VTE_TERMINAL(term), conf_get_scroll_on_output()); vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(term), TRUE); vte_terminal_set_font_from_string(VTE_TERMINAL(term), conf_get_font()); vte_terminal_set_scrollback_lines(VTE_TERMINAL(term), conf_get_lines()); vte_terminal_set_backspace_binding(VTE_TERMINAL(term), VTE_ERASE_ASCII_DELETE); vte_terminal_set_audible_bell (VTE_TERMINAL(term), conf_get_bell()); vte_terminal_set_cursor_blink_mode(VTE_TERMINAL(term), conf_get_cursor_blink()); vte_terminal_set_cursor_shape(VTE_TERMINAL(term), conf_get_cursor_shape()); term_connect_signals(term); return term; }
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); }
/* * init debug related GUI (watch tree view) * arguments: */ void debug_init() { /* create watch page */ wtree = wtree_init(on_watch_expanded_callback, on_watch_dragged_callback, on_watch_key_pressed_callback, on_watch_changed, on_watch_button_pressed_callback); wmodel = gtk_tree_view_get_model(GTK_TREE_VIEW(wtree)); wstore = GTK_TREE_STORE(wmodel); tab_watch = gtk_scrolled_window_new( gtk_tree_view_get_hadjustment(GTK_TREE_VIEW(wtree)), gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(wtree)) ); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tab_watch), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(tab_watch), wtree); /* create autos page */ atree = atree_init(on_watch_expanded_callback, on_watch_button_pressed_callback); tab_autos = gtk_scrolled_window_new( gtk_tree_view_get_hadjustment(GTK_TREE_VIEW(atree)), gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(atree)) ); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tab_autos), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(tab_autos), atree); /* create stack trace page */ stree = stree_init(editor_open_position, on_select_frame); tab_call_stack = gtk_scrolled_window_new( gtk_tree_view_get_hadjustment(GTK_TREE_VIEW(stree )), gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(stree )) ); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tab_call_stack), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(tab_call_stack), stree); /* create debug terminal page */ terminal = vte_terminal_new(); /* create PTY */ openpty(&pty_master, &pty_slave, NULL, NULL, NULL); grantpt(pty_master); unlockpt(pty_master); vte_terminal_set_pty(VTE_TERMINAL(terminal), pty_master); GtkWidget *scrollbar = gtk_vscrollbar_new(GTK_ADJUSTMENT(VTE_TERMINAL(terminal)->adjustment)); GTK_WIDGET_UNSET_FLAGS(scrollbar, GTK_CAN_FOCUS); tab_terminal = gtk_frame_new(NULL); gtk_frame_set_shadow_type (GTK_FRAME(tab_terminal), GTK_SHADOW_NONE); GtkWidget *hbox = gtk_hbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(tab_terminal), hbox); gtk_box_pack_start(GTK_BOX(hbox), terminal, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE, FALSE, 0); /* set the default widget size first to prevent VTE expanding too much, * sometimes causing the hscrollbar to be too big or out of view. */ gtk_widget_set_size_request(GTK_WIDGET(terminal), 10, 10); vte_terminal_set_size(VTE_TERMINAL(terminal), 30, 1); /* set terminal font. */ GKeyFile *config = g_key_file_new(); gchar *configfile = g_strconcat(geany_data->app->configdir, G_DIR_SEPARATOR_S, "geany.conf", NULL); g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); gchar *font = utils_get_setting_string(config, "VTE", "font", "Monospace 10"); vte_terminal_set_font_from_string (VTE_TERMINAL(terminal), font); /* debug messages page */ tab_messages = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tab_messages), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(tab_messages)); vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(tab_messages)); debugger_messages_textview = gtk_text_view_new(); gtk_text_view_set_editable (GTK_TEXT_VIEW (debugger_messages_textview), FALSE); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(tab_messages), debugger_messages_textview); /* create tex tags */ GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(debugger_messages_textview)); gtk_text_buffer_create_tag(buffer, "black", "foreground", "#000000", NULL); gtk_text_buffer_create_tag(buffer, "grey", "foreground", "#AAAAAA", NULL); gtk_text_buffer_create_tag(buffer, "red", "foreground", "#FF0000", NULL); gtk_text_buffer_create_tag(buffer, "green", "foreground", "#00FF00", NULL); gtk_text_buffer_create_tag(buffer, "blue", "foreground", "#0000FF", NULL); gtk_text_buffer_create_tag(buffer, "yellow", "foreground", "#FFFF00", NULL); gtk_text_buffer_create_tag(buffer, "brown", "foreground", "#BB8915", NULL); gtk_text_buffer_create_tag(buffer, "rose", "foreground", "#BA92B7", NULL); }
/* * Class: com_randomwalking_swt_terminal_internal_Vte * Method: vte_terminal_new * Signature: ()I */ JNIEXPORT jint JNICALL Java_com_randomwalking_swt_terminal_internal_Vte__1vte_1terminal_1new (JNIEnv * env, jclass obj) { return (jint)vte_terminal_new(); }
static void activate (GtkApplication* app, gpointer user_data) { GtkWidget *window; GtkWidget *bases, *keyLength, *errorBits, *errorTolerance, *playButton, *mode, *peerIp, *eveRate, *eveStrategy, *channelNoise, *genBias; GtkWidget *windowBox, *optionGrid, *playGrid, *playBox; GtkWidget *baseLabel, *keyLengthLabel, *errorBitsLabel, *errorToleranceLabel, *peerIpLabel, *eveRateLabel, *eveStrategyLabel, *channelNoiseLabel, *genBiasLabel; GtkWidget *tty1; GtkWidget *tty2; window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "Quantum Network Simulator"); gtk_window_set_default_size (GTK_WINDOW (window), 1280, 720); windowBox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL); gtk_container_add(GTK_CONTAINER(window), windowBox); playBox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); gtk_container_add(GTK_CONTAINER(windowBox), playBox); optionGrid = gtk_grid_new (); gtk_container_add(GTK_CONTAINER(playBox), optionGrid); playGrid = gtk_grid_new (); gtk_grid_set_column_spacing(GTK_GRID(playGrid), 20); gtk_container_add(GTK_CONTAINER(playBox), playGrid); mode = gtk_combo_box_text_new (); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(mode), "Superposition Tutorial"); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(mode), "Measurement Tutorial"); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(mode), "Classic BB84 Tutorial"); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(mode), "Polybase BB84 Tutorial"); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(mode), "Bias BB84 Tutorial"); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(mode), "Freestyle BB84"); gtk_grid_attach(GTK_GRID( optionGrid ), mode, 0, 0, 2, 1); baseLabel = gtk_label_new("Number of bases"); bases = gtk_entry_new (); gtk_grid_attach(GTK_GRID( optionGrid ), baseLabel , 0, 1, 1, 1); gtk_grid_attach(GTK_GRID( optionGrid ), bases , 1, 1, 1, 1); keyLengthLabel = gtk_label_new("Key Length"); keyLength = gtk_entry_new (); gtk_grid_attach(GTK_GRID( optionGrid ), keyLengthLabel , 0, 2, 1, 1); gtk_grid_attach(GTK_GRID( optionGrid ), keyLength, 1, 2, 1, 1); errorBitsLabel = gtk_label_new("Number of error detection bits"); errorBits = gtk_entry_new (); gtk_grid_attach(GTK_GRID( optionGrid ), errorBitsLabel , 0, 3, 1, 1); gtk_grid_attach(GTK_GRID( optionGrid ), errorBits , 1, 3, 1, 1); errorToleranceLabel = gtk_label_new("Number of error bits to tolerate"); errorTolerance = gtk_entry_new (); gtk_grid_attach(GTK_GRID( optionGrid ), errorToleranceLabel , 0, 4, 1, 1); gtk_grid_attach(GTK_GRID( optionGrid ), errorTolerance , 1, 4, 1, 1); errorToleranceLabel = gtk_label_new("Peer IP"); errorTolerance = gtk_entry_new (); gtk_grid_attach(GTK_GRID( optionGrid ), errorToleranceLabel , 2, 0, 1, 1); gtk_grid_attach(GTK_GRID( optionGrid ), errorTolerance , 3, 0, 1, 1); errorToleranceLabel = gtk_label_new("Eve Eavesdrop Rate"); errorTolerance = gtk_entry_new (); gtk_grid_attach(GTK_GRID( optionGrid ), errorToleranceLabel , 2, 1, 1, 1); gtk_grid_attach(GTK_GRID( optionGrid ), errorTolerance , 3, 1, 1, 1); errorToleranceLabel = gtk_label_new("Eve Eavesdrop Strategy"); errorTolerance = gtk_entry_new (); gtk_grid_attach(GTK_GRID( optionGrid ), errorToleranceLabel , 2, 2, 1, 1); gtk_grid_attach(GTK_GRID( optionGrid ), errorTolerance , 3, 2, 1, 1); errorToleranceLabel = gtk_label_new("Generator Bias"); errorTolerance = gtk_entry_new (); gtk_grid_attach(GTK_GRID( optionGrid ), errorToleranceLabel , 2, 3, 1, 1); gtk_grid_attach(GTK_GRID( optionGrid ), errorTolerance , 3, 3, 1, 1); errorToleranceLabel = gtk_label_new("Channel Noise"); errorTolerance = gtk_entry_new (); gtk_grid_attach(GTK_GRID( optionGrid ), errorToleranceLabel , 2, 4, 1, 1); gtk_grid_attach(GTK_GRID( optionGrid ), errorTolerance , 3, 4, 1, 1); playButton = gtk_button_new_with_label("PLAY QUANTUM ALGORITHM"); g_signal_connect (playButton, "clicked", G_CALLBACK(playAlgorithm), playButton); // g_signal_connect_swapped (playButton, "clicked", G_CALLBACK(gtk_widget_destroy), window); gtk_grid_attach(GTK_GRID( optionGrid ), playButton, 0, 5, 4, 1); char *startTerm[2] = {0,0}; startTerm[0] = vte_get_user_shell(); GPid pidTerm; tty1 = vte_terminal_new(); vte_terminal_fork_command_full(VTE_TERMINAL(tty1), VTE_PTY_DEFAULT, NULL, //"/tmp", startTerm, NULL, (GSpawnFlags)(G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH), NULL, NULL, NULL, NULL ); gtk_widget_set_size_request(tty1, 600, 400); gtk_grid_attach(GTK_GRID (playGrid ), tty1, 0, 6, 4, 15); gtk_widget_set_sensitive(tty1, FALSE); tty2 = vte_terminal_new(); vte_terminal_fork_command_full(VTE_TERMINAL(tty2), VTE_PTY_DEFAULT, NULL, //"/tmp", startTerm, NULL, (GSpawnFlags)(G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH), NULL, NULL, NULL, NULL ); gtk_widget_set_size_request(tty2, 600, 400); gtk_grid_attach(GTK_GRID (playGrid ), tty2, 4, 6, 4, 15); gtk_widget_set_sensitive(tty2, FALSE); g_object_set_data(G_OBJECT(playButton), "tty1", VTE_TERMINAL(tty1)); g_object_set_data(G_OBJECT(playButton), "tty2", VTE_TERMINAL(tty2)); g_object_set_data(G_OBJECT(playButton), "in_mode", GTK_COMBO_BOX_TEXT(mode)); g_object_set_data(G_OBJECT(playButton), "in_bases", GTK_ENTRY(bases)); g_object_set_data(G_OBJECT(playButton), "in_keyLength", GTK_ENTRY(keyLength)); g_object_set_data(G_OBJECT(playButton), "in_errorBits", GTK_ENTRY(errorBits)); g_object_set_data(G_OBJECT(playButton), "in_errorTolerance", GTK_ENTRY(errorTolerance)); gtk_widget_show_all (window); }
static GtkWidget* create_new_window (GtkApplication *application, GVariantDict *options) { dg_lmem gchar* command = NULL; dg_lmem gchar* title = NULL; gboolean opt_show_title; gboolean opt_update_title; gboolean opt_no_headerbar; g_object_get (dwt_settings_get_instance (), "show-title", &opt_show_title, "update-title", &opt_update_title, "no-header-bar", &opt_no_headerbar, "command", &command, "title", &title, NULL); const gchar *opt_command = command; const gchar *opt_title = title; const gchar *opt_workdir = NULL; if (options) { gboolean opt_no_auto_title = FALSE; g_variant_dict_lookup (options, "title-on-maximize", "b", &opt_show_title); g_variant_dict_lookup (options, "no-header-bar", "b", &opt_no_headerbar); g_variant_dict_lookup (options, "no-auto-title", "b", &opt_no_auto_title); g_variant_dict_lookup (options, "workdir", "&s", &opt_workdir); g_variant_dict_lookup (options, "command", "&s", &opt_command); g_variant_dict_lookup (options, "title", "&s", &opt_title); if (opt_no_auto_title) opt_update_title = FALSE; } if (!opt_workdir) opt_workdir = g_get_home_dir (); if (!opt_command) opt_command = guess_shell (); /* * Title either comes from the default value of the "title" setting, * or from the command line flag, but should never be NULL at this * point. */ g_assert (opt_title); dg_lerr GError *gerror = NULL; gint command_argv_len = 0; gchar **command_argv = NULL; if (!g_shell_parse_argv (opt_command, &command_argv_len, &command_argv, &gerror)) { g_printerr ("%s: coult not parse command: %s\n", __func__, gerror->message); return NULL; } GtkWidget *window = gtk_application_window_new (application); gtk_widget_set_visual (window, gdk_screen_get_system_visual (gtk_widget_get_screen (window))); gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), FALSE); gtk_window_set_title (GTK_WINDOW (window), opt_title); gtk_window_set_hide_titlebar_when_maximized (GTK_WINDOW (window), !opt_show_title); g_action_map_add_action_entries (G_ACTION_MAP (window), win_actions, G_N_ELEMENTS (win_actions), window); VteTerminal *vtterm = VTE_TERMINAL (vte_terminal_new ()); configure_term_widget (vtterm, options); term_char_size_changed (vtterm, vte_terminal_get_char_width (vtterm), vte_terminal_get_char_height (vtterm), window); g_signal_connect (G_OBJECT (window), "notify::has-toplevel-focus", G_CALLBACK (window_has_toplevel_focus_notified), vtterm); g_signal_connect (G_OBJECT (vtterm), "char-size-changed", G_CALLBACK (term_char_size_changed), window); g_signal_connect (G_OBJECT (vtterm), "child-exited", G_CALLBACK (term_child_exited), window); g_signal_connect (G_OBJECT (vtterm), "bell", G_CALLBACK (term_beeped), window); g_signal_connect (G_OBJECT (vtterm), "button-release-event", G_CALLBACK (term_mouse_button_released), setup_popover (vtterm)); /* * Propagate title changes to the window. */ if (opt_update_title) g_object_bind_property (G_OBJECT (vtterm), "window-title", G_OBJECT (window), "title", G_BINDING_DEFAULT); if (!opt_no_headerbar) setup_header_bar (window, vtterm, opt_show_title); gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vtterm)); gtk_widget_set_receives_default (GTK_WIDGET (vtterm), TRUE); /* We need to realize and show the window for it to have a valid XID */ gtk_widget_show_all (window); gchar **command_env = g_get_environ (); #ifdef GDK_WINDOWING_X11 if (GDK_IS_X11_SCREEN (gtk_widget_get_screen (window))) { GdkWindow *gdk_window = gtk_widget_get_window (window); if (gdk_window) { gchar window_id[NDIGITS10(unsigned long)]; snprintf (window_id, sizeof (window_id), "%lu", GDK_WINDOW_XID (gdk_window)); command_env = g_environ_setenv (command_env, "WINDOWID", window_id, TRUE); } else { g_printerr ("No window, cannot set $WINDOWID!\n"); } }
int main (int argc, char *argv[]) { GtkWidget *window, *terminal, *scrollbar, *design; GError *icon_error = NULL; GdkPixbuf *icon; GdkGeometry geo_hints; /* Init gtk and all widgets */ gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); terminal = vte_terminal_new (); scrollbar = gtk_vscrollbar_new (VTE_TERMINAL (terminal)->adjustment); design = gtk_hbox_new (FALSE, 0); /* Set window icon */ icon = gdk_pixbuf_new_from_file (TINYTERM_ICON_PATH, &icon_error); if (!icon) { fprintf (stderr, "%s\n", icon_error->message); g_error_free (icon_error); } gtk_window_set_icon (GTK_WINDOW (window), icon); /* Set window title */ gtk_window_set_title (GTK_WINDOW (window), "TinyTerm"); /* Set scrollback lines */ vte_terminal_set_scrollback_lines (VTE_TERMINAL (terminal), TINYTERM_SCROLLBACK_LINES); /* Apply geometry hints to handle terminal resizing */ geo_hints.base_width = VTE_TERMINAL (terminal)->char_width; geo_hints.base_height = VTE_TERMINAL (terminal)->char_height; geo_hints.min_width = VTE_TERMINAL (terminal)->char_width; geo_hints.min_height = VTE_TERMINAL (terminal)->char_height; geo_hints.width_inc = VTE_TERMINAL (terminal)->char_width; geo_hints.height_inc = VTE_TERMINAL (terminal)->char_height; gtk_window_set_geometry_hints (GTK_WINDOW (window), terminal, &geo_hints, GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); /* Open a standard shell */ vte_terminal_fork_command (VTE_TERMINAL (terminal), NULL, // binary to run (NULL=user's shell) NULL, // arguments NULL, // environment NULL, // dir to start (NULL=CWD) TRUE, // log session to lastlog TRUE, // log session to utmp/utmpx log TRUE); // log session to wtmp/wtmpx log /* Connect signals */ g_signal_connect (window, "delete-event", gtk_main_quit, NULL); g_signal_connect (terminal, "child-exited", gtk_main_quit, NULL); g_signal_connect (terminal, "key-press-event", G_CALLBACK (on_key_press), NULL); /* Set selection behavior for double-clicks */ vte_terminal_set_word_chars (VTE_TERMINAL (terminal), TINYTERM_WORD_CHARS); /* Put all widgets together and show the result */ gtk_box_pack_start (GTK_BOX (design), terminal, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (design), scrollbar, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (window), design); gtk_widget_show_all (window); gtk_main (); return 0; }
void new_window(GtkApplication *app, gchar **argv, gint argc) { GtkWidget* window; GtkWidget* box; GdkPixbuf* icon; GdkGeometry geo_hints; GtkIconTheme* icon_theme; GError* error = NULL; /* Variables for parsed command-line arguments */ char* command = NULL; char* directory = NULL; gboolean keep = FALSE; char* name = NULL; char* title = NULL; parse_arguments(argc, argv, &command, &directory, &keep, &name, &title); /* Create window */ window = gtk_application_window_new(GTK_APPLICATION(app)); g_signal_connect(window, "delete-event", G_CALLBACK(window_close), app); gtk_window_set_wmclass(GTK_WINDOW (window), name ? name : "tinyterm", "TinyTerm"); gtk_window_set_title(GTK_WINDOW (window), title ? title : "TinyTerm"); /* Set window icon supplied by an icon theme */ icon_theme = gtk_icon_theme_get_default(); icon = gtk_icon_theme_load_icon(icon_theme, "terminal", 48, 0, &error); if (error) g_error_free(error); if (icon) gtk_window_set_icon(GTK_WINDOW (window), icon); /* Create main box */ box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_container_add(GTK_CONTAINER (window), box); /* Create vte terminal widget */ GtkWidget* vte_widget = vte_terminal_new(); gtk_box_pack_start(GTK_BOX (box), vte_widget, TRUE, TRUE, 0); VteTerminal* vte = VTE_TERMINAL (vte_widget); if (!keep) g_signal_connect(vte, "child-exited", G_CALLBACK (vte_exit_cb), window); g_signal_connect(vte, "key-press-event", G_CALLBACK (key_press_cb), NULL); #ifdef TINYTERM_URGENT_ON_BELL g_signal_connect(vte, "bell", G_CALLBACK (window_urgency_hint_cb), NULL); g_signal_connect(window, "focus-in-event", G_CALLBACK (window_focus_cb), NULL); g_signal_connect(window, "focus-out-event", G_CALLBACK (window_focus_cb), NULL); #endif // TINYTERM_URGENT_ON_BELL #ifdef TINYTERM_DYNAMIC_WINDOW_TITLE if (!title) g_signal_connect(vte, "window-title-changed", G_CALLBACK (window_title_cb), NULL); #endif // TINYTERM_DYNAMIC_WINDOW_TITLE /* Apply geometry hints to handle terminal resizing */ geo_hints.base_width = vte_terminal_get_char_width(vte); geo_hints.base_height = vte_terminal_get_char_height(vte); geo_hints.min_width = vte_terminal_get_char_width(vte); geo_hints.min_height = vte_terminal_get_char_height(vte); geo_hints.width_inc = vte_terminal_get_char_width(vte); geo_hints.height_inc = vte_terminal_get_char_height(vte); gtk_window_set_geometry_hints(GTK_WINDOW (window), vte_widget, &geo_hints, GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); vte_config(vte); vte_spawn(vte, directory, command, NULL); /* cleanup */ g_free(command); g_free(directory); g_free(name); g_free(title); /* Show widgets and run main loop */ gtk_widget_show_all(window); }
console_t *uimon_window_open(void) { GtkWidget *scrollbar, *horizontal_container; GdkGeometry hints; if (fixed.window == NULL) { fixed.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(fixed.window), "VICE monitor"); gtk_window_set_position(GTK_WINDOW(fixed.window), GTK_WIN_POS_CENTER); gtk_widget_set_app_paintable(fixed.window, TRUE); gtk_window_set_deletable(GTK_WINDOW(fixed.window), TRUE); fixed.term = vte_terminal_new(); vte_terminal_set_scrollback_lines (VTE_TERMINAL(fixed.term), 1000); vte_terminal_set_scroll_on_output (VTE_TERMINAL(fixed.term), TRUE); /* allowed window widths are base_width + width_inc * N * allowed window heights are base_height + height_inc * N */ hints.width_inc = vte_terminal_get_char_width (VTE_TERMINAL(fixed.term)); hints.height_inc = vte_terminal_get_char_height (VTE_TERMINAL(fixed.term)); /* min size should be multiple of .._inc, else we get funky effects */ hints.min_width = hints.width_inc; hints.min_height = hints.height_inc; /* base size should be multiple of .._inc, else we get funky effects */ hints.base_width = hints.width_inc; hints.base_height = hints.height_inc; gtk_window_set_geometry_hints (GTK_WINDOW (fixed.window), fixed.term, &hints, GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); #if GTK_CHECK_VERSION (2, 91, 1) { glong width, height; get_terminal_size_in_chars(VTE_TERMINAL(fixed.term), &width, &height); gtk_window_resize_to_geometry (GTK_WINDOW (fixed.window), width, height); } #endif scrollbar = gtk_vscrollbar_new(vte_terminal_get_adjustment (VTE_TERMINAL(fixed.term))); horizontal_container = gtk_hbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(fixed.window), horizontal_container); gtk_container_add(GTK_CONTAINER(horizontal_container), fixed.term); gtk_container_add(GTK_CONTAINER(horizontal_container), scrollbar); g_signal_connect(G_OBJECT(fixed.window), "delete-event", G_CALLBACK(close_window), &fixed.input_buffer); g_signal_connect(G_OBJECT(fixed.term), "key-press-event", G_CALLBACK(key_press_event), &fixed.input_buffer); g_signal_connect(G_OBJECT(fixed.term), "button-press-event", G_CALLBACK(button_press_event), &fixed.input_buffer); g_signal_connect (fixed.term, "text-modified", G_CALLBACK (screen_resize_window_cb), NULL); vte_console.console_can_stay_open = 1; } return uimon_window_resume(); }
static VALUE rg_initialize(VALUE self) { RBGTK_INITIALIZE(self, vte_terminal_new()); return Qnil; }
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; }
int main(int argc, char **argv) { GdkScreen *screen; GdkColormap *colormap; GtkWidget *window, *widget,*hbox = NULL, *scrollbar, *scrolled_window = NULL; VteTerminal *terminal; char *env_add[] = { #ifdef VTE_DEBUG (char *) "FOO=BAR", (char *) "BOO=BIZ", #endif NULL}; const char *background = NULL; gboolean transparent = FALSE, audible = TRUE, blink = TRUE, debug = FALSE, dingus = FALSE, dbuffer = TRUE, console = FALSE, scroll = FALSE, keep = FALSE, icon_title = FALSE, shell = TRUE, highlight_set = FALSE, cursor_set = FALSE, reverse = FALSE, use_geometry_hints = TRUE, antialias = TRUE, use_scrolled_window = FALSE, show_object_notifications = FALSE; char *geometry = NULL; gint lines = 100; const char *message = "Launching interactive shell...\r\n"; const char *font = NULL; const char *termcap = NULL; const char *command = NULL; const char *working_directory = NULL; const char *output_file = NULL; char *pty_flags_string = NULL; char *cursor_shape_string = NULL; char *scrollbar_policy_string = NULL; GdkColor fore, back, tint, highlight, cursor; const GOptionEntry options[]={ { "antialias", 'A', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &antialias, "Disable the use of anti-aliasing", NULL }, { "background", 'B', 0, G_OPTION_ARG_FILENAME, &background, "Specify a background image", NULL }, { "console", 'C', 0, G_OPTION_ARG_NONE, &console, "Watch /dev/console", NULL }, { "dingus", 'D', 0, G_OPTION_ARG_NONE, &dingus, "Highlight URLs inside the terminal", NULL }, { "shell", 'S', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &shell, "Disable spawning a shell inside the terminal", NULL }, { "transparent", 'T', 0, G_OPTION_ARG_NONE, &transparent, "Enable the use of a transparent background", NULL }, { "double-buffer", '2', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &dbuffer, "Disable double-buffering", NULL }, { "audible", 'a', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &audible, "Use visible, instead of audible, terminal bell", NULL }, { "blink", 'b', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &blink, "Disable the blinking cursor", NULL }, { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "Execute a command in the terminal", NULL }, { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "Enable various debugging checks", NULL }, { "font", 'f', 0, G_OPTION_ARG_STRING, &font, "Specify a font to use", NULL }, { "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry, "Set the size (in characters) and position", "GEOMETRY" }, { "highlight", 'h', 0, G_OPTION_ARG_NONE, &highlight_set, "Enable the cursor highlighting", NULL }, { "icon-title", 'i', 0, G_OPTION_ARG_NONE, &icon_title, "Enable the setting of the icon title", NULL }, { "keep", 'k', 0, G_OPTION_ARG_NONE, &keep, "Live on after the window closes", NULL }, { "scrollback-lines", 'n', 0, G_OPTION_ARG_INT, &lines, "Specify the number of scrollback-lines", NULL }, { "color-cursor", 'r', 0, G_OPTION_ARG_NONE, &cursor_set, "Enable a colored cursor", NULL }, { "cursor-shape", 0, 0, G_OPTION_ARG_STRING, &cursor_shape_string, "Set cursor shape (block|underline|ibeam)", NULL }, { "scroll-background", 's', 0, G_OPTION_ARG_NONE, &scroll, "Enable a scrolling background", NULL }, { "termcap", 't', 0, G_OPTION_ARG_STRING, &termcap, "Specify the terminal emulation to use", NULL }, { "working-directory", 'w', 0, G_OPTION_ARG_FILENAME, &working_directory, "Specify the initial working directory of the terminal", NULL }, { "reverse", 0, 0, G_OPTION_ARG_NONE, &reverse, "Reverse foreground/background colors", NULL }, { "no-geometry-hints", 'G', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &use_geometry_hints, "Allow the terminal to be resized to any dimension, not constrained to fit to an integer multiple of characters", NULL }, { "scrolled-window", 'W', 0, G_OPTION_ARG_NONE, &use_scrolled_window, "Use a GtkScrolledWindow as terminal container", NULL }, { "scrollbar-policy", 'P', 0, G_OPTION_ARG_STRING, &scrollbar_policy_string, "Set the policy for the vertical scroolbar in the scrolled window (always|auto|never; default:always)", NULL }, { "object-notifications", 'N', 0, G_OPTION_ARG_NONE, &show_object_notifications, "Print VteTerminal object notifications", NULL }, { "output-file", 0, 0, G_OPTION_ARG_STRING, &output_file, "Save terminal contents to file at exit", NULL }, { "pty-flags", 0, 0, G_OPTION_ARG_STRING, &pty_flags_string, "PTY flags set from default|no-utmp|no-wtmp|no-lastlog|no-helper|no-fallback", NULL }, { NULL } }; GOptionContext *context; GError *error = NULL; VteTerminalCursorShape cursor_shape = VTE_CURSOR_SHAPE_BLOCK; GtkPolicyType scrollbar_policy = GTK_POLICY_ALWAYS; VtePtyFlags pty_flags = VTE_PTY_DEFAULT; /* Have to do this early. */ if (getenv("VTE_PROFILE_MEMORY")) { if (atol(getenv("VTE_PROFILE_MEMORY")) != 0) { g_mem_set_vtable(glib_mem_profiler_table); } } context = g_option_context_new (" - test VTE terminal emulation"); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error != NULL) { g_printerr ("Failed to parse command line arguments: %s\n", error->message); g_error_free (error); return 1; } if (cursor_shape_string) { cursor_shape = parse_enum(VTE_TYPE_TERMINAL_CURSOR_SHAPE, cursor_shape_string); g_free(cursor_shape_string); } if (scrollbar_policy_string) { scrollbar_policy = parse_enum(GTK_TYPE_POLICY_TYPE, scrollbar_policy_string); g_free(scrollbar_policy_string); } if (pty_flags_string) { pty_flags |= parse_flags(VTE_TYPE_PTY_FLAGS, pty_flags_string); g_free(pty_flags_string); } if (!reverse) { back.red = back.green = back.blue = 0xffff; fore.red = fore.green = fore.blue = 0x0000; } else { back.red = back.green = back.blue = 0x0000; fore.red = fore.green = fore.blue = 0xffff; } highlight.red = highlight.green = highlight.blue = 0xc000; cursor.red = 0xffff; cursor.green = cursor.blue = 0x8000; tint.red = tint.green = tint.blue = 0; tint = back; gdk_window_set_debug_updates(debug); /* Create a window to hold the scrolling shell, and hook its * delete event to the quit function.. */ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_container_set_resize_mode(GTK_CONTAINER(window), GTK_RESIZE_IMMEDIATE); /* Set ARGB colormap */ screen = gtk_widget_get_screen (window); colormap = gdk_screen_get_rgba_colormap (screen); if (colormap) gtk_widget_set_colormap(window, colormap); if (use_scrolled_window) { scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_NEVER, scrollbar_policy); gtk_container_add(GTK_CONTAINER(window), scrolled_window); } else { /* Create a box to hold everything. */ hbox = gtk_hbox_new(0, FALSE); gtk_container_add(GTK_CONTAINER(window), hbox); } /* Create the terminal widget and add it to the scrolling shell. */ widget = vte_terminal_new(); terminal = VTE_TERMINAL (widget); if (!dbuffer) { gtk_widget_set_double_buffered(widget, dbuffer); } g_signal_connect(terminal, "child-exited", G_CALLBACK(child_exit_cb), NULL); if (show_object_notifications) g_signal_connect(terminal, "notify", G_CALLBACK(terminal_notify_cb), NULL); if (use_scrolled_window) { gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(terminal)); } else { gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0); } /* Connect to the "char_size_changed" signal to set geometry hints * whenever the font used by the terminal is changed. */ if (use_geometry_hints) { char_size_changed(widget, 0, 0, window); g_signal_connect(widget, "char-size-changed", G_CALLBACK(char_size_changed), window); g_signal_connect(widget, "realize", G_CALLBACK(char_size_realized), window); } /* Connect to the "window_title_changed" signal to set the main * window's title. */ g_signal_connect(widget, "window-title-changed", G_CALLBACK(window_title_changed), window); if (icon_title) { g_signal_connect(widget, "icon-title-changed", G_CALLBACK(icon_title_changed), window); } /* Connect to the "status-line-changed" signal. */ g_signal_connect(widget, "status-line-changed", G_CALLBACK(status_line_changed), widget); /* Connect to the "button-press" event. */ g_signal_connect(widget, "button-press-event", G_CALLBACK(button_pressed), widget); /* Connect to application request signals. */ g_signal_connect(widget, "iconify-window", G_CALLBACK(iconify_window), window); g_signal_connect(widget, "deiconify-window", G_CALLBACK(deiconify_window), window); g_signal_connect(widget, "raise-window", G_CALLBACK(raise_window), window); g_signal_connect(widget, "lower-window", G_CALLBACK(lower_window), window); g_signal_connect(widget, "maximize-window", G_CALLBACK(maximize_window), window); g_signal_connect(widget, "restore-window", G_CALLBACK(restore_window), window); g_signal_connect(widget, "refresh-window", G_CALLBACK(refresh_window), window); g_signal_connect(widget, "resize-window", G_CALLBACK(resize_window), window); g_signal_connect(widget, "move-window", G_CALLBACK(move_window), window); /* Connect to font tweakage. */ g_signal_connect(widget, "increase-font-size", G_CALLBACK(increase_font_size), window); g_signal_connect(widget, "decrease-font-size", G_CALLBACK(decrease_font_size), window); if (!use_scrolled_window) { /* Create the scrollbar for the widget. */ scrollbar = gtk_vscrollbar_new(terminal->adjustment); gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE, FALSE, 0); } /* Set some defaults. */ vte_terminal_set_audible_bell(terminal, audible); vte_terminal_set_visible_bell(terminal, !audible); vte_terminal_set_cursor_blink_mode(terminal, blink ? VTE_CURSOR_BLINK_SYSTEM : VTE_CURSOR_BLINK_OFF); vte_terminal_set_scroll_background(terminal, scroll); vte_terminal_set_scroll_on_output(terminal, FALSE); vte_terminal_set_scroll_on_keystroke(terminal, TRUE); vte_terminal_set_scrollback_lines(terminal, lines); vte_terminal_set_mouse_autohide(terminal, TRUE); if (background != NULL) { vte_terminal_set_background_image_file(terminal, background); } if (transparent) { vte_terminal_set_background_transparent(terminal, TRUE); } vte_terminal_set_background_tint_color(terminal, &tint); vte_terminal_set_colors(terminal, &fore, &back, NULL, 0); vte_terminal_set_opacity(terminal, 0xdddd); if (highlight_set) { vte_terminal_set_color_highlight(terminal, &highlight); } if (cursor_set) { vte_terminal_set_color_cursor(terminal, &cursor); } if (termcap != NULL) { vte_terminal_set_emulation(terminal, termcap); } vte_terminal_set_cursor_shape(terminal, cursor_shape); /* Set the default font. */ vte_terminal_set_font_from_string_full(terminal, font, antialias ? VTE_ANTI_ALIAS_USE_DEFAULT : VTE_ANTI_ALIAS_FORCE_DISABLE); /* Match "abcdefg". */ if (dingus) { int id; GRegex *regex; regex = g_regex_new (DINGUS1, 0, 0, NULL); id = vte_terminal_match_add_gregex(terminal, regex, 0); g_regex_unref (regex); vte_terminal_match_set_cursor_type(terminal, id, GDK_GUMBY); regex = g_regex_new (DINGUS2, 0, 0, NULL); id = vte_terminal_match_add_gregex(terminal, regex, 0); g_regex_unref (regex); vte_terminal_match_set_cursor_type(terminal, id, GDK_HAND1); } if (console) { /* Open a "console" connection. */ int consolefd = -1, yes = 1, watch; GIOChannel *channel; consolefd = open("/dev/console", O_RDONLY | O_NOCTTY); if (consolefd != -1) { /* Assume failure. */ console = FALSE; #ifdef TIOCCONS if (ioctl(consolefd, TIOCCONS, &yes) != -1) { /* Set up a listener. */ channel = g_io_channel_unix_new(consolefd); watch = g_io_add_watch(channel, G_IO_IN, read_and_feed, widget); g_signal_connect(widget, "eof", G_CALLBACK(disconnect_watch), GINT_TO_POINTER(watch)); g_signal_connect(widget, "child-exited", G_CALLBACK(disconnect_watch), GINT_TO_POINTER(watch)); g_signal_connect(widget, "realize", G_CALLBACK(take_xconsole_ownership), NULL); #ifdef VTE_DEBUG vte_terminal_feed(terminal, "Console log for ...\r\n", -1); #endif /* Record success. */ console = TRUE; } #endif } else { /* Bail back to normal mode. */ g_warning(_("Could not open console.\n")); close(consolefd); console = FALSE; } } if (!console) { if (shell) { GError *err = NULL; char **command_argv = NULL; int command_argc; GPid pid = -1; _VTE_DEBUG_IF(VTE_DEBUG_MISC) vte_terminal_feed(terminal, message, -1); if (command == NULL) command = "/bin/sh"; // FIXMEchpe if (command != NULL) { if (!g_shell_parse_argv(command, &command_argc, &command_argv, &err) || !vte_terminal_fork_command_full(terminal, pty_flags, NULL, command_argv, env_add, G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &err)) { g_warning("Failed to fork: %s\n", err->message); g_error_free(err); } else { g_print("Fork succeeded, PID %d\n", pid); } } g_strfreev(command_argv); #ifdef VTE_DEBUG if (command == NULL) { vte_terminal_feed_child(terminal, "pwd\n", -1); } #endif } else { long i; i = vte_terminal_forkpty(terminal, env_add, working_directory, TRUE, TRUE, TRUE); switch (i) { case -1: /* abnormal */ g_warning("Error in vte_terminal_forkpty(): %s", strerror(errno)); break; case 0: /* child */ for (i = 0; ; i++) { switch (i % 3) { case 0: case 1: g_print("%ld\n", i); break; case 2: g_printerr("%ld\n", i); break; } sleep(1); } _exit(0); break; default: g_print("Child PID is %ld (mine is %ld).\n", (long) i, (long) getpid()); /* normal */ break; } } } g_object_set_data (G_OBJECT (widget), "output_file", (gpointer) output_file); /* Go for it! */ g_signal_connect(widget, "child-exited", G_CALLBACK(child_exited), window); g_signal_connect(window, "delete-event", G_CALLBACK(delete_event), widget); add_weak_pointer(G_OBJECT(widget), &widget); add_weak_pointer(G_OBJECT(window), &window); gtk_widget_realize(widget); if (geometry) { if (!gtk_window_parse_geometry (GTK_WINDOW(window), geometry)) { g_warning (_("Could not parse the geometry spec passed to --geometry")); } } gtk_widget_show_all(window); gtk_main(); g_assert(widget == NULL); g_assert(window == NULL); if (keep) { while (TRUE) { sleep(60); } } return 0; }
void termit_append_tab_with_details(const struct TabInfo* ti) { struct TermitTab* pTab = g_malloc0(sizeof(struct TermitTab)); termit_style_copy(&pTab->style, &configs.style); if (ti->name) { pTab->tab_name = gtk_label_new(ti->name); pTab->custom_tab_name = TRUE; } else { gchar* label_text = g_strdup_printf("%s %d", configs.default_tab_name, termit.tab_max_number++); pTab->tab_name = gtk_label_new(label_text); g_free(label_text); pTab->custom_tab_name = FALSE; } pTab->encoding = (ti->encoding) ? g_strdup(ti->encoding) : g_strdup(configs.default_encoding); pTab->bksp_binding = ti->bksp_binding; pTab->delete_binding = ti->delete_binding; pTab->hbox = gtk_hbox_new(FALSE, 0); pTab->vte = vte_terminal_new(); vte_terminal_set_scrollback_lines(VTE_TERMINAL(pTab->vte), configs.scrollback_lines); if (configs.default_word_chars) vte_terminal_set_word_chars(VTE_TERMINAL(pTab->vte), configs.default_word_chars); vte_terminal_set_mouse_autohide(VTE_TERMINAL(pTab->vte), TRUE); vte_terminal_set_backspace_binding(VTE_TERMINAL(pTab->vte), pTab->bksp_binding); vte_terminal_set_delete_binding(VTE_TERMINAL(pTab->vte), pTab->delete_binding); #ifdef TERMIT_ENABLE_SEARCH vte_terminal_search_set_wrap_around(VTE_TERMINAL(pTab->vte), TRUE); #endif // TERMIT_ENABLE_SEARCH /* parse command */ gchar **cmd_argv; GError *cmd_err = NULL; gchar *cmd_path = NULL; gchar *cmd_file = NULL; pTab->command = (ti->command) ? g_strdup(ti->command) : g_strdup(configs.default_command); if (!g_shell_parse_argv(pTab->command, NULL, &cmd_argv, &cmd_err)) { ERROR("%s", _("Cannot parse command. Creating tab with shell")); g_error_free(cmd_err); } else { cmd_path = g_find_program_in_path(cmd_argv[0]); cmd_file = g_path_get_basename(cmd_argv[0]); } TRACE("command=%s cmd_path=%s cmd_file=%s", pTab->command, cmd_path, cmd_file); if (cmd_path && cmd_file) { g_free(cmd_argv[0]); cmd_argv[0] = g_strdup(cmd_path); #if VTE_CHECK_VERSION(0, 26, 0) > 0 if (vte_terminal_fork_command_full(VTE_TERMINAL(pTab->vte), VTE_PTY_DEFAULT, ti->working_dir, cmd_argv, NULL, 0, NULL, NULL, &pTab->pid, &cmd_err) != TRUE) { ERROR("failed to open tab: %s", cmd_err->message); g_error_free(cmd_err); } #else pTab->pid = vte_terminal_fork_command(VTE_TERMINAL(pTab->vte), cmd_path, cmd_argv, NULL, ti->working_dir, TRUE, TRUE, TRUE); #endif // version >= 0.26 } else { g_free(pTab->command); pTab->command = g_strdup(configs.default_command); gchar* argv[] = {pTab->command, NULL}; TRACE("defaults: cmd=%s working_dir=%s", pTab->command, ti->working_dir); /* default tab */ #if VTE_CHECK_VERSION(0, 26, 0) > 0 if (vte_terminal_fork_command_full(VTE_TERMINAL(pTab->vte), VTE_PTY_DEFAULT, ti->working_dir, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &pTab->pid, &cmd_err) != TRUE) { ERROR("failed to open tab: %s", cmd_err->message); g_error_free(cmd_err); } #else pTab->pid = vte_terminal_fork_command(VTE_TERMINAL(pTab->vte), pTab->command, NULL, NULL, ti->working_dir, TRUE, TRUE, TRUE); #endif // version >= 0.26 } g_strfreev(cmd_argv); g_free(cmd_path); g_free(cmd_file); g_signal_connect(G_OBJECT(pTab->vte), "beep", G_CALLBACK(termit_on_beep), pTab); g_signal_connect(G_OBJECT(pTab->vte), "focus-in-event", G_CALLBACK(termit_on_focus), pTab); g_signal_connect(G_OBJECT(pTab->vte), "window-title-changed", G_CALLBACK(termit_on_tab_title_changed), NULL); g_signal_connect(G_OBJECT(pTab->vte), "child-exited", G_CALLBACK(termit_on_child_exited), NULL); // g_signal_connect(G_OBJECT(pTab->vte), "eof", G_CALLBACK(termit_eof), NULL); g_signal_connect_swapped(G_OBJECT(pTab->vte), "button-press-event", G_CALLBACK(termit_on_popup), NULL); vte_terminal_set_encoding(VTE_TERMINAL(pTab->vte), pTab->encoding); pTab->matches = g_array_new(FALSE, TRUE, sizeof(struct Match)); termit_tab_add_matches(pTab, configs.matches); termit_tab_set_transparency(pTab, pTab->style.transparency); vte_terminal_set_font(VTE_TERMINAL(pTab->vte), pTab->style.font); gint index = gtk_notebook_append_page(GTK_NOTEBOOK(termit.notebook), pTab->hbox, pTab->tab_name); if (index == -1) { ERROR("%s", _("Cannot create a new tab")); return; } if (configs.fill_tabbar) { GValue val = {}; g_value_init(&val, G_TYPE_BOOLEAN); g_value_set_boolean(&val, TRUE); gtk_container_child_set_property(GTK_CONTAINER(termit.notebook), pTab->hbox, "tab-expand", &val); gtk_container_child_set_property(GTK_CONTAINER(termit.notebook), pTab->hbox, "tab-fill", &val); } termit_tab_set_audible_bell(pTab, configs.audible_bell); termit_tab_set_visible_bell(pTab, configs.visible_bell); pTab->scrollbar = gtk_vscrollbar_new(vte_terminal_get_adjustment(VTE_TERMINAL(pTab->vte))); gtk_box_pack_start(GTK_BOX(pTab->hbox), pTab->vte, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(pTab->hbox), pTab->scrollbar, FALSE, FALSE, 0); GtkWidget* tabWidget = gtk_notebook_get_nth_page(GTK_NOTEBOOK(termit.notebook), index); if (!tabWidget) { ERROR("tabWidget is NULL"); return; } g_object_set_data(G_OBJECT(tabWidget), TERMIT_TAB_DATA, pTab); if (index == 0) { // there is no "switch-page" signal on the first page termit_set_statusbar_message(index); } pTab->scrollbar_is_shown = configs.show_scrollbar; gtk_widget_show_all(termit.notebook); if (pTab->style.image_file == NULL) { vte_terminal_set_background_image(VTE_TERMINAL(pTab->vte), NULL); } else { vte_terminal_set_background_image_file(VTE_TERMINAL(pTab->vte), pTab->style.image_file); } termit_tab_apply_colors(pTab); gtk_notebook_set_current_page(GTK_NOTEBOOK(termit.notebook), index); gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(termit.notebook), pTab->hbox, TRUE); gtk_window_set_focus(GTK_WINDOW(termit.main_window), pTab->vte); termit_check_single_tab(); termit_hide_scrollbars(); }