emacs-diffs
[Top][All Lists]
Advanced

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

master 40c0124816: Minor improvements to precision scroll interpolation


From: Po Lu
Subject: master 40c0124816: Minor improvements to precision scroll interpolation
Date: Fri, 29 Jul 2022 23:26:58 -0400 (EDT)

branch: master
commit 40c0124816969985d00cb7edf55859ef2264d332
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Minor improvements to precision scroll interpolation
    
    * lisp/pixel-scroll.el (pixel-scroll-start-momentum): Bump GC
    cons threshold temporarily.  This leads to a very noticable
    improvement to animation speed.
---
 lisp/pixel-scroll.el | 77 +++++++++++++++++++++++++++-------------------------
 1 file changed, 40 insertions(+), 37 deletions(-)

diff --git a/lisp/pixel-scroll.el b/lisp/pixel-scroll.el
index fc7e680c26..aefe3c12dc 100644
--- a/lisp/pixel-scroll.el
+++ b/lisp/pixel-scroll.el
@@ -759,6 +759,9 @@ It is a vector of the form [ VELOCITY TIME SIGN ]."
   (interactive "e")
   (when pixel-scroll-precision-use-momentum
     (let ((window (mwheel-event-window event))
+          ;; The animations are smoother if the GC threshold is
+          ;; reduced for the duration of the animation.
+          (gc-cons-threshold (* gc-cons-threshold 3))
           (state nil))
       (when (framep window)
         (setq window (frame-selected-window window)))
@@ -767,43 +770,43 @@ It is a vector of the form [ VELOCITY TIME SIGN ]."
                  (listp (aref state 0)))
         (condition-case nil
             (while-no-input
-              (unwind-protect (progn
-                                (aset state 0 (pixel-scroll-calculate-velocity 
state))
-                                (when (> (abs (aref state 0))
-                                         
pixel-scroll-precision-momentum-min-velocity)
-                                  (let* ((velocity (aref state 0))
-                                         (original-velocity velocity)
-                                         (time-spent 0))
-                                    (if (> velocity 0)
-                                        (while (and (> velocity 0)
-                                                    (<= time-spent
-                                                        
pixel-scroll-precision-momentum-seconds))
-                                          (when (> (round velocity) 0)
-                                            (with-selected-window window
-                                              
(pixel-scroll-precision-scroll-up (round velocity))))
-                                          (setq velocity (- velocity
-                                                            (/ 
original-velocity
-                                                               (/ 
pixel-scroll-precision-momentum-seconds
-                                                                  
pixel-scroll-precision-momentum-tick))))
-                                          (redisplay t)
-                                          (sit-for 
pixel-scroll-precision-momentum-tick)
-                                          (setq time-spent (+ time-spent
-                                                              
pixel-scroll-precision-momentum-tick))))
-                                    (while (and (< velocity 0)
-                                                (<= time-spent
-                                                    
pixel-scroll-precision-momentum-seconds))
-                                      (when (> (round (abs velocity)) 0)
-                                        (with-selected-window window
-                                          (pixel-scroll-precision-scroll-down 
(round
-                                                                               
(abs velocity)))))
-                                      (setq velocity (+ velocity
-                                                        (/ (abs 
original-velocity)
-                                                           (/ 
pixel-scroll-precision-momentum-seconds
-                                                              
pixel-scroll-precision-momentum-tick))))
-                                      (redisplay t)
-                                      (sit-for 
pixel-scroll-precision-momentum-tick)
-                                      (setq time-spent (+ time-spent
-                                                          
pixel-scroll-precision-momentum-tick))))))
+              (unwind-protect
+                  (progn
+                    (aset state 0 (pixel-scroll-calculate-velocity state))
+                    (when (> (abs (aref state 0))
+                             pixel-scroll-precision-momentum-min-velocity)
+                      (let* ((velocity (aref state 0))
+                             (original-velocity velocity)
+                             (time-spent 0))
+                        (if (> velocity 0)
+                            (while (and (> velocity 0)
+                                        (<= time-spent
+                                            
pixel-scroll-precision-momentum-seconds))
+                              (when (> (round velocity) 0)
+                                (with-selected-window window
+                                  (pixel-scroll-precision-scroll-up (round 
velocity))))
+                              (setq velocity (- velocity
+                                                (/ original-velocity
+                                                   (/ 
pixel-scroll-precision-momentum-seconds
+                                                      
pixel-scroll-precision-momentum-tick))))
+                              (sit-for pixel-scroll-precision-momentum-tick)
+                              (setq time-spent (+ time-spent
+                                                  
pixel-scroll-precision-momentum-tick))))
+                        (while (and (< velocity 0)
+                                    (<= time-spent
+                                        
pixel-scroll-precision-momentum-seconds))
+                          (when (> (round (abs velocity)) 0)
+                            (with-selected-window window
+                              (pixel-scroll-precision-scroll-down (round
+                                                                   (abs 
velocity)))))
+                          (setq velocity (+ velocity
+                                            (/ (abs original-velocity)
+                                               (/ 
pixel-scroll-precision-momentum-seconds
+                                                  
pixel-scroll-precision-momentum-tick))))
+                          (redisplay t)
+                          (sit-for pixel-scroll-precision-momentum-tick)
+                          (setq time-spent (+ time-spent
+                                              
pixel-scroll-precision-momentum-tick))))))
                 (aset state 0 (make-ring 30))
                 (aset state 1 nil)))
           (beginning-of-buffer



reply via email to

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