[gtk/wip/carlosg/fixes] gtkscrolledwindow: Add fixed multiplier to scroll events in surface units




commit c68247f63ba1db8849eb1679e53a64f7f2633973
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Aug 5 17:13:28 2022 +0200

    gtkscrolledwindow: Add fixed multiplier to scroll events in surface units
    
    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 | 11 +++++++++++
 1 file changed, 11 insertions(+)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index d2768d3ae0..518e0a4412 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -201,6 +201,8 @@
 /* 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,


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