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