hej,

second of two. this one was a bit harder to come up with and probably
requires some sort of explanation and definitely a review.

the patch introduces the flag scroll-page-aware which is by default
unset. if set, this modifies the behaviour of full- and half-scrolls:

- if a page boundary is in view, it exactly scrolls it out of view
- if a page boundary would come into view, it stops just before

feels a lot better to me, the idea came from the default pagewise
scrolling in djview4 (on <space> and <backspace>).

i definitely would like to see this feature for full-scrolls at
least. i'm undecided for half-scrolls. more thoughts would be good.

gives a trivial merge conflict if applied before the scroll overlap
patch.

tested on archlinux.

comments welcome.

cheers,
jonas

btw. i signed up to the list, so it's fine if you just answer to the
list without ccing me. but it doesn't matter either way.

>From ca3f80f310feca0dc430e5f30c4bcea856c0a06c Mon Sep 17 00:00:00 2001
From: Jonas Hoersch <co...@online.de>
Date: Sat, 15 Sep 2012 18:00:15 +0200
Subject: [PATCH 2/2] Introduce page aware scrolling

if scroll-page-aware is set, scrolling by full and half pages stops at
page boundaries (as djview4 does it on <space> and <backspace>).
---
 config.c    |  2 ++
 shortcuts.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/config.c b/config.c
index 2687b9d..dda182a 100644
--- a/config.c
+++ b/config.c
@@ -173,6 +173,8 @@ config_load_default(zathura_t* zathura)
   bool_value = false;
   girara_setting_add(gsession, "scroll-wrap",            &bool_value,  BOOLEAN, false, _("Wrap scrolling"), NULL, NULL);
   bool_value = false;
+  girara_setting_add(gsession, "scroll-page-aware",      &bool_value,  BOOLEAN, false, _("Page aware scrolling"), NULL, NULL);
+  bool_value = false;
   girara_setting_add(gsession, "advance-pages-per-row",  &bool_value,  BOOLEAN, false, _("Advance number of pages per row"), NULL, NULL);
   bool_value = false;
   girara_setting_add(gsession, "zoom-center",            &bool_value,  BOOLEAN, false, _("Horizontally centered zoom"), NULL, NULL);
diff --git a/shortcuts.c b/shortcuts.c
index bbb34b0..3425506 100644
--- a/shortcuts.c
+++ b/shortcuts.c
@@ -565,6 +565,8 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument,
   }
   float scroll_full_overlap = 0.1;
   girara_setting_get(session, "scroll-full-overlap", &scroll_full_overlap);
+  bool scroll_page_aware = false;
+  girara_setting_get(session, "scroll-page-aware", &scroll_page_aware);
 
   int padding = 1;
   girara_setting_get(session, "page-padding", &padding);
@@ -610,6 +612,59 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument,
       new_value = value;
   }
 
+  if (scroll_page_aware) {
+    int page_offset;
+    double page_size;
+
+    {
+      unsigned int page_id = zathura_document_get_current_page_number(zathura->document);
+      zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
+      page_offset_t offset;
+      page_calculate_offset(zathura, page, &offset);
+
+      double scale = zathura_document_get_scale(zathura->document);
+
+      if ( (argument->n == LEFT) || (argument->n == FULL_LEFT) || (argument->n == HALF_LEFT) ||
+           (argument->n == RIGHT) || (argument->n == FULL_RIGHT) || (argument->n == HALF_RIGHT)) {
+        page_offset = offset.x;
+        page_size = zathura_page_get_width(page) * scale;
+      } else {
+        page_offset = offset.y;
+        page_size = zathura_page_get_height(page) * scale;
+      }
+
+      page_offset -= padding / 2;
+      page_size   += padding;
+    }
+    
+    if ( (argument->n==FULL_DOWN) || (argument->n==HALF_DOWN) ||
+         (argument->n==FULL_RIGHT) || (argument->n==HALF_RIGHT) )
+      {
+      if ( (page_offset > value) &&
+           (page_offset < value + view_size) )
+        new_value = page_offset;
+      else if ( (page_offset <= value) &&
+                (page_offset + page_size < value + view_size) )
+        new_value = page_offset + page_size + 1;
+      else if ( (page_offset <= value) &&
+                (page_offset + page_size < new_value + view_size) )
+        new_value = page_offset + page_size - view_size + 1;
+      }
+    else if ( (argument->n==FULL_UP) || (argument->n==HALF_UP) ||
+              (argument->n==FULL_LEFT) || (argument->n==HALF_LEFT) )
+      {
+      if ( (page_offset + 1 >= value) &&
+           (page_offset < value + view_size) )
+        new_value = page_offset - view_size;
+      else if ( (page_offset <= value) &&
+                (page_offset + page_size + 1 < value + view_size) )
+        new_value = page_offset + page_size - view_size;
+      else if ( (page_offset <= value) &&
+                (page_offset > new_value) )
+        new_value = page_offset;
+      }
+  }
+
   set_adjustment(adjustment, new_value);
 
   return false;
-- 
1.7.12

_______________________________________________
zathura mailing list
zathura@lists.pwmt.org
http://lists.pwmt.org/mailman/listinfo/zathura

Reply via email to