[zathura] some fixes for the new synctex forward search

2014-01-17 Thread Abdó Roig-Maranges

Hi,

I attach some small fixes for the new synctex forward search functionality.

Abdó.

From 922361bab36aef469766806cca12974e442ce99a Mon Sep 17 00:00:00 2001
From: Abdo Roig-Maranges abdo.r...@gmail.com
Date: Fri, 17 Jan 2014 12:52:05 +0100
Subject: [PATCH 1/4] fix page range check

In those cases, page is in the range [1...N], both ends included.
---
 dbus-interface.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/dbus-interface.c b/dbus-interface.c
index 569d83a..d145106 100644
--- a/dbus-interface.c
+++ b/dbus-interface.c
@@ -255,7 +255,7 @@ handle_method_call(GDBusConnection* UNUSED(connection),
 g_variant_get(parameters, (i), page);
 
 bool ret = true;
-if (page  1 || (unsigned int)page = number_of_pages) {
+if (page  1 || (unsigned int)page  number_of_pages) {
   ret = false;
 } else {
   page_set(priv-zathura, page - 1);
@@ -270,7 +270,7 @@ handle_method_call(GDBusConnection* UNUSED(connection),
 g_variant_get(parameters, (ia()a(i)), page, iter,
 secondary_iter);
 
-if (page  1 || (unsigned int)page = number_of_pages) {
+if (page  1 || (unsigned int)page  number_of_pages) {
   GVariant* result = g_variant_new((b), false);
   g_variant_iter_free(iter);
   g_variant_iter_free(secondary_iter);
-- 
1.8.5.3


From b77b32259b6b0ecfed298102e0a1878625773263 Mon Sep 17 00:00:00 2001
From: Abdo Roig-Maranges abdo.r...@gmail.com
Date: Fri, 17 Jan 2014 13:09:10 +0100
Subject: [PATCH 2/4] fix rectangles subindex. Need page not 0

---
 dbus-interface.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/dbus-interface.c b/dbus-interface.c
index d145106..e8e55e5 100644
--- a/dbus-interface.c
+++ b/dbus-interface.c
@@ -169,7 +169,7 @@ highlight_rects(zathura_t* zathura, unsigned int page,
 
   document_draw_search_results(zathura, true);
 
-  if (rectangles[0] == NULL || girara_list_size(rectangles[0]) == 0) {
+  if (rectangles[page] == NULL || girara_list_size(rectangles[page]) == 0) {
 page_set(zathura, page);
 return;
   }
@@ -192,7 +192,8 @@ highlight_rects(zathura_t* zathura, unsigned int page,
   unsigned int doc_width = 0;
   zathura_document_get_document_size(zathura-document, doc_height, doc_width);
 
-  zathura_rectangle_t* rectangle = girara_list_nth(rectangles[0], 0);
+  zathura_rectangle_t* rectangle = girara_list_nth(rectangles[page], 0);
+
   pos_y += (rectangle-y1 - (double)cell_height/2) / (double)doc_height;
   if (search_hadjust == true) {
 pos_x += (rectangle-x1 - (double)cell_width/2) / (double)doc_width;
-- 
1.8.5.3


From 7874948b7b7dd00a1dc2b04c800381bc64dac397 Mon Sep 17 00:00:00 2001
From: Abdo Roig-Maranges abdo.r...@gmail.com
Date: Fri, 17 Jan 2014 13:35:11 +0100
Subject: [PATCH 3/4] properly scale and rotate rectangle

---
 dbus-interface.c | 9 ++---
 shortcuts.c  | 1 +
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/dbus-interface.c b/dbus-interface.c
index e8e55e5..1f780dd 100644
--- a/dbus-interface.c
+++ b/dbus-interface.c
@@ -192,11 +192,14 @@ highlight_rects(zathura_t* zathura, unsigned int page,
   unsigned int doc_width = 0;
   zathura_document_get_document_size(zathura-document, doc_height, doc_width);
 
-  zathura_rectangle_t* rectangle = girara_list_nth(rectangles[page], 0);
+  /* Need to adjust rectangle to page scale and orientation */
+  zathura_page_t* doc_page = zathura_document_get_page(zathura-document, page);
+  zathura_rectangle_t* rect = girara_list_nth(rectangles[page], 0);
+  zathura_rectangle_t rectangle = recalc_rectangle(doc_page, *rect);
 
-  pos_y += (rectangle-y1 - (double)cell_height/2) / (double)doc_height;
+  pos_y += (rectangle.y1 - (double)cell_height/2) / (double)doc_height;
   if (search_hadjust == true) {
-pos_x += (rectangle-x1 - (double)cell_width/2) / (double)doc_width;
+pos_x += (rectangle.x1 - (double)cell_width/2) / (double)doc_width;
   }
 
   /* move to position */
diff --git a/shortcuts.c b/shortcuts.c
index 7e76235..a067dac 100644
--- a/shortcuts.c
+++ b/shortcuts.c
@@ -917,6 +917,7 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
 g_object_set(page_widget, search-current, target_idx, NULL);
 g_object_get(page_widget, search-results, results, NULL);
 
+/* Need to adjust rectangle to page scale and orientation */
 zathura_rectangle_t* rect = girara_list_nth(results, target_idx);
 zathura_rectangle_t rectangle = recalc_rectangle(target_page, *rect);
 
-- 
1.8.5.3


From d3926da7fd7d3eb6b9742e7b23c238d99151dcf6 Mon Sep 17 00:00:00 2001
From: Abdo Roig-Maranges abdo.r...@gmail.com
Date: Fri, 17 Jan 2014 13:40:51 +0100
Subject: [PATCH 4/4] align highlighted rectangles correctly

Align center of the rectangle with the center of the viewport, vor both
keyword searches and synctex forward search.
---
 dbus-interface.c | 9 +++--
 shortcuts.c  | 8 ++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/dbus-interface.c 

Re: [zathura] some fixes for the new synctex forward search

2014-01-17 Thread Abdó Roig-Maranges

abdo.r...@gmail.com writes:

 Hi,

 Thanks for the patches. Unfortunately, they do not apply (starting with
 patch 2).

 Oops, sorry about that. I missed the first commit in the series. I attach the
 missing piece, which now should apply on top of current develop branch.

And now I attach a non-empty patch. Again, sorry.

Abdó.

From e0528d45d7108730ec9df0b6ce2d7b58b5a32b7a Mon Sep 17 00:00:00 2001
From: Abdo Roig-Maranges abdo.r...@gmail.com
Date: Fri, 17 Jan 2014 17:53:28 +0100
Subject: [PATCH] honor search-hadjust setting in synctex forward search

---
 dbus-interface.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/dbus-interface.c b/dbus-interface.c
index ce9ea64..356def7 100644
--- a/dbus-interface.c
+++ b/dbus-interface.c
@@ -9,6 +9,7 @@
 #include utils.h
 #include adjustment.h
 
+#include girara/session.h
 #include girara/utils.h
 #include gio/gio.h
 #include sys/types.h
@@ -173,6 +174,9 @@ highlight_rects(zathura_t* zathura, unsigned int page,
 return;
   }
 
+  bool search_hadjust = true;
+  girara_setting_get(zathura-ui.session, search-hadjust, search_hadjust);
+
   /* compute the position of the center of the page */
   double pos_x = 0;
   double pos_y = 0;
@@ -199,7 +203,9 @@ highlight_rects(zathura_t* zathura, unsigned int page,
   double center_y = (rectangle.y1 + rectangle.y2) / 2;
 
   pos_y += (center_y - (double)cell_height/2) / (double)doc_height;
-  pos_x += (center_x - (double)cell_width/2) / (double)doc_width;
+  if (search_hadjust == true) {
+pos_x += (center_x - (double)cell_width/2) / (double)doc_width;
+  }
 
   /* move to position */
   zathura_jumplist_add(zathura);
-- 
1.8.5.3

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