emacs-diffs
[Top][All Lists]
Advanced

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

master 67191f7: Make momentum scrolling much nicer


From: Po Lu
Subject: master 67191f7: Make momentum scrolling much nicer
Date: Thu, 2 Dec 2021 21:13:44 -0500 (EST)

branch: master
commit 67191f7eee3f2a4e83897c3d820f8c13c629dedb
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Make momentum scrolling much nicer
    
    * lisp/pixel-scroll.el (pixel-scroll-precision-momentum-tick):
    Set default value to 0.01.
    (pixel-scroll-precision-momentum-seconds): New user option.
    (pixel-scroll-start-momentum): Improvements to momentum
    algorithm.
---
 lisp/pixel-scroll.el | 53 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 21 deletions(-)

diff --git a/lisp/pixel-scroll.el b/lisp/pixel-scroll.el
index 00d9bf6..3c764ff 100644
--- a/lisp/pixel-scroll.el
+++ b/lisp/pixel-scroll.el
@@ -109,12 +109,18 @@ This is only effective if supported by your mouse or 
touchpad."
   :type 'boolean
   :version "29.1")
 
-(defcustom pixel-scroll-precision-momentum-tick 0.16
+(defcustom pixel-scroll-precision-momentum-tick 0.01
   "Number of seconds between each momentum scroll."
   :group 'mouse
   :type 'float
   :version "29.1")
 
+(defcustom pixel-scroll-precision-momentum-seconds 1.75
+  "The maximum duration in seconds of momentum scrolling."
+  :group 'mouse
+  :type 'float
+  :version "29.1")
+
 (defcustom pixel-scroll-precision-momentum-factor 0.95
   "Factor by which to reduce scroll velocity on each momentum scroll"
   :group 'mouse
@@ -546,26 +552,31 @@ It is a vector of the form [ VELOCITY TIME ]."
         (setq state (pixel-scroll-kinetic-state))
         (when (and (aref state 1)
                    (listp (aref state 0)))
-          (unwind-protect (progn
-                            (aset state 0
-                                  (/ (pixel-scroll-calculate-velocity state) 
2))
-                            (let ((velocity (* (aref state 0)
-                                               
pixel-scroll-precision-momentum-tick)))
-                              (if (> velocity 0)
-                                  (while (> velocity 1)
-                                    (pixel-scroll-precision-scroll-up (round 
velocity))
-                                    (setq velocity (* velocity
-                                                      
pixel-scroll-precision-momentum-factor))
-                                    (redisplay t)
-                                    (sit-for 
pixel-scroll-precision-momentum-tick)))
-                              (while (< velocity -1)
-                                (pixel-scroll-precision-scroll-down (round 
(abs velocity)))
-                                (setq velocity (* velocity
-                                                  
pixel-scroll-precision-momentum-factor))
-                                (redisplay t)
-                                (sit-for 
pixel-scroll-precision-momentum-tick))))
-            (aset state 0 (make-ring 10))
-            (aset state 1 nil)))))))
+          (while-no-input
+            (unwind-protect (progn
+                              (aset state 0 (pixel-scroll-calculate-velocity 
state))
+                              (let ((velocity (/ (aref state 0) 3))
+                                    (time-spent 0))
+                                (if (> velocity 0)
+                                    (while (and (> velocity 0.2)
+                                                (<= time-spent 
pixel-scroll-precision-momentum-seconds))
+                                      (pixel-scroll-precision-scroll-up 
(ceiling velocity))
+                                      (setq velocity (* velocity 
pixel-scroll-precision-momentum-factor))
+                                      (redisplay t)
+                                      (sit-for 
pixel-scroll-precision-momentum-tick)
+                                      (setq time-spent (+ time-spent
+                                                          
pixel-scroll-precision-momentum-tick))))
+                                (while (and (< velocity -0.4)
+                                            (<= time-spent
+                                                
pixel-scroll-precision-momentum-seconds))
+                                  (pixel-scroll-precision-scroll-down (floor 
(abs velocity)))
+                                  (setq velocity (* velocity 
pixel-scroll-precision-momentum-factor))
+                                  (redisplay t)
+                                  (sit-for 
pixel-scroll-precision-momentum-tick)
+                                  (setq time-spent (+ time-spent
+                                                      
pixel-scroll-precision-momentum-tick)))))
+              (aset state 0 (make-ring 10))
+              (aset state 1 nil))))))))
 
 ;;;###autoload
 (define-minor-mode pixel-scroll-precision-mode



reply via email to

[Prev in Thread] Current Thread [Next in Thread]