From 633889f291db6169cd6899817c9d749e6fd8165a Mon Sep 17 00:00:00 2001 From: Abdo Roig-Maranges Date: Fri, 17 Jan 2014 13:40:51 +0100 Subject: [PATCH] align highlighted rectangles correctly Align center of the rectangle with the center of the viewport, vor both keyword searches and synctex forward search. Signed-off-by: Sebastian Ramacher --- dbus-interface.c | 9 +++++++-- shortcuts.c | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dbus-interface.c b/dbus-interface.c index 9819743..ce9ea64 100644 --- a/dbus-interface.c +++ b/dbus-interface.c @@ -193,8 +193,13 @@ highlight_rects(zathura_t* zathura, unsigned int 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_x += (rectangle.x1 - (double)cell_width/2) / (double)doc_width; + /* compute the center of the rectangle, which will be aligned to the center + of the viewport */ + double center_x = (rectangle.x1 + rectangle.x2) / 2; + 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; /* move to position */ zathura_jumplist_add(zathura); diff --git a/shortcuts.c b/shortcuts.c index a067dac..0f5c807 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -940,10 +940,14 @@ sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int doc_width = 0; zathura_document_get_document_size(zathura->document, &doc_height, &doc_width); - pos_y += (rectangle.y1 - (double)cell_height/2) / (double)doc_height; + /* compute the center of the rectangle, which will be aligned to the center + of the viewport */ + double center_x = (rectangle.x1 + rectangle.x2) / 2; + double center_y = (rectangle.y1 + rectangle.y2) / 2; + pos_y += (center_y - (double)cell_height/2) / (double)doc_height; if (search_hadjust == true) { - pos_x += (rectangle.x1 - (double)cell_width/2) / (double)doc_width; + pos_x += (center_x - (double)cell_width/2) / (double)doc_width; } /* move to position */