summaryrefslogtreecommitdiff
path: root/libview/ev-view.c
diff options
context:
space:
mode:
authorXiao-Long Chen <[email protected]>2012-10-11 14:55:48 -0400
committerraveit65 <[email protected]>2017-08-18 21:18:30 +0200
commitab44eb6f7808eaf9fddbf6a248cd227122593d5b (patch)
treeff1ec5841d1a49db10cca192c604afa68a79f6b2 /libview/ev-view.c
parentd4a003784ca37950a2c5bd0ccb5289807e834ce6 (diff)
downloadatril-ab44eb6f7808eaf9fddbf6a248cd227122593d5b.tar.bz2
atril-ab44eb6f7808eaf9fddbf6a248cd227122593d5b.tar.xz
libview: Enable GDK_SMOOTH_SCROLL events for view
This enables the smooth/kinetic scrolling support found in GTK+ 3.3.18 with the document view, and handles them for the Ctrl+scroll, Shift+scroll, and non-continuous best-fit mode scrolling cases. https://bugzilla.gnome.org/show_bug.cgi?id=674098 origin commit link: https://git.gnome.org/browse/evince/commit/?id=34d0d5d
Diffstat (limited to 'libview/ev-view.c')
-rw-r--r--libview/ev-view.c71
1 files changed, 50 insertions, 21 deletions
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 3a5fefdd..b7a5335e 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -3287,24 +3287,32 @@ ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
EvView *view = EV_VIEW (widget);
guint state;
- if (event->direction == GDK_SCROLL_SMOOTH)
- return FALSE;
-
state = event->state & gtk_accelerator_get_default_mod_mask ();
if (state == GDK_CONTROL_MASK) {
ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
view->zoom_center_x = event->x;
view->zoom_center_y = event->y;
- if (event->direction == GDK_SCROLL_UP ||
- event->direction == GDK_SCROLL_LEFT) {
- if (ev_view_can_zoom_in (view)) {
- ev_view_zoom_in (view);
- }
- } else {
- if (ev_view_can_zoom_out (view)) {
+ switch (event->direction) {
+ case GDK_SCROLL_DOWN:
+ case GDK_SCROLL_RIGHT:
+ if (ev_view_can_zoom_out (view))
ev_view_zoom_out (view);
- }
+ break;
+ case GDK_SCROLL_UP:
+ case GDK_SCROLL_LEFT:
+ if (ev_view_can_zoom_in (view))
+ ev_view_zoom_in (view);
+ break;
+ case GDK_SCROLL_SMOOTH: {
+ gdouble delta = event->delta_x + event->delta_y;
+ gdouble factor = pow (delta < 0 ? ZOOM_IN_FACTOR : ZOOM_OUT_FACTOR, fabs (delta));
+
+ if ((factor < 1.0 && ev_view_can_zoom_out (view)) ||
+ (factor >= 1.0 && ev_view_can_zoom_in (view)))
+ ev_view_zoom (view, factor);
+ }
+ break;
}
return TRUE;
@@ -3322,6 +3330,13 @@ ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
event->direction = GDK_SCROLL_RIGHT;
else if (event->direction == GDK_SCROLL_RIGHT)
event->direction = GDK_SCROLL_DOWN;
+ else if (event->direction == GDK_SCROLL_SMOOTH) {
+ /* Swap the deltas for perpendicular direction */
+ gdouble tmp_delta = event->delta_x;
+
+ event->delta_x = event->delta_y;
+ event->delta_y = tmp_delta;
+ }
event->state &= ~GDK_SHIFT_MASK;
state &= ~GDK_SHIFT_MASK;
@@ -3329,16 +3344,29 @@ ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
if (state == 0 && view->sizing_mode == EV_SIZING_BEST_FIT && !view->continuous) {
switch (event->direction) {
- case GDK_SCROLL_DOWN:
- case GDK_SCROLL_RIGHT:
- ev_view_next_page (view);
- break;
- case GDK_SCROLL_UP:
- case GDK_SCROLL_LEFT:
- ev_view_previous_page (view);
- break;
- case GDK_SCROLL_SMOOTH:
- g_assert_not_reached ();
+ case GDK_SCROLL_DOWN:
+ case GDK_SCROLL_RIGHT:
+ ev_view_next_page (view);
+ break;
+ case GDK_SCROLL_UP:
+ case GDK_SCROLL_LEFT:
+ ev_view_previous_page (view);
+ break;
+ case GDK_SCROLL_SMOOTH: {
+ gdouble decrement;
+
+ /* Emulate normal scrolling by summing the deltas */
+ view->total_delta += event->delta_x + event->delta_y;
+
+ decrement = view->total_delta < 0 ? -1.0 : 1.0;
+ for (; fabs (view->total_delta) >= 1.0; view->total_delta -= decrement) {
+ if (decrement < 0)
+ ev_view_previous_page (view);
+ else
+ ev_view_next_page (view);
+ }
+ }
+ break;
}
return TRUE;
@@ -5042,6 +5070,7 @@ ev_view_init (EvView *view)
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_SCROLL_MASK |
+ GDK_SMOOTH_SCROLL_MASK |
GDK_KEY_PRESS_MASK |
GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK |