Skip to content

Commit

Permalink
Altering pixel-scroll-precission patch to work on Emacs w/o X.
Browse files Browse the repository at this point in the history
  • Loading branch information
chaosemer committed Dec 9, 2023
1 parent 118dda5 commit b737fe8
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions 00.emacs-patches.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,42 @@
;;
;; The proper upstream is actually in `pixel-scroll-precision' to
;; collapse other cases to mouse. Solve via advice.
(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)
(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

Check failure on line 40 in 00.emacs-patches.el

View workflow job for this annotation

GitHub Actions / test (29.1, byte-compile)

reference to free variable ‘mouse-wheel-up-event’

Check failure on line 40 in 00.emacs-patches.el

View workflow job for this annotation

GitHub Actions / test (29.1, byte-compile)

reference to free variable ‘mouse-wheel-down-event’
mouse-wheel-up-alternate-event mouse-wheel-down-alternate-event))

Check failure on line 41 in 00.emacs-patches.el

View workflow job for this annotation

GitHub Actions / test (29.1, byte-compile)

reference to free variable ‘mouse-wheel-up-alternate-event’

Check failure on line 41 in 00.emacs-patches.el

View workflow job for this annotation

GitHub Actions / test (29.1, byte-compile)

reference to free variable ‘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)))
(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)

Check failure on line 64 in 00.emacs-patches.el

View workflow job for this annotation

GitHub Actions / test (29.1, byte-compile)

the function ‘pixel-scroll-precision’ is not known to be defined.
(setf device-class--prev-event-timestamp timestamp
device-class--prev-event-seems-like-mouse-event device-class--should-collapse-to-mouse)))

(when (featurep 'ns-win)
(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))
(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)))

(when (version< emacs-version "30.0")
(with-eval-after-load 'dired
Expand Down

0 comments on commit b737fe8

Please sign in to comment.