fix: correct SGR mouse-wheel button codes (64/65/66/67, not 68/69/70/71) - #238
Open
smohekey wants to merge 1 commit into
Open
fix: correct SGR mouse-wheel button codes (64/65/66/67, not 68/69/70/71)#238smohekey wants to merge 1 commit into
smohekey wants to merge 1 commit into
Conversation
The wheel buttons were encoded as `64 + <button number>` (4/5/6/7), producing 68/69/70/71. In the X10/SGR mouse protocol the four wheel buttons are 64/65/66/67 — bit 6 set with the button number in the low two bits — so the surplus bits read as a spurious Shift modifier (`64 + 5` = 69 = wheel-down + shift). Applications that validate the button field reject the modified report as an invalid wheel event and don't scroll; lenient ones mask the modifier and happen to still work. Encode the wheel buttons as `64 + (0/1/2/3)` to match the spec and xterm, so both SGR (`ESC[<…M`) and normal-encoding (`ESC[M`) reports carry the correct code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
TerminalMouseButtonencodes the wheel buttons with the wrong values:In the X10/SGR mouse protocol the four wheel buttons are 64/65/66/67: bit 6 set (the high-button/"wheel" bit, +64) with the button number carried in the low two bits. The enum adds the raw button number (4/5/6/7) on top of 64 instead of transposing it into the low bits, giving 68/69/70/71.
Those extra bits are the modifier bits of the encoding:
68 = 64 + 4is wheel-up with Shift,69is wheel-down with Shift, and so on. So every wheel report the terminal emits carries a spurious Shift modifier.Impact
Applications that check the button field reject the report as a modified/invalid wheel event and don't scroll. (More lenient apps mask the modifier bit and still scroll, which is why this often goes unnoticed.) On the alternate screen,
TerminalScrollGestureHandlerforwards wheel events throughmouseInput, so a strict full-screen TUI never scrolls from the wheel.Fix
Encode the wheel buttons as
64 + (0/1/2/3)— bit 6 plus the button number in the low two bits — matching the SGR spec and xterm.Verified against an app that enables SGR mouse mode (
?1006) with any-event tracking (?1003): a wheel-down previously emittedESC[<69;…Mand did nothing; it now emitsESC[<65;…Mand the app scrolls.ESC[M(normal-encoding) reports are corrected the same way.