Description: fix window scrolling position when switching channels and on
 initial channel autojoin
Author: Marc Deslauriers <marc.deslauriers@canonical.com>
Forwarded: yes
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=739895
Updated: 2014-11-13

Index: xchat-gnome-0.30.0~git20141005.816798/src/fe-gnome/xtext.c
===================================================================
--- xchat-gnome-0.30.0~git20141005.816798.orig/src/fe-gnome/xtext.c	2014-11-13 00:36:31.997252340 -0500
+++ xchat-gnome-0.30.0~git20141005.816798/src/fe-gnome/xtext.c	2014-11-13 00:37:00.585451674 -0500
@@ -3302,7 +3302,8 @@
 	buffer->old_value -= ent->lines_taken;
 	if (buffer->xtext->buffer == buffer)	/* is it the current buffer? */
 	{
-		gtk_adjustment_set_value (buffer->xtext->adj, ent->lines_taken);
+		gtk_adjustment_set_value (buffer->xtext->adj,
+			gtk_adjustment_get_value (buffer->xtext->adj) - ent->lines_taken);
 		buffer->xtext->select_start_adj -= ent->lines_taken;
 	}
 
@@ -3574,7 +3575,8 @@
 															gtk_xtext_render_page_timeout,
 															buf->xtext);
 		}
-	} else if (buf->scrollbar_down)
+	}
+	if (buf->scrollbar_down)
 	{
 		buf->old_value = buf->num_lines - gtk_adjustment_get_page_size (buf->xtext->adj);
 		if (buf->old_value < 0)
@@ -3827,14 +3829,15 @@
 
 	/* now change to the new buffer */
 	xtext->buffer = buf;
-	gtk_adjustment_set_value (xtext->adj, buf->old_value);
 	gtk_adjustment_set_upper (xtext->adj, buf->num_lines? buf->num_lines: 1);
 	/* sanity check */
-	if (gtk_adjustment_get_value (xtext->adj) > gtk_adjustment_get_upper (xtext->adj) - 
+	if (buf->old_value > gtk_adjustment_get_upper (xtext->adj) -
 			gtk_adjustment_get_page_size (xtext->adj))
 	{
 		int val = gtk_adjustment_get_upper (xtext->adj) - gtk_adjustment_get_page_size (xtext->adj);
 		gtk_adjustment_set_value (xtext->adj, (val > 0)? val: 0);
+	} else {
+		gtk_adjustment_set_value (xtext->adj, buf->old_value);
 	}
 
 	if (render)
@@ -3851,6 +3854,8 @@
 		{
 			buf->window_height = h;
 			buf->pagetop_ent = NULL;
+			if (buf->scrollbar_down)
+				gtk_adjustment_set_value (xtext->adj, gtk_adjustment_get_upper (xtext->adj));
 			gtk_xtext_adjustment_set (buf, FALSE);
 		}
 
