commit 977a150919b84db993ed7513dffcf0c62765b771
Author: Josh Stone <jistone@redhat.com>
Date:   Tue Apr 14 20:16:37 2009 -0700

    [vte] ensure that scroll_delta is always adjusted
    
    When gnome-terminal's height is reduced, the active tab's terminal gets
    a vte_terminal_size_allocate() call, which queues an adjustment to the
    scroll_delta based on visible_rows to ensure that the scrollback moves
    correctly.
    
    However, when you then switch to a different tab, that terminal gets a
    vte_terminal_set_size() first, which will update terminal->row_count
    with the new height.  Only after it's visible does it get
    vte_terminal_size_allocate(), and there the computation of visible_rows
    thinks that there's no reduction (since terminal->row_count already
    matches the new height), so it doesn't compute the new scroll_delta.
    
    This patch moves the scroll_delta computation into set_size so it is
    always kept current.

diff --git a/src/vte.c b/src/vte.c
index e6b2e9b..d21e409 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -7718,6 +7718,18 @@ vte_terminal_set_size(VteTerminal *terminal, glong columns, glong rows)
 	}
 	if (old_rows != terminal->row_count ||
 			old_columns != terminal->column_count) {
+		VteScreen *screen = terminal->pvt->screen;
+		if (screen) {
+			glong visible_rows = MIN (old_rows,
+					_vte_ring_length (screen->row_data));
+			if (terminal->row_count < visible_rows) {
+				glong delta = visible_rows - terminal->row_count;
+				screen->insert_delta += delta;
+				vte_terminal_queue_adjustment_value_changed (
+						terminal,
+						screen->scroll_delta + delta);
+			}
+		}
 		gtk_widget_queue_resize (&terminal->widget);
 		/* Our visible text changed. */
 		vte_terminal_emit_text_modified(terminal);
@@ -8233,27 +8245,18 @@ vte_terminal_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
 	if (width != terminal->column_count
 			|| height != terminal->row_count
 			|| update_scrollback) {
-		VteScreen *screen = terminal->pvt->screen;
-		glong visible_rows = MIN (terminal->row_count,
-				_vte_ring_length (screen->row_data));
-		if (height < visible_rows) {
-			glong delta = visible_rows - height;
-			screen->insert_delta += delta;
-			vte_terminal_queue_adjustment_value_changed (
-					terminal,
-					screen->scroll_delta + delta);
-		}
 		/* Set the size of the pseudo-terminal. */
 		vte_terminal_set_size(terminal, width, height);
 
 		/* Adjust scrolling area in case our boundaries have just been
 		 * redefined to be invalid. */
-		if (terminal->pvt->screen->scrolling_restricted) {
-			terminal->pvt->screen->scrolling_region.start =
-				MIN(terminal->pvt->screen->scrolling_region.start,
+		VteScreen *screen = terminal->pvt->screen;
+		if (screen->scrolling_restricted) {
+			screen->scrolling_region.start =
+				MIN(screen->scrolling_region.start,
 						terminal->row_count - 1);
-			terminal->pvt->screen->scrolling_region.end =
-				MIN(terminal->pvt->screen->scrolling_region.end,
+			screen->scrolling_region.end =
+				MIN(screen->scrolling_region.end,
 						terminal->row_count - 1);
 		}
 
