From 8e9631946d2863b7f7c5260cff3d1413c38b1621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abd=C3=B3=20Roig-Maranges?= Date: Thu, 16 Aug 2012 18:41:31 +0200 Subject: [PATCH] Option to keep horizontal position when following internal links Added config parameter "link-hadjust" with default value true. When set to false, following internal links do not change the horizontal position of the page, only the vertical position. Also updates page number when following links, now. Signed-off-by: Sebastian Ramacher --- config.c | 2 ++ links.c | 22 +++++++++++++++------- zathura.c | 10 ++++++++-- zathurarc.5.rst | 7 +++++++ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/config.c b/config.c index 8c65cf8..92c3bef 100644 --- a/config.c +++ b/config.c @@ -186,6 +186,8 @@ config_load_default(zathura_t* zathura) bool_value = false; girara_setting_add(gsession, "zoom-center", &bool_value, BOOLEAN, false, _("Horizontally centered zoom"), NULL, NULL); bool_value = true; + girara_setting_add(gsession, "link-hadjust", &bool_value, BOOLEAN, false, _("Align link target to the left"), NULL, NULL); + bool_value = true; girara_setting_add(gsession, "search-hadjust", &bool_value, BOOLEAN, false, _("Center result horizontally"), NULL, NULL); float_value = 0.5; girara_setting_add(gsession, "highlight-transparency", &float_value, FLOAT, false, _("Transparency for highlighting"), NULL, NULL); diff --git a/links.c b/links.c index 8ea913a..4ce1487 100644 --- a/links.c +++ b/links.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "links.h" #include "zathura.h" @@ -135,11 +136,8 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link) return; } - zathura_document_set_current_page_number(zathura->document, link->target.page_number); - - /* get page offset */ - page_offset_t offset; - page_calculate_offset(zathura, page, &offset); + page_offset_t offset; + page_calculate_offset(zathura, page, &offset); if (link->target.destination_type == ZATHURA_LINK_DESTINATION_XYZ) { if (link->target.left != -1) { @@ -151,8 +149,18 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link) } } - position_set_delayed(zathura, offset.x, offset.y); - statusbar_page_number_update(zathura); + /* jump to the page */ + page_set(zathura, link->target.page_number); + + /* move to the target position */ + bool link_hadjust = true; + girara_setting_get(zathura->ui.session, "link-hadjust", &link_hadjust); + + if (link_hadjust == true) { + position_set_delayed(zathura, offset.x, offset.y); + } else { + position_set_delayed(zathura, -1, offset.y); + } } break; case ZATHURA_LINK_GOTO_REMOTE: diff --git a/zathura.c b/zathura.c index 5e2c3f6..713d9c3 100644 --- a/zathura.c +++ b/zathura.c @@ -1093,8 +1093,14 @@ position_set_delayed_impl(gpointer data) GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(window); GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(window); - zathura_adjustment_set_value(hadjustment, p->position_x); - zathura_adjustment_set_value(vadjustment, p->position_y); + /* negative values mean: don't set the position */ + if (p->position_x >= 0) { + zathura_adjustment_set_value(hadjustment, p->position_x); + } + + if (p->position_y >= 0) { + zathura_adjustment_set_value(vadjustment, p->position_y); + } g_free(p); diff --git a/zathurarc.5.rst b/zathurarc.5.rst index 09854b6..f2ad1e4 100644 --- a/zathurarc.5.rst +++ b/zathurarc.5.rst @@ -640,6 +640,13 @@ Defines if scrolling by half or full pages stops at page boundaries. * Value type: Boolean * Default value: false +link-hadjust +^^^^^^^^^^^^ +En/Disables aligning to the left internal link targets, for example from the index + +* Value type: Boolean +* Default value: true + search-hadjust ^^^^^^^^^^^^^^ En/Disables horizontally centered search results