[evince] libview: Handle adjustment change during drag event



commit 38131b9f8bb70e13e4fccadf91636f7ce6d040d9
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 f77a39d4..ba56c0cc 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 eda8c0c7..a0b16146 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -5659,6 +5659,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,
@@ -5669,6 +5674,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;
                }
 
@@ -8012,6 +8019,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]