[evince/gnome-3-28] libview: Handle adjustment change during drag event



commit f0818c0d19c533236c7ea259977210b2eab42129
Author: Jason Crain <jcrain src gnome org>
Date:   Sun Oct 21 15:10:07 2018 -0600

    libview: Handle adjustment change during drag event
    
    If you zoom in or out while using middle-click drag to scroll the
    document, evince may unexpectedly jump to a different page. This is
    because the zoom operation changes the adjustment's `upper` and `value`
    to account for the document's new size while keeping the visible part of
    the document visible, but the drag event will overwrite the adjustment
    value next time the mouse is moved.
    
    Fix this by updating the drag start position so that the drag can
    continue from the new location.

 libview/ev-view-private.h |  1 +
 libview/ev-view.c         | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
---
diff --git a/libview/ev-view-private.h b/libview/ev-view-private.h
index 7bf9adc5..2cdbf066 100644
--- a/libview/ev-view-private.h
+++ b/libview/ev-view-private.h
@@ -47,6 +47,7 @@ typedef struct {
        guint release_timeout_id;
        GdkPoint buffer[DRAG_HISTORY];
        GdkPoint momentum;
+       gboolean in_notify;
 } DragInfo;
 
 /* Autoscrolling */
diff --git a/libview/ev-view.c b/libview/ev-view.c
index d0f9894a..f71ef9a2 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -5615,6 +5615,11 @@ ev_view_motion_notify_event (GtkWidget      *widget,
                        dvadj_value = gtk_adjustment_get_page_size (view->vadjustment) *
                                      (gdouble)dy / allocation.height;
 
+                       /* We will update the drag event's start position if
+                        * the adjustment value is changed, but only if the
+                        * change was not caused by this function. */
+                       view->drag_info.in_notify = TRUE;
+
                        /* clamp scrolling to visible area */
                        gtk_adjustment_set_value (view->hadjustment,
                                                  MIN (view->drag_info.hadj - dhadj_value,
@@ -5625,6 +5630,8 @@ ev_view_motion_notify_event (GtkWidget      *widget,
                                                       gtk_adjustment_get_upper (view->vadjustment) -
                                                       gtk_adjustment_get_page_size (view->vadjustment)));
 
+                       view->drag_info.in_notify = FALSE;
+
                        return TRUE;
                }
 
@@ -7821,6 +7828,13 @@ on_adjustment_value_changed (GtkAdjustment *adjustment,
        if (!gtk_widget_get_realized (widget))
                return;
 
+       /* If the adjustment value is set during a drag event, update the drag
+        * start position so it can continue from the new location. */
+       if (view->drag_info.in_drag && !view->drag_info.in_notify) {
+               view->drag_info.hadj += gtk_adjustment_get_value (view->hadjustment) - view->scroll_x;
+               view->drag_info.vadj += gtk_adjustment_get_value (view->vadjustment) - view->scroll_y;
+       }
+
        if (view->hadjustment) {
                value = (gint) gtk_adjustment_get_value (view->hadjustment);
                dx = view->scroll_x - value;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]