From dfb4e33e9ed40c364a11f5faf23f3e7b87b88d54 Mon Sep 17 00:00:00 2001 From: Jared Finder Date: Tue, 26 Dec 2023 12:44:40 -0800 Subject: [PATCH] Allow interpolation with arbitrary device classes * lisp/pixel-scroll.el (pixel-scroll-precision-interpolate-mice) (pixel-scroll-precision-interpolate-devices): Change boolean option to list so it can support mulitple device class symbols and rename it for clarity. * (pixel-scroll--interpolate-based-on-device-class-p): New function for backward compatibile check against above option. * (pixel-scroll-precision): Call it. --- lisp/pixel-scroll.el | 46 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/lisp/pixel-scroll.el b/lisp/pixel-scroll.el index 5f412bf418a..f82f95153b5 100644 --- a/lisp/pixel-scroll.el +++ b/lisp/pixel-scroll.el @@ -212,13 +212,31 @@ pixel-scroll-precision-interpolate-page :type 'boolean :version "29.1") -(defcustom pixel-scroll-precision-interpolate-mice t - "Whether or not to interpolate scrolling from a mouse. -If non-nil, scrolling from the mouse wheel of an actual mouse (as -opposed to a touchpad) will cause Emacs to interpolate the scroll." +(define-obsolete-variable-alias + 'pixel-scroll-precision-interpolate-mice + 'pixel-scroll-precision-interpolate-devices + "29.2") + +(defcustom pixel-scroll-precision-interpolate-devices (list 'mouse) + "List of device classes that will cause interpolated scrolling. +Interpolated scrolling looks good for devices that generate +significant scroll distance per event, such as mice, and looks +poor for devices that have ery small distance events, such as +high precision touchpads. + +See `device-class' for possible device classes. + +For backward compatibility, this also can be set to t, which is +equivalent to '(mouse)." :group 'scrolling - :type 'boolean - :version "29.1") + :type '(list + (checklist :inline t + (const :tag "Mouse" mouse) + (const :tag "Generic pointing device" core-pointer)) + (repeat :inline t + :tag "Other devices" + symbol)) + :version "29.2") (defun pixel-scroll-in-rush-p () "Return non-nil if next scroll should be non-smooth. @@ -700,10 +718,8 @@ pixel-scroll-precision (if (> (abs delta) (window-text-height window t)) (mwheel-scroll event nil) (with-selected-window window - (if (or (and pixel-scroll-precision-interpolate-mice - (eq (device-class last-event-frame - last-event-device) - 'mouse)) + (if (or (pixel-scroll--interpolate-based-on-device-class-p + (device-class last-event-frame last-event-device)) (and pixel-scroll-precision-large-scroll-height (> (abs delta) pixel-scroll-precision-large-scroll-height) @@ -732,6 +748,16 @@ pixel-scroll-precision (message (error-message-string '(end-of-buffer)))))))))) (mwheel-scroll event nil)))) +(defun pixel-scroll--interpolate-based-on-device-class-p (class) + "Return whether this device class should always interpolate scrolling. +CLASS is a value returned from `device-class'." + (and pixel-scroll-precision-interpolate-devices + (memq class + (if (eq pixel-scroll-precision-interpolate-devices t) + ;; Emacs 29.1 had this as a boolean, defaulting to t. + '(mouse) + pixel-scroll-precision-interpolate-devices)))) + ;; isearch-scroll support (put 'pixel-scroll-precision 'scroll-command t) -- 2.39.2