Function: pixel-scroll-start-momentum

pixel-scroll-start-momentum is an interactive and byte-compiled function defined in pixel-scroll.el.gz.

Signature

(pixel-scroll-start-momentum EVENT)

Documentation

Start kinetic scrolling for the touch event EVENT.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/pixel-scroll.el.gz
(defun pixel-scroll-start-momentum (event)
  "Start kinetic scrolling for the touch event EVENT."
  (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 (min most-positive-fixnum
                                  (* gc-cons-threshold 3)))
          (state nil))
      (when (framep window)
        (setq window (frame-selected-window window)))
      (setq state (pixel-scroll-kinetic-state window))
      (when (and (aref state 1)
                 (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))))
                              (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
           (message (error-message-string '(beginning-of-buffer))))
          (end-of-buffer
           (message (error-message-string '(end-of-buffer)))))))))