From 1bb0da0fee1b680a7f71186a1b4d4295abd55d6a Mon Sep 17 00:00:00 2001 From: Jared Finder Date: Wed, 27 Dec 2023 17:37:52 -0800 Subject: [PATCH] No need for patch! (See Bug#68050) Instead, use existing workaround built in to pixel-scroll.el. --- 00.emacs-patches.el | 62 +++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/00.emacs-patches.el b/00.emacs-patches.el index e87c594..6b80478 100644 --- a/00.emacs-patches.el +++ b/00.emacs-patches.el @@ -37,47 +37,6 @@ (keymap-lookup log-edit-mode-map "C-a")) (keymap-unset log-edit-mode-map "C-a")) -;; TODO(upstream) -;; -;; The proper upstream is actually in `pixel-scroll-precision' to -;; collapse other cases to mouse. Solve via advice. -(when (featurep 'ns-win) - (with-eval-after-load 'pixel-scroll - (defvar device-class--should-collapse-to-mouse nil - "Internal variable to track if collapsing should happen") - (defvar device-class--mouse-wheel-events - (list mouse-wheel-up-event mouse-wheel-down-event - mouse-wheel-up-alternate-event mouse-wheel-down-alternate-event)) - (defvar device-class--prev-event-timestamp 0 - "Interval variable of the previous event's timestamp.") - (defvar device-class--prev-event-seems-like-mouse-event nil) - - (defun device-class--collapse-to-mouse (r) - "Patch for `pixel-scroll-precision' to return mouse for pointers." - (if (and device-class--should-collapse-to-mouse - (eq r 'core-pointer)) - 'mouse - r)) - (defun pixel-scroll-precision--patched (event) - (interactive "e") - (let* ((wheel-event (member (event-basic-type event) device-class--mouse-wheel-events)) - (line-count (event-line-count event)) - (seems-like-mouse-event (and wheel-event (/= line-count 0))) - (timestamp (posn-timestamp (event-start event))) - ;; collapse to mouse when the event seems like a mouse event - (device-class--should-collapse-to-mouse - (if (< (- timestamp device-class--prev-event-timestamp) - 100) - device-class--prev-event-seems-like-mouse-event - seems-like-mouse-event))) - (pixel-scroll-precision event) - (setf device-class--prev-event-timestamp timestamp - device-class--prev-event-seems-like-mouse-event device-class--should-collapse-to-mouse))) - - (display-warning 'emacs "Fixing buggy pixel-scroll-precesion") - (keymap-global-set " " 'pixel-scroll-precision--patched) - (advice-add 'device-class :filter-return 'device-class--collapse-to-mouse))) - ;; Fix for clicking on directory line not properly respecting ;; `dired-kill-when-opening-new-dired-buffer'. TODO(Bug#67856, fixed in 29.2) (when (version< emacs-version "29.2") @@ -117,3 +76,24 @@ "" 'mouse-face "RET" click)))) (setq segment-start (point)))))))) + +;; Waiting on Emacs support for `device-class' on other platforms. +;; +;; Currently, only x and pgtk distinguish between touchpad and mouse +;; via `device-class' so prompt the user (me!) to choose if using +;; pixel-scroll. +(unless (memq window-system '(x pgtk)) + (with-eval-after-load 'pixel-scroll + (display-warning + 'emacs + (concat + "On this OS smooth scrolling assumes you have a touchpad.\n" + " Toggle if using other device: " + (buttonize "[Mouse]" + (lambda (&rest _) + (setf pixel-scroll-precision-large-scroll-height 0))) + " " + (buttonize "[Touchpad]" + (lambda (&rest _) + (setf pixel-scroll-precision-large-scroll-height nil))) + (propertize " " 'invisible t 'rear-nonsticky t)))))