X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fpager.c;h=a31bb07871fd68a1c6748a7731dc523596be65d2;hb=69f5d79e00333f8986ee27beb053a34b1dab04ba;hp=9fd2b0cbc9c656c183d972ea96340b50ce8df1b8;hpb=e20d9510ba4e742ce4ade114b004d68e6e69f038;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/pager.c b/libchimara/pager.c index 9fd2b0c..a31bb07 100644 --- a/libchimara/pager.c +++ b/libchimara/pager.c @@ -2,6 +2,10 @@ #include "pager.h" +/* Not sure if necessary, but this is the margin within which the pager will +stop paging if it's close to the end of the text buffer */ +#define PAGER_FUZZINESS 1.0 + /* Helper function: move the pager to the last visible position in the buffer, and return the distance between the pager and the end of the buffer in buffer coordinates */ @@ -32,11 +36,6 @@ move_pager_and_get_scroll_distance(GtkTextView *textview, gint *view_height, gin gtk_text_view_get_iter_location(textview, &newpager, &pagerpos); gtk_text_view_get_iter_location(textview, &end, &endpos); - /* - g_printerr("View height = %d\n", visiblerect.height); - g_printerr("End - Pager = %d - %d = %d\n", endpos.y, pagerpos.y, endpos.y - pagerpos.y); - */ - *view_height = visiblerect.height; *scroll_distance = endpos.y - pagerpos.y; } @@ -59,6 +58,20 @@ stop_paging(winid_t win) g_signal_handler_block(win->widget, win->pager_keypress_handler); } +/* Helper function: If the adjustment is at its maximum value, stop paging */ +static void +check_paging(GtkAdjustment *adj, winid_t win) +{ + double page_size, upper, value; + g_object_get(adj, + "page-size", &page_size, + "upper", &upper, + "value", &value, + NULL); + if(value + PAGER_FUZZINESS >= upper - page_size && win->currently_paging) + stop_paging(win); +} + /* When the user scrolls up in a textbuffer, start paging. */ void pager_after_adjustment_changed(GtkAdjustment *adj, winid_t win) @@ -68,12 +81,21 @@ pager_after_adjustment_changed(GtkAdjustment *adj, winid_t win) 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); + return; + } else if(scroll_distance == 0 && win->currently_paging) + { stop_paging(win); - + gtk_widget_queue_draw(win->widget); + return; + } + /* Refresh the widget so that any extra "more" prompts disappear */ gtk_widget_queue_draw(win->widget); + + check_paging(adj, win); } /* Handle key press events in the textview while paging is active */ @@ -94,9 +116,11 @@ pager_on_key_press_event(GtkTextView *textview, GdkEventKey *event, winid_t win) case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down: case GDK_KEY_Return: case GDK_KEY_KP_Enter: gtk_adjustment_set_value(adj, CLAMP(value + page_size, lower, upper - page_size)); + check_paging(adj, win); return TRUE; case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up: gtk_adjustment_set_value(adj, CLAMP(value - page_size, lower, upper - page_size)); + check_paging(adj, win); return TRUE; /* don't handle "up" and "down", they're used for input history */ } @@ -112,16 +136,17 @@ pager_on_expose(GtkTextView *textview, GdkEventExpose *event, winid_t win) gint promptwidth, promptheight; pango_layout_get_pixel_size(win->pager_layout, &promptwidth, &promptheight); - gint winx, winy, winwidth, winheight; + int winx, winy; gdk_window_get_position(event->window, &winx, &winy); - gdk_drawable_get_size(GDK_DRAWABLE(event->window), &winwidth, &winheight); + int winwidth = gdk_window_get_width(event->window); + int winheight = gdk_window_get_height(event->window); /* Draw the 'more' tag */ - GdkGC *context = gdk_gc_new(GDK_DRAWABLE(event->window)); - gdk_draw_layout(event->window, context, - winx + winwidth - promptwidth, - winy + winheight - promptheight, - win->pager_layout); + cairo_t *cr = gdk_cairo_create(event->window); + cairo_move_to(cr, + winx + winwidth - promptwidth, + winy + winheight - promptheight); + pango_cairo_show_layout(cr, win->pager_layout); return FALSE; /* Propagate event further */ }