gtkscrolledwindow: Add fixed multiplier to scroll events in surface units
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 5 Aug 2022 15:13:28 +0000 (17:13 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Sun, 7 Aug 2022 15:16:14 +0000 (17:16 +0200)
The expected configurability is not going to arrive yet from compositors, and
it is precipitate for GTK to gain any configurability. We do know a factor of 1
feels way too slow, and we do know a factor of page_size * pow (2 / 3) feels way
way too fast.

With the previous multiplier, gtk4-demo at its default size had a vertical textview
factor of 64.332901, and maximized on a 1920x1080 screen a factor of 97.585365.
Pick a magic multiplier that is both significantly below these values and above 1,
and stick to it.

Future work will add the configurability of smooth scroll events where it belongs.
At that point this commit may be reverted so we don't pile up on magic numbers again.

Related: https://gitlab.gnome.org/GNOME/gtk/-/issues/4793

gtk/gtkscrolledwindow.c

index d2768d3ae06e245ff33935afec684b4053aec05f..518e0a44125a791bb8e80549147c440fcaf9b311 100644 (file)
 /* Scrolled off indication */
 #define UNDERSHOOT_SIZE 40
 
+#define MAGIC_SCROLL_FACTOR (42 / 7 / 1.618033 * 2.718281)
+
 typedef struct _GtkScrolledWindowClass         GtkScrolledWindowClass;
 
 struct _GtkScrolledWindow
@@ -1376,6 +1378,8 @@ scrolled_window_scroll (GtkScrolledWindow        *scrolled_window,
           delta_x *= get_wheel_detent_scroll_step (scrolled_window,
                                                    GTK_ORIENTATION_HORIZONTAL);
         }
+      else if (scroll_unit == GDK_SCROLL_UNIT_SURFACE)
+        delta_x *= MAGIC_SCROLL_FACTOR;
 
       new_value = priv->unclamped_hadj_value + delta_x;
       _gtk_scrolled_window_set_adjustment_value (scrolled_window, adj,
@@ -1397,6 +1401,8 @@ scrolled_window_scroll (GtkScrolledWindow        *scrolled_window,
           delta_y *= get_wheel_detent_scroll_step (scrolled_window,
                                                    GTK_ORIENTATION_VERTICAL);
         }
+      else if (scroll_unit == GDK_SCROLL_UNIT_SURFACE)
+        delta_y *= MAGIC_SCROLL_FACTOR;
 
       new_value = priv->unclamped_vadj_value + delta_y;
       _gtk_scrolled_window_set_adjustment_value (scrolled_window, adj,
@@ -1471,6 +1477,11 @@ scroll_controller_decelerate (GtkEventControllerScroll *scroll,
       initial_vel_y *= get_wheel_detent_scroll_step (scrolled_window,
                                                      GTK_ORIENTATION_VERTICAL);
     }
+  else
+    {
+      initial_vel_x *= MAGIC_SCROLL_FACTOR;
+      initial_vel_y *= MAGIC_SCROLL_FACTOR;
+    }
 
   gtk_scrolled_window_decelerate (scrolled_window,
                                   initial_vel_x,