Discussion:
[zathura] [Zathura PATCH 2/2 v2] Hide the inputbar and completion menu before saving the adjustments ratios into a new jump structure
Marwan Tanager
2013-06-21 07:45:53 UTC
Permalink
ince we are now saving the adjustments ratios in the jump structures, we need
to take care of the following scenario:

- We do an action that results in a new jump structure being added to the
jumplist while the inputbar is visible (e.g., search, jumping to a
specific page, jumping to a bookmark, or following a link).

- Since we are now storing the adjustments ratios in the jump structures,
all of the above actions would result in the vertical adjustment ratio
being saved while the inputbar and/or the completion menu is visible.

- Now we are exactly on the target of the jump (note that the inputbar and
completion menu now are hidden), so suppose that we want to go back using
^o (assuming that we didn't change the adjustments after jumping), then
the check at sc_jumplist that compares the current adjustments ratios
with that of the current jump (the jump that has just been added and
which we are currently on it's position) would fail, because after the
inputbar (with possibly the completion menu in case of bookmarks) is
activated it is hidden, which results in the vertical adjustment upper
bound to change, which in turn results in the vertical adjustment ratio
returned by zathura_adjustment_get_ratio to become different from what is
stored in the current jump structure, even though we haven't changed the
adjustments at all after the jump. This would always result in taking us
back to the exact position of the jump (which would be slightly different
from the current position) when we press ^o. This can be annoying,
because it would happen, for example, every time we need to go back
quickly after jumping to a link target, a search result, or a bookmark.

So, what this patch does is essentially to make the vertical adjustment ratio
reflecting the current vertical adjustment after a jump, to always be the same
as the one stored in the newly added jump structure, since both are calculated
with zathura_adjustment_get_ratio while the inputbar is _not_ visible, so they
should be the same.

I've elaborated just to make things clear, in case the purpose of the patch
isn't obvious.

---
zathura.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

diff --git a/zathura.c b/zathura.c
index a82fb55..edf284a 100644
--- a/zathura.c
+++ b/zathura.c
@@ -13,6 +13,7 @@
#include <girara/session.h>
#include <girara/statusbar.h>
#include <girara/settings.h>
+#include <girara/shortcuts.h>
#include <glib/gstdio.h>
#include <glib/gi18n.h>

@@ -1145,6 +1146,25 @@ position_set(zathura_t* zathura, double position_x, double position_y)
}
}

+static void
+zathura_jumplist_hide_inputbar(zathura_t* zathura)
+{
+ g_return_if_fail(zathura != NULL && zathura->ui.session->gtk.inputbar != NULL);
+
+ girara_argument_t arg = { GIRARA_HIDE, NULL };
+ girara_isc_completion(zathura->ui.session, &arg, NULL, 0);
+
+ if (zathura->ui.session->global.autohide_inputbar == true) {
+ gtk_widget_hide(zathura->ui.session->gtk.inputbar);
+ }
+
+ /* we want to do it immediately */
+
+ while (gtk_events_pending()) {
+ gtk_main_iteration();
+ }
+}
+
bool
zathura_jumplist_has_previous(zathura_t* zathura)
{
@@ -1254,11 +1274,14 @@ zathura_jumplist_add(zathura_t* zathura)
static void
zathura_jumplist_save(zathura_t* zathura)
{
+ g_return_if_fail(zathura != NULL);
+
zathura_jump_t* cur = zathura_jumplist_current(zathura);

unsigned int pagenum = zathura_document_get_current_page_number(zathura->document);

if (cur) {
+ zathura_jumplist_hide_inputbar(zathura);
cur->page = pagenum;
cur->x = zathura_adjustment_get_ratio(gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)));
cur->y = zathura_adjustment_get_ratio(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)));
--
1.7.10.4
Loading...