This patch eliminates the aforementioned problems by setting the adjustment 
ratio dynamically from the 'value-changed' callback only if the vertical 
adjustment upper bound hasn't changed. If it's found to be changed, this means 
that the document scale have changed (e.g due to zooming or resizing the 
window) so the adjustment ratio shouldn't be updated. Otherwise, we assume that 
the adjustment value has been changed as a result of scrolling or jumping to a 
specific page.

Of course it's just a draft, but you can generalize it to account for the 
horizontal adjustment as well as the adjustments lower bounds. IMO, the 
adjustment_ratio struct could now be called something like 'struct adjustments' 
with possibly two substructures for the horizontal and vertical adjustments 
each containing the ratio and the upper/lower bounds, but of course it's your 
patch in the first place so you are free to arrange things as you see fit.

---
 callbacks.c |    5 +++++
 document.c  |   13 +++++++++++++
 document.h  |    3 +++
 utils.c     |    1 +
 zathura.c   |    3 +++
 5 files changed, 25 insertions(+)

diff --git a/callbacks.c b/callbacks.c
index 59123f8..7dea733 100644
--- a/callbacks.c
+++ b/callbacks.c
@@ -105,6 +105,10 @@ cb_view_vadjustment_value_changed(GtkAdjustment* 
GIRARA_UNUSED(adjustment), gpoi
     zathura_page_widget_update_view_time(ZATHURA_PAGE(page_widget));
   }
 
+  if (zathura_document_get_adj_upper(zathura->document) == 
gtk_adjustment_get_upper(view_vadjustment)) {
+    readjust_view_after_zooming(zathura);
+  }
+
   statusbar_page_number_update(zathura);
 }
 
@@ -149,6 +153,7 @@ cb_view_vadjustment_changed(GtkAdjustment* adjustment, 
gpointer data)
 
   double ratio = zathura_document_get_vadjustment_ratio(zathura->document);
   set_adjustment_from_ratio(adjustment, ratio);
+  zathura_document_set_adj_upper(zathura->document, 
gtk_adjustment_get_upper(adjustment));
 }
 
 void
diff --git a/document.c b/document.c
index b992010..49f6420 100644
--- a/document.c
+++ b/document.c
@@ -51,6 +51,7 @@ struct zathura_document_s {
   struct {
     double horizontal; /**< Horizontal adjustment ratio */
     double vertical; /**< Vertical adjustment ratio */
+    double vertical_adj_upper;
   } adjustment_ratio;
 
   /**
@@ -423,6 +424,18 @@ zathura_document_set_adjustment_ratios(zathura_document_t* 
document,
   document->adjustment_ratio.vertical   = vadjustment_ratio;
 }
 
+void zathura_document_set_adj_upper(zathura_document_t* document, double upper)
+{
+  g_return_if_fail(document != NULL);
+  document->adjustment_ratio.vertical_adj_upper = upper;
+}
+
+double zathura_document_get_adj_upper(zathura_document_t* document)
+{
+  g_return_val_if_fail(document != NULL, 0.0);
+  return document->adjustment_ratio.vertical_adj_upper;
+}
+
 void
 zathura_document_get_cell_size(zathura_document_t* document,
                                unsigned int* height, unsigned int* width)
diff --git a/document.h b/document.h
index b8c3426..2f3bd90 100644
--- a/document.h
+++ b/document.h
@@ -191,6 +191,9 @@ void 
zathura_document_set_adjustment_ratios(zathura_document_t* document,
                                             double hadjustment_ratio,
                                             double vadjustment_ratio);
 
+double zathura_document_get_adj_upper(zathura_document_t* document);
+void zathura_document_set_adj_upper(zathura_document_t* document, double 
upper);
+
 /**
  * Returns the private data of the document
  *
diff --git a/utils.c b/utils.c
index c402512..47124b2 100644
--- a/utils.c
+++ b/utils.c
@@ -372,6 +372,7 @@ readjust_view_after_zooming(zathura_t *zathura)
   zathura_document_set_adjustment_ratios(zathura->document,
       compute_adjustment_ratio(hadjustment),
       compute_adjustment_ratio(vadjustment));
+  zathura_document_set_adj_upper(zathura->document, 
gtk_adjustment_get_upper(vadjustment));
 }
 
 void
diff --git a/zathura.c b/zathura.c
index 351ffed..d2815be 100644
--- a/zathura.c
+++ b/zathura.c
@@ -743,6 +743,9 @@ document_open(zathura_t* zathura, const char* path, const 
char* password,
     cb_view_vadjustment_value_changed(NULL, zathura);
   }
 
+  GtkAdjustment* view_vadjustment = 
gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
+  zathura_document_set_adj_upper(zathura->document, 
gtk_adjustment_get_upper(view_vadjustment));
+
   return true;
 
 error_free:
-- 
1.7.10.4

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

Reply via email to