From 454b356f37cc7835ec8b509ed98355939bccd48f Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sun, 31 Oct 2010 10:11:25 +0100 Subject: [PATCH] Implement wrap-around scrolling (closes #44) Applied a modified version of raylu's patch. One can enable/disable wrap-around scrolling with `set scroll_wrap 1/0". It's disabled per default. --- config.def.h | 2 ++ zathura.c | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/config.def.h b/config.def.h index 5000aa9..9a65d21 100644 --- a/config.def.h +++ b/config.def.h @@ -66,6 +66,7 @@ char* uri_command = "firefox %s"; /* uri */ /* additional settings */ gboolean show_scrollbars = FALSE; +gboolean scroll_wrap = FALSE; int adjust_open = ADJUST_BESTFIT; #define SELECTION_STYLE POPPLER_SELECTION_GLYPH #define GOTO_MODE GOTO_LABELS /* GOTO_DEFAULT, GOTO_LABELS, GOTO_OFFSET */ @@ -245,6 +246,7 @@ Setting settings[] = { {"recolor_darkcolor", &(recolor_darkcolor), 's', FALSE, TRUE, "Recoloring (dark color)"}, {"recolor_lightcolor", &(recolor_lightcolor), 's', FALSE, TRUE, "Recoloring (light color)"}, {"scroll_step", &(scroll_step), 'f', FALSE, FALSE, "Scroll step"}, + {"scroll_wrap", &(scroll_wrap), 'b', FALSE, FALSE, "Wrap scolling at last page"}, {"scrollbars", &(show_scrollbars), 'b', FALSE, TRUE, "Show scrollbars"}, {"show_statusbar", &(Zathura.Global.show_statusbar), 'b', FALSE, TRUE, "Show statusbar"}, {"show_inputbar", &(Zathura.Global.show_inputbar), 'b', FALSE, TRUE, "Show inputbar"}, diff --git a/zathura.c b/zathura.c index 4fb9028..15224e4 100644 --- a/zathura.c +++ b/zathura.c @@ -2092,9 +2092,12 @@ sc_navigate(Argument* argument) int new_page = Zathura.PDF.page_number; if(argument->n == NEXT) - new_page = (new_page + number_of_pages + 1) % number_of_pages; + new_page = scroll_wrap ? (new_page + 1) : ((new_page + 1) % number_of_pages); else if(argument->n == PREVIOUS) - new_page = (new_page + number_of_pages - 1) % number_of_pages; + new_page = scroll_wrap ? (new_page - 1) : ((new_page + number_of_pages - 1) % number_of_pages); + + if (scroll_wrap && (new_page < 0 || new_page >= number_of_pages)) + return; set_page(new_page); update_status(); @@ -2172,12 +2175,16 @@ sc_scroll(Argument* argument) if((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0) { + int old_page = Zathura.PDF.page_number; Argument arg; arg.n = PREVIOUS; sc_navigate(&arg); - arg.n = BOTTOM; - ss = TRUE; - sc_scroll(&arg); + if (!scroll_wrap || (Zathura.PDF.page_number < old_page)) + { + arg.n = BOTTOM; + ss = TRUE; + sc_scroll(&arg); + } return; } else if((argument->n == DOWN || argument->n == HALF_DOWN || argument->n == FULL_DOWN) && value == max)