[vte] widget: Add window geometry helper function



commit 854633c4cff36853f2618ea02cdb3e4936a3f813
Author: Christian Persch <chpe gnome org>
Date:   Mon Apr 7 21:26:03 2014 +0200

    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.

 doc/reference/vte-sections.txt |    4 ++
 src/vte.c                      |   76 ++++++++++++++++++++++++++++++++++++++++
 src/vte.h                      |    8 ++++
 src/vteapp.c                   |   59 +++++--------------------------
 4 files changed, 97 insertions(+), 50 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 99c4d02..8878ef2 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -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
diff --git a/src/vte.c b/src/vte.c
index 803041e..b46201a 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -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);
+}
diff --git a/src/vte.h b/src/vte.h
index 55662b0..e1c60db 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -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 */
 
 /**
diff --git a/src/vteapp.c b/src/vteapp.c
index 78ba9bd..8f6a364 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -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);
 }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]