From 06fe34a85d02df941da86e34cd1d88ef9da52a18 Mon Sep 17 00:00:00 2001 From: Kristian Rietveld Date: Sun, 17 Feb 2013 13:08:14 +0100 Subject: [PATCH 34/68] Do not start overshooting for legacy mouse scroll events Doing overshooting properly relies on the detection of gestures. For legacy devices that do emit precise deltas but no (gesture) phase, simply disallow overshooting so that the state machine does not get stuck. --- gtk/gtkscrolledwindow.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index 77bb5af..4159af8 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -2141,7 +2141,12 @@ gtk_scrolled_window_scroll_event (GtkWidget *widget, gint old_overshoot_x, old_overshoot_y; gboolean start_snap_back = FALSE; gboolean is_overshot = FALSE; - gboolean is_momentum_event = event->phase == GDK_EVENT_SCROLL_PHASE_NONE; + gboolean is_momentum_event = event->momentum_phase != GDK_EVENT_SCROLL_PHASE_NONE; + gboolean legacy_mouse = FALSE; + + if (event->phase == GDK_EVENT_SCROLL_PHASE_NONE && + event->momentum_phase == GDK_EVENT_SCROLL_PHASE_NONE) + legacy_mouse = TRUE; _gtk_scrolled_window_get_overshoot (scrolled_window, &old_overshoot_x, &old_overshoot_y); @@ -2150,10 +2155,12 @@ gtk_scrolled_window_scroll_event (GtkWidget *widget, if (old_overshoot_x != 0 || old_overshoot_y != 0) is_overshot = TRUE; - /* If a new gesture has started, reset snap back state. + /* If a new gesture has started or we detect the end of a momentum + * phase, reset snap back state. * FIXME: check if overshoot has really ended. */ - if (event->phase == GDK_EVENT_SCROLL_PHASE_START) + if (event->momentum_phase == GDK_EVENT_SCROLL_PHASE_END || + event->phase == GDK_EVENT_SCROLL_PHASE_START) { priv->is_snapping_back = FALSE; priv->gesture_in_progress = TRUE; @@ -2193,8 +2200,9 @@ gtk_scrolled_window_scroll_event (GtkWidget *widget, */ adj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->hscrollbar)); gdouble max_adj = gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj); - if (gtk_adjustment_get_value (adj) < 1.0 || - gtk_adjustment_get_value (adj) > max_adj - 1.0) + if (!legacy_mouse && + (gtk_adjustment_get_value (adj) < 1.0 || + gtk_adjustment_get_value (adj) > max_adj - 1.0)) may_overshoot = TRUE; if (scrolled_window->hscrollbar_visible && (is_overshot || may_overshoot)) @@ -2240,8 +2248,9 @@ gtk_scrolled_window_scroll_event (GtkWidget *widget, */ adj = gtk_range_get_adjustment (GTK_RANGE (scrolled_window->vscrollbar)); gdouble max_adj = gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj); - if (gtk_adjustment_get_value (adj) < 1.0 || - gtk_adjustment_get_value (adj) > max_adj - 1.0) + if (!legacy_mouse && + (gtk_adjustment_get_value (adj) < 1.0 || + gtk_adjustment_get_value (adj) > max_adj - 1.0)) may_overshoot = TRUE; if (scrolled_window->vscrollbar_visible && (is_overshot || may_overshoot)) -- 1.7.10.2 (Apple Git-33)