summaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2015-03-26 18:28:58 +0000
committerjstebbins <[email protected]>2015-03-26 18:28:58 +0000
commitb57a04d14e2a5a6e8b5d18374efce3f66c4ea8d6 (patch)
tree3a93b73f249a0e9bf8ca0bf7dce8a7e43fb681c2 /gtk
parentd95ba727796d6d138aa3e44c0eeeb9f60354a48f (diff)
merge LinGui: fix activity window scrolling
Yet another work-around for a gtk+-3 problem. They now delay updating the scrollbar adjustment to an idle loop callback. So I must delay my scroll-to-bottom code so that it occurrs after their update. git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/0.10.x@7018 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk')
-rw-r--r--gtk/src/callbacks.c70
1 files changed, 40 insertions, 30 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c
index 1d2ea0c46..afe0a560d 100644
--- a/gtk/src/callbacks.c
+++ b/gtk/src/callbacks.c
@@ -3392,6 +3392,35 @@ ghb_timer_cb(gpointer data)
return TRUE;
}
+gboolean scroll_at_bottom(signal_user_data_t *ud, const char *scroll)
+{
+ GtkScrolledWindow *window;
+ GtkAdjustment *adj;
+ double val, upper, ps;
+
+ window = GTK_SCROLLED_WINDOW(GHB_WIDGET(ud->builder, scroll));
+ adj = gtk_scrolled_window_get_vadjustment(window);
+ val = gtk_adjustment_get_value(adj);
+ upper = gtk_adjustment_get_upper(adj);
+ ps = gtk_adjustment_get_page_size(adj);
+ return val >= upper - ps;
+}
+
+G_MODULE_EXPORT gboolean
+activity_scroll_to_bottom(signal_user_data_t *ud)
+{
+ GtkScrolledWindow *window;
+ GtkAdjustment *adj;
+ double upper, ps;
+
+ window = GTK_SCROLLED_WINDOW(GHB_WIDGET(ud->builder, "activity_scroll"));
+ adj = gtk_scrolled_window_get_vadjustment(window);
+ upper = gtk_adjustment_get_upper(adj);
+ ps = gtk_adjustment_get_page_size(adj);
+ gtk_adjustment_set_value(adj, upper - ps);
+ return FALSE;
+}
+
G_MODULE_EXPORT gboolean
ghb_log_cb(GIOChannel *source, GIOCondition cond, gpointer data)
{
@@ -3400,7 +3429,6 @@ ghb_log_cb(GIOChannel *source, GIOCondition cond, gpointer data)
GtkTextView *textview;
GtkTextBuffer *buffer;
GtkTextIter iter;
- GtkTextMark *mark;
GError *gerror = NULL;
GIOStatus status;
@@ -3413,36 +3441,12 @@ ghb_log_cb(GIOChannel *source, GIOCondition cond, gpointer data)
length--;
if (text != NULL && length > 0)
{
- GdkWindow *window;
- gint width, height;
- gint x, y;
gboolean bottom = FALSE;
gchar *utf8_text;
+ bottom = scroll_at_bottom(ud, "activity_scroll");
textview = GTK_TEXT_VIEW(GHB_WIDGET (ud->builder, "activity_view"));
buffer = gtk_text_view_get_buffer (textview);
- // I would like to auto-scroll the window when the scrollbar
- // is at the bottom,
- // must determine whether the insert point is at
- // the bottom of the window
- window = gtk_text_view_get_window(textview, GTK_TEXT_WINDOW_TEXT);
- if (window != NULL)
- {
- width = gdk_window_get_width(window);
- height = gdk_window_get_height(window);
- gtk_text_view_window_to_buffer_coords(textview,
- GTK_TEXT_WINDOW_TEXT, width, height, &x, &y);
- gtk_text_view_get_iter_at_location(textview, &iter, x, y);
- if (gtk_text_iter_is_end(&iter))
- {
- bottom = TRUE;
- }
- }
- else
- {
- // If the window isn't available, assume bottom
- bottom = TRUE;
- }
gtk_text_buffer_get_end_iter(buffer, &iter);
utf8_text = g_convert_with_fallback(text, -1, "UTF-8", "ISO-8859-1",
"?", NULL, &length, NULL);
@@ -3451,10 +3455,16 @@ ghb_log_cb(GIOChannel *source, GIOCondition cond, gpointer data)
gtk_text_buffer_insert(buffer, &iter, utf8_text, -1);
if (bottom)
{
- gtk_text_buffer_get_end_iter(buffer, &iter);
- mark = gtk_text_buffer_create_mark(buffer, NULL, &iter, FALSE);
- gtk_text_view_scroll_mark_onscreen(textview, mark);
- gtk_text_buffer_delete_mark(buffer, mark);
+ static guint scroll_tok = 0;
+ GSource *source = NULL;
+ if (scroll_tok > 0)
+ source = g_main_context_find_source_by_id(NULL, scroll_tok);
+ if (source != NULL)
+ {
+ g_source_remove(scroll_tok);
+ }
+ scroll_tok = g_idle_add((GSourceFunc)activity_scroll_to_bottom,
+ ud);
}
#if defined(_WIN32)
gsize one = 1;