Paging is slowly becoming better, but still susceptible to race conditions
authorMarijn van Vliet <marijn.vanvliet@med.kuleuven.be>
Tue, 11 May 2010 00:27:59 +0000 (00:27 +0000)
committerMarijn van Vliet <marijn.vanvliet@med.kuleuven.be>
Tue, 11 May 2010 00:27:59 +0000 (00:27 +0000)
git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@271 ddfedd41-794f-dd11-ae45-00112f111e67

libchimara/input.c
libchimara/pager.c
libchimara/pager.h
libchimara/strio.c
libchimara/window.c

index a4511dc57306e6fc2dec661f5496d568b11c8fbf..43ed0453ddcc56a43394809eac0af3e916371884 100644 (file)
@@ -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;
index a8904cf2a9cf2bb4bcc808ce1e25779301cf9596..c88ab63630c3918478e7c1d75027af4a85307175 100644 (file)
@@ -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);
+}
index 3ee35d812d6aa4efc85b44b9e060790bb9b19952..7353b3fc87c66ad079cc18bfcf9a531a51c885e6 100644 (file)
@@ -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
index ea9d7b5d5128a33d5a68a3ab93c367a1d294ae39..d0404931508a1d70d87e0842129b59542d24ff54 100644 (file)
@@ -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;
 
index 782acd1395232c54da35c7faa7550f6658468fc8..77c916e97f1cfa7aa4eae6f346719a107d878f6a 100644 (file)
@@ -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 );