[vte/vte-next: 210/223] Add vte_view_get_geometry_hints
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/vte-next: 210/223] Add vte_view_get_geometry_hints
- Date: Wed, 22 Jun 2011 21:06:14 +0000 (UTC)
commit e05640a27aeded5f1329ad515e790489286f9458
Author: Christian Persch <chpe gnome org>
Date: Mon Jun 20 00:35:13 2011 +0200
Add vte_view_get_geometry_hints
Add vte_view_get_geometry_hints to fill in a #GdkGeometry with
the geometry hints for the view.
doc/reference/vte-sections.txt | 4 ++
src/vte.c | 68 ++++++++++++++++++++++++++++++++++++++++
src/vteapp.c | 62 +++++-------------------------------
src/vteview.h | 7 ++++
4 files changed, 88 insertions(+), 53 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 7b1c8d3..32bdcaf 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -44,6 +44,10 @@ vte_view_search_set_gregex
vte_view_search_set_wrap_around
<SUBSECTION>
+vte_view_get_geometry_hints
+vte_view_set_window_geometry_hints
+
+<SUBSECTION>
VTE_STYLE_CLASS_TERMINAL
<SUBSECTION>
diff --git a/src/vte.c b/src/vte.c
index 839435c..c932f75 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -13474,6 +13474,74 @@ vte_view_search_find_next (VteView *terminal)
return vte_view_search_find (terminal, FALSE);
}
+#define MIN_COLUMNS (8)
+#define MIN_ROWS (1)
+
+/**
+ * vte_view_get_geometry_hints:
+ * @view: a #VteView
+ * @hints: a #GdkGeometry
+ * @min_rows: the minimum number of rows to request
+ * @min_columns: the minimum number of columns to request
+ *
+ * Fills in some @hints from @view'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.
+ *
+ * @view must be realized (see gtk_widget_get_realized()).
+ */
+void
+vte_view_get_geometry_hints(VteView *view,
+ GdkGeometry *hints,
+ int min_rows,
+ int min_columns)
+{
+ VteViewPrivate *pvt;
+
+ g_return_if_fail(VTE_IS_VIEW(view));
+ g_return_if_fail(hints != NULL);
+ g_return_if_fail(gtk_widget_get_realized(&view->widget));
+
+ pvt = view->pvt;
+
+ hints->base_width = pvt->padding.left + pvt->padding.right;
+ hints->base_height = pvt->padding.top + pvt->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_view_set_window_geometry_hints:
+ * @view: a #VteView
+ * @window: a #GtkWindow
+ *
+ * Sets @view as @window's geometry widget. See
+ * gtk_window_set_geometry_hints() for more information.
+ *
+ * @view must be realized (see gtk_widget_get_realized()).
+ */
+void
+vte_view_set_window_geometry_hints(VteView *view,
+ GtkWindow *window)
+{
+ GdkGeometry hints;
+
+ g_return_if_fail(VTE_IS_VIEW(view));
+ g_return_if_fail(gtk_widget_get_realized(&view->widget));
+
+ vte_view_get_geometry_hints(view, &hints, MIN_ROWS, MIN_COLUMNS);
+ gtk_window_set_geometry_hints(window,
+ &view->widget,
+ &hints,
+ GDK_HINT_RESIZE_INC |
+ GDK_HINT_MIN_SIZE |
+ GDK_HINT_BASE_SIZE);
+}
+
/* *********
* VteBuffer
* *********
diff --git a/src/vteapp.c b/src/vteapp.c
index f702f82..5588d40 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -60,71 +60,27 @@ icon_title_changed(VteBuffer *buffer, GtkWindow *window)
static void
char_size_changed(GtkWidget *widget, guint width, guint height, gpointer data)
{
- VteView *terminal;
- GtkWindow *window;
- GdkGeometry geometry;
- GtkBorder padding;
-
- g_assert(GTK_IS_WINDOW(data));
- g_assert(VTE_IS_VIEW(widget));
+ VteView *view = VTE_VIEW(widget);
+ GtkWindow *window = GTK_WINDOW(data);
- terminal = VTE_VIEW(widget);
- 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_view_set_window_geometry_hints(view, window);
}
static void
char_size_realized(GtkWidget *widget, gpointer data)
{
- VteView *terminal;
- GtkWindow *window;
- GdkGeometry geometry;
- guint width, height;
- GtkBorder padding;
-
- g_assert(GTK_IS_WINDOW(data));
- g_assert(VTE_IS_VIEW(widget));
+ VteView *view = VTE_VIEW(widget);
+ GtkWindow *window = GTK_WINDOW(data);
- terminal = VTE_VIEW(widget);
- 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);
- width = vte_view_get_char_width (terminal);
- height = vte_view_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_view_set_window_geometry_hints(view, window);
}
-
static void
destroy_and_quit(VteView *terminal, GtkWidget *window)
{
diff --git a/src/vteview.h b/src/vteview.h
index 986c8c3..9f70d42 100644
--- a/src/vteview.h
+++ b/src/vteview.h
@@ -174,6 +174,13 @@ gboolean vte_view_search_find_next (VteView *terminal);
glong vte_view_get_char_width(VteView *terminal);
glong vte_view_get_char_height(VteView *terminal);
+void vte_view_get_geometry_hints(VteView *view,
+ GdkGeometry *hints,
+ int min_rows,
+ int min_columns);
+void vte_view_set_window_geometry_hints(VteView *view,
+ GtkWindow *window);
+
G_END_DECLS
#endif /* __VTE_VIEW_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]