From 441fcc88b3dfe63ca59faf77c00caf7504497c35 Mon Sep 17 00:00:00 2001 From: Marijn van Vliet Date: Tue, 11 May 2010 00:27:59 +0000 Subject: [PATCH] Paging is slowly becoming better, but still susceptible to race conditions git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@271 ddfedd41-794f-dd11-ae45-00112f111e67 --- libchimara/input.c | 14 +++++++++ libchimara/pager.c | 72 ++++++++++++++++++++++++++++++++++++++------- libchimara/pager.h | 2 ++ libchimara/strio.c | 4 --- libchimara/window.c | 2 ++ 5 files changed, 79 insertions(+), 15 deletions(-) diff --git a/libchimara/input.c b/libchimara/input.c index a4511dc..43ed045 100644 --- a/libchimara/input.c +++ b/libchimara/input.c @@ -1,6 +1,7 @@ #include "charset.h" #include "magic.h" #include "input.h" +#include "pager.h" #include "chimara-glk-private.h" extern GPrivate *glk_data_key; @@ -32,6 +33,12 @@ request_char_event_common(winid_t win, gboolean unicode) /* Emit the "waiting" signal to let listeners know we are ready for input */ g_signal_emit_by_name(glk_data->self, "waiting"); + + /* Schedule a check for the pager */ + /* + if(win->type == wintype_TextBuffer) + g_idle_add(pager_check, win); + */ } /** @@ -196,6 +203,11 @@ text_buffer_request_line_event_common(winid_t win, glui32 maxlen, gboolean inser gtk_widget_grab_focus(win->widget); gdk_threads_leave(); + + /* Schedule a check for the pager */ + /* + g_idle_add(pager_check, win); + */ } /** @@ -293,6 +305,8 @@ glk_request_line_event_uni(winid_t win, glui32 *buf, glui32 maxlen, glui32 initl if(glk_data->register_arr) win->buffer_rock = (*glk_data->register_arr)(buf, maxlen, "&+#!Iu"); + + win->input_request_type = INPUT_REQUEST_LINE_UNICODE; win->line_input_buffer_unicode = buf; win->line_input_buffer_max_len = maxlen; diff --git a/libchimara/pager.c b/libchimara/pager.c index a8904cf..c88ab63 100644 --- a/libchimara/pager.c +++ b/libchimara/pager.c @@ -6,7 +6,7 @@ and return the distance between the pager and the end of the buffer in buffer coordinates */ static void -move_pager_and_get_scroll_distance(GtkTextView *textview, gint *view_height, gint *scroll_distance) +move_pager_and_get_scroll_distance(GtkTextView *textview, gint *view_height, gint *scroll_distance, gboolean move ) { GdkRectangle pagerpos, endpos, visiblerect; GtkTextIter oldpager, newpager, end; @@ -23,7 +23,8 @@ move_pager_and_get_scroll_distance(GtkTextView *textview, gint *view_height, gin ); gtk_text_buffer_get_iter_at_mark(buffer, &oldpager, pager); - gtk_text_buffer_move_mark(buffer, pager, &newpager); + if(move) + gtk_text_buffer_move_mark(buffer, pager, &newpager); /* Get the buffer coordinates of the pager and the end iter */ gtk_text_buffer_get_end_iter(buffer, &end); @@ -42,6 +43,7 @@ move_pager_and_get_scroll_distance(GtkTextView *textview, gint *view_height, gin static void start_paging(winid_t win) { + printf("Start paging\n"); win->currently_paging = TRUE; g_signal_handler_unblock(win->widget, win->pager_expose_handler); g_signal_handler_unblock(win->widget, win->pager_keypress_handler); @@ -51,6 +53,7 @@ start_paging(winid_t win) static void stop_paging(winid_t win) { + printf("Stop paging\n"); win->currently_paging = FALSE; g_signal_handler_block(win->widget, win->pager_expose_handler); g_signal_handler_block(win->widget, win->pager_keypress_handler); @@ -62,13 +65,15 @@ gboolean pager_check(gpointer data) { - printf("pager check...\n"); + printf("pager check (idle)...\n"); winid_t win = (winid_t) data; /* Move the pager to the last visible character in the buffer */ gint view_height, scroll_distance; - move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget), &view_height, &scroll_distance ); + move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget), &view_height, &scroll_distance, FALSE ); + + gdk_threads_enter(); if(view_height <= 1) /* Paging is unusable when window is too small */ @@ -86,14 +91,15 @@ pager_check(gpointer data) #endif } else if(scroll_distance > 0) { - GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->widget)); - GtkTextMark *end = gtk_text_buffer_get_mark(buffer, "end_position"); + if(win->input_request_type != INPUT_REQUEST_NONE) { + GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->widget)); + GtkTextMark *end = gtk_text_buffer_get_mark(buffer, "end_position"); - gdk_threads_enter(); - gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(win->widget), end); - gdk_threads_leave(); + gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(win->widget), end); + } } } + gdk_threads_leave(); /* Returning FALSE to prevent this function from being called multiple times */ return FALSE; @@ -105,8 +111,8 @@ pager_after_adjustment_changed(GtkAdjustment *adj, winid_t win) { /* Move the pager, etc. */ gint scroll_distance, view_height; - move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget), &view_height, &scroll_distance ); - + move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget), &view_height, &scroll_distance, TRUE ); + if(scroll_distance > 0 && !win->currently_paging) start_paging(win); else if(scroll_distance == 0 && win->currently_paging) @@ -168,3 +174,47 @@ pager_on_expose(GtkTextView *textview, GdkEventExpose *event, winid_t win) return FALSE; /* Propagate event further */ } +gboolean +pager_after_expose_event(GtkTextView *textview, GdkEventExpose *event, winid_t win) +{ + printf("pager check (expose)...\n"); + g_idle_add(pager_check, win); + +// /* Move the pager to the last visible character in the buffer */ +// gint view_height, scroll_distance; +// move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget), &view_height, &scroll_distance, FALSE ); +// +// if(view_height <= 1) +// /* Paging is unusable when window is too small */ +// return FALSE; +// +// if(!win->currently_paging) { +// if(scroll_distance > view_height) { +// start_paging(win); +// /* Seriously... */ +// /* COMPAT: */ +//#if GTK_CHECK_VERSION(2,14,0) +// gdk_window_invalidate_rect(gtk_widget_get_window(win->widget), NULL, TRUE); +//#else +// gdk_window_invalidate_rect(win->widget->window, NULL, TRUE); +//#endif +// } +// else if(scroll_distance > 0) { +// if(win->input_request_type != INPUT_REQUEST_NONE) { +// GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->widget)); +// GtkTextMark *end = gtk_text_buffer_get_mark(buffer, "end_position"); +// +// gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(win->widget), end); +// } +// } +// } + + return FALSE; +} + +void +pager_after_size_request(GtkTextView *textview, GtkRequisition *requisition, winid_t win) +{ + printf("pager check (size request)...\n"); + g_idle_add(pager_check, win); +} diff --git a/libchimara/pager.h b/libchimara/pager.h index 3ee35d8..7353b3f 100644 --- a/libchimara/pager.h +++ b/libchimara/pager.h @@ -9,6 +9,8 @@ G_GNUC_INTERNAL gboolean pager_on_expose(GtkTextView *textview, GdkEventExpose * G_GNUC_INTERNAL gboolean pager_on_key_press_event(GtkTextView *textview, GdkEventKey *event, winid_t win); G_GNUC_INTERNAL void pager_after_adjustment_changed(GtkAdjustment *adj, winid_t win); G_GNUC_INTERNAL gboolean pager_check(gpointer data); +G_GNUC_INTERNAL gboolean pager_after_expose_event(GtkTextView *textview, GdkEventExpose *event, winid_t win); +G_GNUC_INTERNAL void pager_after_size_request(GtkTextView *textview, GtkRequisition *requisition, winid_t win); #endif diff --git a/libchimara/strio.c b/libchimara/strio.c index ea9d7b5..d040493 100644 --- a/libchimara/strio.c +++ b/libchimara/strio.c @@ -62,10 +62,6 @@ flush_window_buffer(winid_t win) ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK)); g_assert(glk); g_signal_emit_by_name(glk, "text-buffer-output", win->rock, win->buffer->str); - - /* Schedule a check for the pager */ - g_idle_add(pager_check, win); - } break; diff --git a/libchimara/window.c b/libchimara/window.c index 782acd1..77c916e 100644 --- a/libchimara/window.c +++ b/libchimara/window.c @@ -552,6 +552,8 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype, /* Connect signal handlers */ /* Pager */ + //g_signal_connect_after( textview, "expose-event", G_CALLBACK(pager_after_expose_event), win ); + g_signal_connect_after( textview, "size-request", G_CALLBACK(pager_after_size_request), win ); win->pager_expose_handler = g_signal_connect_after( textview, "expose-event", G_CALLBACK(pager_on_expose), win ); g_signal_handler_block(textview, win->pager_expose_handler); win->pager_keypress_handler = g_signal_connect( textview, "key-press-event", G_CALLBACK(pager_on_key_press_event), win ); -- 2.30.2