Skip to content

terminal: announce lower mouse tracking modes cumulatively - #1405

Open
kedimuzafer wants to merge 1 commit into
mobile-shell:masterfrom
kedimuzafer:fix/cumulative-mouse-modes
Open

terminal: announce lower mouse tracking modes cumulatively#1405
kedimuzafer wants to merge 1 commit into
mobile-shell:masterfrom
kedimuzafer:fix/cumulative-mouse-modes

Conversation

@kedimuzafer

Copy link
Copy Markdown

Fixes #1364.

Mouse tracking modes 1000, 1002 and 1003 are separate flags in xterm, and applications set them cumulatively. mosh stores them in a single mouse_reporting_mode and announces only the most recent one to the client terminal.

Terminals need not implement every mode; the usual behaviour is to ignore an unsupported request and keep the mode already in effect. Because mosh forwards only the final mode, that fallback never happens — a terminal without 1003 ends up with mouse reporting entirely off, even though it supports 1000 and 1002.

Where we hit it

Android/Termux → mosh → tmux → a full-screen terminal application that requests 1000h 1002h 1003h 1006h at startup. Scrolling produced arrow keys instead of mouse events. Same phone, same server, same tmux over plain ssh: works.

Measurements

Raw bytes read from the tty in Termux while scrolling, one mode at a time, no mosh in the path:

requested received
1000h 1006h \e[<65;39;37M — SGR mouse
1002h 1006h \e[<64;35;28M — SGR mouse
1003h 1006h \e[A \e[B — arrow keys

So Termux implements 1000 and 1002 but not 1003. Then, same client and server, application sending all four modes:

transport result
ssh SGR mouse — every request reaches the terminal, 1003 is ignored harmlessly
mosh arrow keys — only 1003h reaches the terminal, so nothing is enabled

Fix

Announce the lower modes alongside the stored one, mirroring what applications send. Terminals that do support 1003 are unaffected, since the higher mode takes precedence.

Scope

This is the minimal fix. #1364 also suggests recording every requested mode in order and replaying it, which would preserve exact ordering across arbitrary transitions; that is a larger change to the state model. The existing disable of the previous mode is left alone.

Testing

Built and run as the client on Android/Termux (aarch64) against an unpatched mosh 1.4.0 server: mouse reporting works again through mosh → tmux. Also builds clean on Linux x86_64. Behaviour unchanged on terminals that support 1003.

Credit to @Imberflur for diagnosing the root cause in #1364.

Mouse tracking modes 1000, 1002 and 1003 are separate flags in xterm, and
applications set them cumulatively. mosh collapses them into a single
mouse_reporting_mode value and announces only that one to the client
terminal.

When an application requests 1000h, 1002h and then 1003h, mosh forwards
only 1003h. Terminals that do not implement 1003 ignore it and are left
with no mouse reporting at all, even though they support 1000 and 1002 and
would have worked over a plain ssh session.

Announce the lower modes alongside the stored one so such terminals keep
working.

Fixes mobile-shell#1364

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

Mouse support has issues when terminal does not support all modes.

1 participant