[gtk/wip/carlosg/fix-accumulated-velocity: 49/50] gtkscrolledwindow: Do not trigger kinetic helpers on 0 velocity




commit eab1499e20034fb9f92e3e64c2bcefd7bc20feb0
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Mar 15 22:41:27 2022 +0100

    gtkscrolledwindow: Do not trigger kinetic helpers on 0 velocity
    
    Doing this is pointless, so it could be skipped.

 gtk/gtkscrolledwindow.c | 54 +++++++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 227e3e2741..db76dae551 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -3371,18 +3371,21 @@ gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window)
       gtk_scrolled_window_accumulate_velocity (&priv->hscrolling, elapsed, &priv->x_velocity);
       g_clear_pointer (&priv->hscrolling, gtk_kinetic_scrolling_free);
 
-      hadjustment = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->hscrollbar));
-      lower = gtk_adjustment_get_lower (hadjustment);
-      upper = gtk_adjustment_get_upper (hadjustment);
-      upper -= gtk_adjustment_get_page_size (hadjustment);
-      priv->hscrolling =
-        gtk_kinetic_scrolling_new (lower,
-                                   upper,
-                                   MAX_OVERSHOOT_DISTANCE,
-                                   DECELERATION_FRICTION,
-                                   OVERSHOOT_FRICTION,
-                                   priv->unclamped_hadj_value,
-                                   priv->x_velocity);
+      if (priv->x_velocity != 0)
+        {
+          hadjustment = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->hscrollbar));
+          lower = gtk_adjustment_get_lower (hadjustment);
+          upper = gtk_adjustment_get_upper (hadjustment);
+          upper -= gtk_adjustment_get_page_size (hadjustment);
+          priv->hscrolling =
+            gtk_kinetic_scrolling_new (lower,
+                                       upper,
+                                       MAX_OVERSHOOT_DISTANCE,
+                                       DECELERATION_FRICTION,
+                                       OVERSHOOT_FRICTION,
+                                       priv->unclamped_hadj_value,
+                                       priv->x_velocity);
+        }
     }
   else
     g_clear_pointer (&priv->hscrolling, gtk_kinetic_scrolling_free);
@@ -3395,18 +3398,21 @@ gtk_scrolled_window_start_deceleration (GtkScrolledWindow *scrolled_window)
       gtk_scrolled_window_accumulate_velocity (&priv->vscrolling, elapsed, &priv->y_velocity);
       g_clear_pointer (&priv->vscrolling, gtk_kinetic_scrolling_free);
 
-      vadjustment = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->vscrollbar));
-      lower = gtk_adjustment_get_lower(vadjustment);
-      upper = gtk_adjustment_get_upper(vadjustment);
-      upper -= gtk_adjustment_get_page_size(vadjustment);
-      priv->vscrolling =
-        gtk_kinetic_scrolling_new (lower,
-                                   upper,
-                                   MAX_OVERSHOOT_DISTANCE,
-                                   DECELERATION_FRICTION,
-                                   OVERSHOOT_FRICTION,
-                                   priv->unclamped_vadj_value,
-                                   priv->y_velocity);
+      if (priv->y_velocity != 0)
+        {
+          vadjustment = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (priv->vscrollbar));
+          lower = gtk_adjustment_get_lower(vadjustment);
+          upper = gtk_adjustment_get_upper(vadjustment);
+          upper -= gtk_adjustment_get_page_size(vadjustment);
+          priv->vscrolling =
+            gtk_kinetic_scrolling_new (lower,
+                                       upper,
+                                       MAX_OVERSHOOT_DISTANCE,
+                                       DECELERATION_FRICTION,
+                                       OVERSHOOT_FRICTION,
+                                       priv->unclamped_vadj_value,
+                                       priv->y_velocity);
+        }
     }
   else
     g_clear_pointer (&priv->vscrolling, gtk_kinetic_scrolling_free);


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