Skip to content

Accumulate high-resolution wheel events forwarded to mouse-tracking apps - #660

Merged
dakra merged 1 commit into
dakra:mainfrom
mrcnski:fix-wheel-scroll-speed
Sep 2, 2026
Merged

dakra merged 1 commit into
dakra:mainfrom
mrcnski:fix-wheel-scroll-speed

Conversation

@mrcnski

@mrcnski mrcnski commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes wheel scrolling being far too fast in mouse-tracking apps (vim, htop, Claude Code) when a pixel-precision scroll package is active.

Problem: pixel-scroll-precision-mode and ultra-scroll disable wheel-event coalescing, so one trackpad gesture arrives as dozens of small-delta wheel events. The scroll intercept forwards each one to the terminal as a full wheel click. Follow-up to #97, which made non-tracking buffers fall through to the user's scroll package but left the forwarded path at one click per event.

Fix: accumulate pixel deltas per buffer and forward one wheel click per cell height of travel, as ghostty itself does. Events without pixel data (classic one-notch-per-event wheels) still forward one click each. A new ghostel-mouse-scroll-multiplier option (named after ghostty's mouse-scroll-multiplier) tunes the rate.

Since events absorbed into the accumulator must be consumed without sending anything, the tracking check moved out of the send: a new native ghostel--mouse-tracking exposes the terminal's flags.mouse_event — the same state the mouse encoder consults — and X10-only tracking falls through to the user's scroll package, since X10 never reports wheel buttons.

Tested on macOS (NS build) with a trackpad against Claude Code; plain-shell buffers still fall through to ultra-scroll as before. Untested on the emacs-mac port, where wheel events may lack the pixel-delta slot — the guard makes that case behave exactly as before this change.

🤖 Generated with Claude Code

@mrcnski

mrcnski commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Looks like tests need to be updated (and maybe some new ones added). I'll try to do this a bit later.

@mrcnski
mrcnski force-pushed the fix-wheel-scroll-speed branch from 44dd96b to 4392bdc Compare August 30, 2026 22:19
@dakra
dakra force-pushed the fix-wheel-scroll-speed branch from 4392bdc to 6133b38 Compare September 2, 2026 17:16
With pixel-scroll-precision-mode (or ultra-scroll) Emacs stops coalescing
wheel events and emits one per trackpad tick, and every tick was forwarded
as a full button-4/5 press, so a short swipe scrolled htop and vim by many
rows.  Bank each event's pixel delta and send one press per full row of
travel, as ghostty does.  A mouse-wheel notch stays one press: X11 and
pgtk identify the device, macOS reports a line count.

A native ghostel--mouse-tracking-p reads the encoder's mouse mode so a
sub-row tick can be consumed without sending anything, while wheel events
on an untracked terminal still fall through to the user's scroll package.
@dakra
dakra force-pushed the fix-wheel-scroll-speed branch 2 times, most recently from 05d8dcd to 1a1b0cb Compare September 2, 2026 17:50
@dakra
dakra merged commit 1a1b0cb into dakra:main Sep 2, 2026
30 checks passed
@dakra

dakra commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Thanks. I squashed the commit and made a few changes. Also removed the defcustom.
I'm not against adding one but would rather only do when someone asks for it and the emacs nx/x-scroll-event-delta-factor settings are not good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants