Skip to content

Commit

Permalink
No need for patch! (See Bug#68050)
Browse files Browse the repository at this point in the history
Instead, use existing workaround built in to pixel-scroll.el.
  • Loading branch information
chaosemer committed Dec 28, 2023
1 parent 8e6064c commit 1bb0da0
Showing 1 changed file with 21 additions and 41 deletions.
62 changes: 21 additions & 41 deletions 00.emacs-patches.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<remap> <pixel-scroll-precision>" '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")
Expand Down Expand Up @@ -117,3 +76,24 @@
"<follow-link>" '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)))

Check warning on line 94 in 00.emacs-patches.el

View workflow job for this annotation

GitHub Actions / test (29.1, byte-compile)

assignment to free variable ‘pixel-scroll-precision-large-scroll-height’
" "
(buttonize "[Touchpad]"
(lambda (&rest _)
(setf pixel-scroll-precision-large-scroll-height nil)))
(propertize " " 'invisible t 'rear-nonsticky t)))))

0 comments on commit 1bb0da0

Please sign in to comment.