# HG changeset patch # User Mark Doliner # Date 1118709948 0 # Node ID 5d3b0a920d83f70f6cbf2c6868f8158fc558366f # Parent bb7fd9359f9e3c6242ad7284ae9d0be0fdbb0080 [gaim-migrate @ 12866] sf patch #1206146, from Ted Percival "Fix smooth scrolling assertions" (Start Gaim with the debug window enabled if you don't believe me) committer: Tailor Script diff -r bb7fd9359f9e -r 5d3b0a920d83 COPYRIGHT --- a/COPYRIGHT Tue Jun 14 00:24:27 2005 +0000 +++ b/COPYRIGHT Tue Jun 14 00:45:48 2005 +0000 @@ -143,6 +143,7 @@ Matt Pandina Ricardo Fernandez Pascual Havoc Pennington +Ted Percival Eduardo PĂ©rez Ari Pollak Robey Pointer diff -r bb7fd9359f9e -r 5d3b0a920d83 src/gtkimhtml.c --- a/src/gtkimhtml.c Tue Jun 14 00:24:27 2005 +0000 +++ b/src/gtkimhtml.c Tue Jun 14 00:45:48 2005 +0000 @@ -2241,37 +2241,39 @@ } } -#define MAX_SCROLL_TIME 0.4 - +#define MAX_SCROLL_TIME 0.4 /* seconds */ +#define SCROLL_DELAY 33 /* milliseconds */ + +/* + * Smoothly scroll a GtkIMHtml. + * + * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom. + */ static gboolean scroll_cb(gpointer data) { GtkIMHtml *imhtml = data; GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; - gdouble val = adj->upper - adj->page_size; - gdouble t; - - t = g_timer_elapsed(imhtml->scroll_time, NULL); - - if (adj->value >= val || t >= MAX_SCROLL_TIME) { - gaim_debug_info("gtkimhtml", "scroll_cb: out of time\n"); - gtk_adjustment_set_value(adj, val); - } else { - gtk_adjustment_set_value(adj, - adj->value + (((val - adj->value) * t ) / MAX_SCROLL_TIME)); - } - - if (adj->value >= val) { + gdouble max_val = adj->upper - adj->page_size; + + g_return_val_if_fail(imhtml->scroll_time != NULL, FALSE); + + if (g_timer_elapsed(imhtml->scroll_time, NULL) > MAX_SCROLL_TIME) { + /* time's up. jump to the end and kill the timer */ + gtk_adjustment_set_value(adj, max_val); g_timer_destroy(imhtml->scroll_time); imhtml->scroll_time = NULL; return FALSE; - } else - return TRUE; + } + + /* scroll by 1/3rd the remaining distance */ + gtk_adjustment_set_value(adj, gtk_adjustment_get_value(adj) + ((max_val - gtk_adjustment_get_value(adj)) / 3)); + return TRUE; } static gboolean scroll_idle_cb(gpointer data) { GtkIMHtml *imhtml = data; - imhtml->scroll_src = g_timeout_add(33, scroll_cb, imhtml); + imhtml->scroll_src = g_timeout_add(SCROLL_DELAY, scroll_cb, imhtml); return FALSE; }