static VALUE term_get_padding(VALUE self) { int xpad, ypad; vte_terminal_get_padding(RVAL2TERM(self), &xpad, &ypad); return rb_ary_new3(2, INT2NUM(xpad), INT2NUM(ypad)); }
// set the window hints information void window_resizable(GtkWidget *window, GtkWidget *vte, gint set_hints_inc) { #ifdef DEFENSIVE if ((window==NULL) || (vte==NULL)) return; #endif #ifdef DETAIL g_debug("! Launch window_resizable() with window = %p, vte = %p, set_hints_inc = %d", window, vte, set_hints_inc); #endif // DIRTY HACK: don't run window_resizable too much times before window is shown! if ((set_hints_inc != 1) && (gtk_widget_get_mapped(window) == FALSE)) return; // vte=NULL when creating a new root window with drag & drop. // if (vte==NULL) return; GdkGeometry hints = {0}; // g_debug("Trying to get padding..."); vte_terminal_get_padding (VTE_TERMINAL(vte), &(hints.base_width), &(hints.base_height)); // g_debug("hints.base_width = %d, hints.base_height = %d", hints.base_width, hints.base_height); switch (set_hints_inc) { case 1: hints.width_inc = vte_terminal_get_char_width(VTE_TERMINAL(vte)); hints.height_inc = vte_terminal_get_char_height(VTE_TERMINAL(vte)); break; case 2: hints.width_inc = 1; hints.height_inc = 1; break; } // g_debug("hints.width_inc = %d, hints.height_inc = %d", // hints.width_inc, hints.height_inc); // // minsize = -1: the size of vte can NOT be changed. // if (minsize == -1) // { // hints.min_width = minsize; // hints.min_height = minsize; // } // else // { hints.min_width = hints.base_width + hints.width_inc; hints.min_height = hints.base_height + hints.height_inc; // } // g_debug("Tring to set geometry on %p, and set_hints_inc = %d", vte, set_hints_inc); gtk_window_set_geometry_hints (GTK_WINDOW (window), GTK_WIDGET (vte), &hints, GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); //g_debug("current the size of vte %p whith hinting = %ld x %ld", // vte, // vte_terminal_get_column_count(VTE_TERMINAL(vte)), // vte_terminal_get_row_count(VTE_TERMINAL(vte))); }
static void mud_subwindow_set_size_force_grid (MudSubwindow *window, VteTerminal *screen, gboolean even_if_mapped, int force_grid_width, int force_grid_height) { /* TODO: Missing get_padding in new VTE; maybe we can just use vte_terminal_set_size? */ #if 0 #warning Reimplement mud_subwindow size forcing /* Owen's hack from gnome-terminal */ GtkWidget *widget; GtkWidget *app; GtkRequisition toplevel_request; GtkRequisition widget_request; int w, h; int char_width; int char_height; int grid_width; int grid_height; int xpad; int ypad; g_return_if_fail(MUD_IS_SUBWINDOW(window)); /* be sure our geometry is up-to-date */ mud_subwindow_update_geometry (window); widget = GTK_WIDGET (screen); app = window->priv->window; gtk_widget_size_request (app, &toplevel_request); gtk_widget_size_request (widget, &widget_request); w = toplevel_request.width - widget_request.width; h = toplevel_request.height - widget_request.height; char_width = vte_terminal_get_char_width (screen); char_height = vte_terminal_get_char_height (screen); grid_width = vte_terminal_get_column_count (screen); grid_height = vte_terminal_get_row_count (screen); if (force_grid_width >= 0) grid_width = force_grid_width; if (force_grid_height >= 0) grid_height = force_grid_height; vte_terminal_get_padding (VTE_TERMINAL (screen), &xpad, &ypad); w += xpad * 2 + char_width * grid_width; h += ypad * 2 + char_height * grid_height; if (even_if_mapped && gtk_widget_get_mapped (app)) { gtk_window_resize (GTK_WINDOW (app), w, h); } }
static void term_app_request_resize_move(VteTerminal *term, guint x, guint y, gpointer user_data) { int event = GPOINTER_TO_INT(user_data); if (event == TERM_RESIZE_WINDOW) { gint owidth, oheight, xpad, ypad; gtk_window_get_size(GTK_WINDOW(mainwindow), &owidth, &oheight); owidth -= term->char_width * term->column_count; oheight -= term->char_height * term->row_count; vte_terminal_get_padding(term, &xpad, &ypad); owidth -= xpad; oheight -= ypad; gtk_window_resize(GTK_WINDOW(mainwindow), x+owidth, y+oheight); } if (event == TERM_MOVE_WINDOW) { gdk_window_move(GTK_WIDGET(mainwindow)->window, x, y); } }
static void mud_subwindow_update_geometry (MudSubwindow *window) { GtkWidget *widget = window->priv->terminal; GdkGeometry hints; gint char_width; gint char_height; gint xpad, ypad; if(gtk_widget_get_mapped(window->priv->window)) { char_width = vte_terminal_get_char_width (VTE_TERMINAL(widget)); char_height = vte_terminal_get_char_height (VTE_TERMINAL(widget)); vte_terminal_get_padding (VTE_TERMINAL (window->priv->terminal), &xpad, &ypad); hints.base_width = xpad; hints.base_height = ypad; #define MIN_WIDTH_CHARS 4 #define MIN_HEIGHT_CHARS 2 hints.width_inc = char_width; hints.height_inc = char_height; /* min size is min size of just the geometry widget, remember. */ hints.min_width = hints.base_width + hints.width_inc * MIN_WIDTH_CHARS; hints.min_height = hints.base_height + hints.height_inc * MIN_HEIGHT_CHARS; gtk_window_set_geometry_hints (GTK_WINDOW (window->priv->window), widget, &hints, GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); } #endif }
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); }
// set the window hints information void window_resizable(GtkWidget *window, GtkWidget *vte, Hints_Type hints_type) { #ifdef DETAIL fprintf(stderr, "\033[1;31m** Launch window_resizable() with window = %p, vte = %p, hints_type = %d\033[0m\n", window, vte, hints_type); #endif #ifdef SAFEMODE if ((window==NULL) || (vte==NULL)) return; #endif // DIRTY HACK: don't run window_resizable too much times before window is shown! if ((hints_type != HINTS_FONT_BASE) && (gtk_widget_get_mapped(window) == FALSE)) return; // vte=NULL when creating a new root window with drag & drop. // if (vte==NULL) return; GdkGeometry hints = {0}; // g_debug("Trying to get padding..."); vte_terminal_get_padding (VTE_TERMINAL(vte), &(hints.base_width), &(hints.base_height)); // g_debug("hints.base_width = %d, hints.base_height = %d", hints.base_width, hints.base_height); switch (hints_type) { case HINTS_FONT_BASE: hints.width_inc = vte_terminal_get_char_width(VTE_TERMINAL(vte)); hints.height_inc = vte_terminal_get_char_height(VTE_TERMINAL(vte)); break; case HINTS_NONE: hints.width_inc = 1; hints.height_inc = 1; break; #if defined(USE_GTK3_GEOMETRY_METHOD) || defined(UNIT_TEST) case HINTS_SKIP_ONCE: return; #endif } // g_debug("hints.width_inc = %d, hints.height_inc = %d", // hints.width_inc, hints.height_inc); // // minsize = -1: the size of vte can NOT be changed. // if (minsize == -1) // { // hints.min_width = minsize; // hints.min_height = minsize; // } // else // { #if defined(USE_GTK3_GEOMETRY_METHOD) || defined(UNIT_TEST) gint min_width = 0, min_height = 0; struct Window *win_data = (struct Window *)g_object_get_data(G_OBJECT(window), "Win_Data"); struct Page *page_data = (struct Page *)g_object_get_data(G_OBJECT(vte), "Page_Data"); get_hint_min_size(win_data->notebook, page_data->scroll_bar, &min_width, &min_height); hints.min_width = hints.base_width + ((int)(min_width/hints.width_inc)+1)*hints.width_inc; hints.min_height = hints.base_height + ((int)(min_height/hints.height_inc)+1)*hints.height_inc; # ifdef GEOMETRY fprintf(stderr, "\033[1;37m** window_resizable(win_data %p): window = %p, vte = %p, hints_type = %d\033[0m\n", win_data, window, vte, hints_type); # endif #endif #ifdef USE_GTK2_GEOMETRY_METHOD hints.min_width = hints.base_width + hints.width_inc; hints.min_height = hints.base_height + hints.height_inc; #endif // } #ifdef GEOMETRY g_debug("@ hint data: hints.width_inc = %d, hints.height_inc = %d, hints.base_width = %d, " "@ hints.base_height = %d, hints.min_width = %d, hints.min_height = %d", hints.width_inc, hints.height_inc, hints.base_width, hints.base_height, hints.min_width, hints.min_height); #endif // g_debug("Tring to set geometry on %p, and hints_type = %d", vte, hints_type); gtk_window_set_geometry_hints (GTK_WINDOW (window), GTK_WIDGET (vte), &hints, GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); //g_debug("current the size of vte %p whith hinting = %ld x %ld", // vte, // vte_terminal_get_column_count(VTE_TERMINAL(vte)), // vte_terminal_get_row_count(VTE_TERMINAL(vte))); }