macos: revert pixel-scroll-precision-mode, fix scroll with mwheel

pixel-scroll-precision-mode (from previous commit) breaks scrolling on
NS/Cocoa builds: it rebinds [wheel-up/down] to precision handlers that
do not work with the NS event system, resulting in zero scroll response.

Fix: remove pixel-scroll-precision-mode, use standard mwheel.el:
- require mwheel explicitly (Doom may not load it early enough)
- 3 lines/tick, shift=1, meta=0, ctrl=text-scale
- mouse-wheel-progressive-speed nil (constant speed, no acceleration)
- mouse-wheel-tilt-scroll t (horizontal two-finger scroll)
- explicitly bind [wheel-up/down] to mwheel-scroll (prevents Doom
  remapping from silently eating scroll events)
This commit is contained in:
2026-02-23 14:15:35 +01:00
parent a887f6a59d
commit 06de5b447a

View File

@@ -168,35 +168,34 @@ Bound to cmd+v in org-mode and markdown-mode."
mac-right-option-modifier 'none)) mac-right-option-modifier 'none))
;; Fix C: Disable mouse clicks in GUI Emacs (prevent accidental cursor movement) ;; Fix C: Disable mouse clicks in GUI Emacs (prevent accidental cursor movement)
;; Scroll wheel ([wheel-up/down]) is intentionally NOT disabled — scrolling works. ;; Scroll wheel events ([wheel-up/down]) are NOT disabled — scrolling works normally.
;; Mouse movement does not move cursor (mouse-autoselect-window nil above). ;; Mouse movement does not switch windows (mouse-autoselect-window nil above).
(when (display-graphic-p) (when (display-graphic-p)
;; Disable clicks only — NOT wheel events
(dolist (key '([mouse-1] [mouse-2] [mouse-3] (dolist (key '([mouse-1] [mouse-2] [mouse-3]
[double-mouse-1] [double-mouse-2] [double-mouse-3] [double-mouse-1] [double-mouse-2] [double-mouse-3]
[triple-mouse-1] [triple-mouse-2] [triple-mouse-3] [triple-mouse-1] [triple-mouse-2] [triple-mouse-3]
[drag-mouse-1] [drag-mouse-2] [drag-mouse-3] [drag-mouse-1] [drag-mouse-2] [drag-mouse-3]
[down-mouse-1] [down-mouse-2] [down-mouse-3])) [down-mouse-1] [down-mouse-2] [down-mouse-3]))
(global-set-key key #'ignore)) (global-set-key key #'ignore))
(setq mouse-highlight nil) (setq mouse-highlight nil))
;; Scroll wheel — macOS NS/Cocoa generates pixel-level scroll events from ;; macOS scroll wheel best practice (NS/Cocoa build):
;; trackpad and Magic Mouse. pixel-scroll-precision-mode (Emacs 29+) handles ;; - pixel-scroll-precision-mode is NOT used: it targets X11/Haiku and breaks
;; these natively for smooth, 1:1 scrolling. Line-based mouse-wheel-scroll-amount ;; NS/Cocoa scroll event delivery (rebinds [wheel-up/down] to non-working handlers)
;; is kept as fallback for physical scroll wheels that send line events. ;; - Standard mwheel.el with conservative settings is reliable on macOS
(setq mouse-wheel-scroll-amount '(3 ((shift) . 1) ((control) . nil)) ;; - NS backend converts trackpad + physical wheel to [wheel-up]/[wheel-down] events
mouse-wheel-progressive-speed nil (when (display-graphic-p)
mouse-wheel-follow-mouse t) (require 'mwheel)
;; 3 lines per scroll tick; shift = 1 line; no progressive acceleration
;; Enable pixel-precise scrolling (Emacs 29+) — essential for macOS trackpad/ (setq mouse-wheel-scroll-amount '(3 ((shift) . 1) ((meta) . 0) ((control) . text-scale))
;; Magic Mouse. Translates pixel deltas from NS scroll events into smooth mouse-wheel-progressive-speed nil ; constant speed, no acceleration
;; pixel-level buffer scrolling instead of jerky line jumps. mouse-wheel-follow-mouse t ; scroll window under cursor
(when (fboundp 'pixel-scroll-precision-mode) mouse-wheel-tilt-scroll t ; horizontal scroll with tilt/two-finger
(pixel-scroll-precision-mode 1) mouse-wheel-flip-direction nil) ; standard direction (not natural)
;; Large scroll threshold: pixel deltas above this trigger line-based scroll ;; Ensure mwheel-scroll is bound (Doom may remap these)
;; (prevents trackpad fling from being interpolated frame-by-frame). (global-set-key [wheel-up] #'mwheel-scroll)
(setq pixel-scroll-precision-large-scroll-height 40.0 (global-set-key [wheel-down] #'mwheel-scroll))
;; Use momentum scrolling from macOS (trackpad inertia)
pixel-scroll-precision-use-momentum t)))