Commit 854633c4 authored by Christian Persch's avatar Christian Persch

widget: Add window geometry helper function

Encapsulate this into a helper function that'll be used in gnome-terminal,
instead of having to poke at the internas like character width and height.
parent d7772dd9
......@@ -89,6 +89,10 @@ vte_terminal_set_pty
vte_terminal_pty_new_sync
vte_terminal_watch_child
<SUBSECTION>
vte_terminal_get_geometry_hints
vte_terminal_set_geometry_hints_for_window
<SUBSECTION Standard>
VTE_TYPE_CURSOR_BLINK_MODE
vte_cursor_blink_mode_get_type
......
......@@ -13929,3 +13929,79 @@ vte_terminal_search_find_next (VteTerminal *terminal)
{
return vte_terminal_search_find (terminal, FALSE);
}
/* Just some arbitrary minimum values */
#define MIN_COLUMNS (16)
#define MIN_ROWS (2)
/**
* vte_terminal_get_geometry_hints:
* @terminal: a #VteTerminal
* @hints: (out caller-allocates): a #GdkGeometry to fill in
* @min_rows: the minimum number of rows to request
* @min_columns: the minimum number of columns to request
*
* Fills in some @hints from @terminal's geometry. The hints
* filled are those covered by the %GDK_HINT_RESIZE_INC,
* %GDK_HINT_MIN_SIZE and %GDK_HINT_BASE_SIZE flags.
*
* See gtk_window_set_geometry_hints() for more information.
*
* @terminal must be realized (see gtk_widget_get_realized()).
*/
void
vte_terminal_get_geometry_hints(VteTerminal *terminal,
GdkGeometry *hints,
int min_rows,
int min_columns)
{
VteTerminalPrivate *pvt;
GtkWidget *widget;
GtkBorder padding;
g_return_if_fail(VTE_IS_TERMINAL(terminal));
g_return_if_fail(hints != NULL);
widget = &terminal->widget;
g_return_if_fail(gtk_widget_get_realized(widget));
pvt = terminal->pvt;
gtk_style_context_get_padding(gtk_widget_get_style_context(widget),
gtk_widget_get_state_flags(widget),
&padding);
hints->base_width = padding.left + padding.right;
hints->base_height = padding.top + padding.bottom;
hints->width_inc = pvt->char_width;
hints->height_inc = pvt->char_height;
hints->min_width = hints->base_width + hints->width_inc * min_columns;
hints->min_height = hints->base_height + hints->height_inc * min_rows;
}
/**
* vte_terminal_set_geometry_hints_for_window:
* @terminal: a #VteTerminal
* @window: a #GtkWindow
*
* Sets @terminal as @window's geometry widget. See
* gtk_window_set_geometry_hints() for more information.
*
* @terminal must be realized (see gtk_widget_get_realized()).
*/
void
vte_terminal_set_geometry_hints_for_window(VteTerminal *terminal,
GtkWindow *window)
{
GdkGeometry hints;
g_return_if_fail(VTE_IS_TERMINAL(terminal));
g_return_if_fail(gtk_widget_get_realized(&terminal->widget));
vte_terminal_get_geometry_hints(terminal, &hints, MIN_ROWS, MIN_COLUMNS);
gtk_window_set_geometry_hints(window,
&terminal->widget,
&hints,
GDK_HINT_RESIZE_INC |
GDK_HINT_MIN_SIZE |
GDK_HINT_BASE_SIZE);
}
......@@ -384,6 +384,14 @@ const char *vte_terminal_get_icon_title(VteTerminal *terminal);
const char *vte_terminal_get_current_directory_uri(VteTerminal *terminal);
const char *vte_terminal_get_current_file_uri(VteTerminal *terminal);
/* Window geometry helpers */
void vte_terminal_get_geometry_hints(VteTerminal *terminal,
GdkGeometry *hints,
int min_rows,
int min_columns);
void vte_terminal_set_geometry_hints_for_window(VteTerminal *terminal,
GtkWindow *window);
/* Writing contents out */
/**
......
......@@ -69,66 +69,25 @@ icon_title_changed(GtkWidget *widget, gpointer win)
static void
char_size_changed(GtkWidget *widget, guint width, guint height, gpointer data)
{
GtkWindow *window;
GdkGeometry geometry;
GtkBorder padding;
g_assert(GTK_IS_WINDOW(data));
g_assert(VTE_IS_TERMINAL(widget));
VteTerminal *terminal = VTE_TERMINAL(widget);
GtkWindow *window = GTK_WINDOW(data);
window = GTK_WINDOW(data);
if (!gtk_widget_get_realized (GTK_WIDGET (window)))
if (!gtk_widget_get_realized (widget))
return;
gtk_style_context_get_padding(gtk_widget_get_style_context(widget),
gtk_widget_get_state_flags(widget),
&padding);
geometry.width_inc = width;
geometry.height_inc = height;
geometry.base_width = padding.left + padding.right;
geometry.base_height = padding.top + padding.bottom;
geometry.min_width = geometry.base_width + width * 2;
geometry.min_height = geometry.base_height + height * 2;
gtk_window_set_geometry_hints(window, widget, &geometry,
GDK_HINT_RESIZE_INC |
GDK_HINT_BASE_SIZE |
GDK_HINT_MIN_SIZE);
vte_terminal_set_geometry_hints_for_window(terminal, window);
}
static void
char_size_realized(GtkWidget *widget, gpointer data)
{
VteTerminal *terminal;
GtkWindow *window;
GdkGeometry geometry;
guint width, height;
GtkBorder padding;
g_assert(GTK_IS_WINDOW(data));
g_assert(VTE_IS_TERMINAL(widget));
VteTerminal *terminal = VTE_TERMINAL(widget);
GtkWindow *window = GTK_WINDOW(data);
terminal = VTE_TERMINAL(widget);
window = GTK_WINDOW(data);
if (!gtk_widget_get_realized (GTK_WIDGET(window)))
return;
if (!gtk_widget_get_realized (widget))
return;
gtk_style_context_get_padding(gtk_widget_get_style_context(widget),
gtk_widget_get_state_flags(widget),
&padding);
width = vte_terminal_get_char_width (terminal);
height = vte_terminal_get_char_height (terminal);
geometry.width_inc = width;
geometry.height_inc = height;
geometry.base_width = padding.left + padding.right;
geometry.base_height = padding.top + padding.bottom;
geometry.min_width = geometry.base_width + width * 2;
geometry.min_height = geometry.base_height + height * 2;
gtk_window_set_geometry_hints(window, widget, &geometry,
GDK_HINT_RESIZE_INC |
GDK_HINT_BASE_SIZE |
GDK_HINT_MIN_SIZE);
vte_terminal_set_geometry_hints_for_window(terminal, window);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment