[vte] Report correct minimum/natural sizes for GTK+ 3
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] Report correct minimum/natural sizes for GTK+ 3
- Date: Mon, 11 Oct 2010 19:35:02 +0000 (UTC)
commit 7d0eb2ff215709712d80577521a22979490126e5
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Mon Oct 11 13:22:31 2010 -0400
Report correct minimum/natural sizes for GTK+ 3
In GTK+ 3, the hack of reporting the current size of the terminal
as its minimum size breaks down because GTK+ 3 will never allocate
a widget smaller than its minimum size. However, in GTK+ 3 it's
possible to report separate minimum and natural sizes, so we
should just report a minimum size of 1x1 character and a natural
size of the current size.
This requires a change in vteapp.c to make the window start off
at the right size.
https://bugzilla.gnome.org/show_bug.cgi?id=631903
src/vte.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/vteapp.c | 10 ++++++++
2 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/src/vte.c b/src/vte.c
index 0a21d9f..867a9c1 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -8203,6 +8203,67 @@ vte_terminal_init(VteTerminal *terminal)
}
/* Tell GTK+ how much space we need. */
+#if GTK_CHECK_VERSION (2, 91, 0)
+static void
+vte_terminal_get_preferred_width(GtkWidget *widget,
+ int *minimum_width,
+ int *natural_width)
+{
+ VteTerminal *terminal;
+
+ _vte_debug_print(VTE_DEBUG_LIFECYCLE, "vte_terminal_get_preferred_width()\n");
+
+ terminal = VTE_TERMINAL(widget);
+
+ vte_terminal_ensure_font (terminal);
+
+ vte_terminal_refresh_size(terminal);
+ *minimum_width = terminal->char_width * 1;
+ *natural_width = terminal->char_width * terminal->column_count;
+
+ *minimum_width += terminal->pvt->inner_border.left +
+ terminal->pvt->inner_border.right;
+ *natural_width += terminal->pvt->inner_border.left +
+ terminal->pvt->inner_border.right;
+
+ _vte_debug_print(VTE_DEBUG_WIDGET_SIZE,
+ "[Terminal %p] minimum_width=%d, natural_width=%d for %ldx%ld cells.\n",
+ terminal,
+ *minimum_width, *natural_width,
+ terminal->column_count,
+ terminal->row_count);
+}
+
+static void
+vte_terminal_get_preferred_height(GtkWidget *widget,
+ int *minimum_height,
+ int *natural_height)
+{
+ VteTerminal *terminal;
+
+ _vte_debug_print(VTE_DEBUG_LIFECYCLE, "vte_terminal_get_preferred_height()\n");
+
+ terminal = VTE_TERMINAL(widget);
+
+ vte_terminal_ensure_font (terminal);
+
+ vte_terminal_refresh_size(terminal);
+ *minimum_height = terminal->char_height * 1;
+ *natural_height = terminal->char_height * terminal->row_count;
+
+ *minimum_height += terminal->pvt->inner_border.left +
+ terminal->pvt->inner_border.right;
+ *natural_height += terminal->pvt->inner_border.left +
+ terminal->pvt->inner_border.right;
+
+ _vte_debug_print(VTE_DEBUG_WIDGET_SIZE,
+ "[Terminal %p] minimum_height=%d, natural_height=%d for %ldx%ld cells.\n",
+ terminal,
+ *minimum_height, *natural_height,
+ terminal->column_count,
+ terminal->row_count);
+}
+#else /* GTK+ 2.x */
static void
vte_terminal_size_request(GtkWidget *widget, GtkRequisition *requisition)
{
@@ -8230,6 +8291,7 @@ vte_terminal_size_request(GtkWidget *widget, GtkRequisition *requisition)
terminal->column_count,
terminal->row_count);
}
+#endif
/* Accept a given size from GTK+. */
static void
@@ -11402,7 +11464,12 @@ vte_terminal_class_init(VteTerminalClass *klass)
widget_class->visibility_notify_event = vte_terminal_visibility_notify;
widget_class->unrealize = vte_terminal_unrealize;
widget_class->style_set = vte_terminal_style_set;
+#if GTK_CHECK_VERSION (2, 91, 0)
+ widget_class->get_preferred_width = vte_terminal_get_preferred_width;
+ widget_class->get_preferred_height = vte_terminal_get_preferred_height;
+#else
widget_class->size_request = vte_terminal_size_request;
+#endif
widget_class->size_allocate = vte_terminal_size_allocate;
widget_class->get_accessible = vte_terminal_get_accessible;
widget_class->screen_changed = vte_terminal_screen_changed;
diff --git a/src/vteapp.c b/src/vteapp.c
index c3921a0..144eaed 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -1074,6 +1074,16 @@ main(int argc, char **argv)
g_warning (_("Could not parse the geometry spec passed to --geometry"));
}
}
+#if GTK_CHECK_VERSION(2, 91, 0)
+ else {
+ /* As of GTK+ 2.91.0, the default size of a window comes from its minimum
+ * size not its natural size, so we need to set the right default size
+ * explicitly */
+ gtk_window_set_default_geometry (window,
+ vte_terminal_get_column_count (terminal),
+ vte_terminal_get_row_count (terminal));
+ }
+#endif
gtk_widget_show_all(window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]