Skip to content

Windows: the wheel and presses reach a full-screen program - #34

Closed
zcg wants to merge 1 commit into
ELY-Open-Source:mainfrom
zcg:fix/windows-conpty-mouse
Closed

zcg wants to merge 1 commit into
ELY-Open-Source:mainfrom
zcg:fix/windows-conpty-mouse

Conversation

@zcg

@zcg zcg commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

What

On Windows, a wheel over a full-screen program scrolled nothing: in RPI's --tui-mode fullscreen the wheel moved the draft instead of the transcript above it, and a click on RPI's jump-to-end control started a selection instead of answering it.

Why

ConPTY drops a program's mouse DECSET. A program that writes CSI ? 1000 h, 1002 h or 1006 h to its stdout never has that byte reach the reader, so the tap's Modes never learns the program asked for the mouse and the view's mouse stays Off. I measured which sequences survive: 1049 h, 2004 h, 1001 h, 1015 h and 1030 h do; the standard mouse-tracking modes do not.

The wheel therefore took the alternate-screen branch and sent arrows, which RPI's editor answered.

ConPTY does translate an SGR mouse report written to its input pipe into a MOUSE_EVENT for the program, and it does so whether or not its own DECSET survived. So the fix sends an SGR report rather than arrows when the tap has never read a mouse mode and the pointer is over the alternate screen.

How

  • TerminalView::wheel sends an SGR report instead of arrows under that condition; the same fallback carries a press, its motion and its release, so RPI's jump-to-end control answers a click instead of starting a selection.
  • saw_mouse records whether the tap has ever read a mouse mode; a full reset clears it. It lives on every platform, though only Windows reads it, so the fallback has one shape everywhere and cfg!(windows) keeps it inert off Windows.
  • report takes the format as an argument, since that path needs SGR where the program's own mode named another.

Verified

  • On the owner's Windows 11 PC, in RPI's --tui-mode fullscreen: the wheel now scrolls the transcript above the draft, and the jump-to-end control answers a click.
  • cargo clippy --all-targets -- -D warnings clean, cargo fmt --check clean, 280 tests pass.
  • Cross-platform: off Windows hidden is always false, so asked returns the mode the tap read unchanged. I checked the non-Windows path compiles by forcing the predicate false. Linux and macOS behaviour is untouched; CI covers all three.

Not the answer

  • Writing through WriteConsoleW with ENABLE_VIRTUAL_TERMINAL_PROCESSING leaves the DECSET dropped.
  • CreatePseudoConsole's flags: Windows Terminal's match alacritty's, so they are not the difference.

Limit

A program on the alternate screen that wants no mouse — vim with its own scroll off among them — now takes the wheel as a report. There is no reliable signal that tells "the program wants the mouse but ConPTY ate the DECSET" from "the program wants no mouse"; alt-screen is the closest one available.

ConPTY drops a program's mouse DECSET, so the tap never learns the
program asked for the mouse: `CSI ? 1000 h`, `1002 h` and `1006 h`
written to its stdout never reach the reader, while `1049 h`, `2004 h`,
`1001 h`, `1015 h` and `1030 h` do. The wheel therefore took the
alternate-screen branch and sent arrows, which RPI's `--tui-mode
fullscreen` answered by moving its draft instead of scrolling the
transcript above it.

ConPTY does translate an SGR mouse report written to its input pipe into
a `MOUSE_EVENT` for the program, whether or not its own DECSET survived,
so `wheel` sends an SGR report rather than arrows when the tap has never
read a mouse mode and the pointer is over the alternate screen. The same
fallback carries a press, its motion and its release, so RPI's jump-to-end
control answers a click instead of starting a selection. `report` takes
the format as an argument, since that path needs SGR where the program's
own mode named another.

`saw_mouse` lives on every platform, though only Windows reads it, so the
fallback is one shape everywhere; `cfg!(windows)` keeps `hidden` false
off Windows, where a mode the tap read always holds.

Writing through `WriteConsoleW` with `ENABLE_VIRTUAL_TERMINAL_PROCESSING`
leaves the DECSET dropped, so that is not the answer; Windows Terminal's
`CreatePseudoConsole` flags match alacritty's.

A limit: a program on the alternate screen that wants no mouse, vim with
its own scroll off among them, now takes the wheel as a report.
@zcg

zcg commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

咦,明明是我的提交,怎么在这里显示成雷电芽衣了?这AI又犯了什么病了啊?不过无所谓了

@Raiden-MeixElysia

Copy link
Copy Markdown
Contributor

咦,明明是我的提交,怎么在这里显示成雷电芽衣了?这AI又犯了什么病了啊?不过无所谓了

绷不住了。我在合并的时候看看能不能修改一下。🤣🤣🤣

@Raiden-MeixElysia

Copy link
Copy Markdown
Contributor

Thank you, zcg. Merged in parts on main:

  • c37ea46, under your name: a composition holding a newline draws on one line, so the IME no longer stops the app.
  • 373fd6c: your finding was right. Windows' own conhost drops a program's CSI ? 1000 h, 1002 h and 1006 h. Microsoft's OpenConsole, which Windows Terminal runs on, passes them through, so every session now runs on a bundled OpenConsole 1.25. Programs' own mouse modes reach the terminal, and vim and less keep their arrows, which the alternate-screen fallback would have turned into reports.

The fallback itself is not merged.

Raiden-MeixElysia pushed a commit that referenced this pull request Oct 28, 2026
zcg found it typing by voice on Windows, in PR #34: gpui's shape_line
asserts its text holds no newline, and a composition that held one
reached it in paint_preedit, so the app died mid-composition. The
composition draws on one line now, each control as its picture, as
session labels do.
Raiden-MeixElysia added a commit that referenced this pull request Oct 28, 2026
PR #34 found the wheel dead over full-screen programs on Windows: the
system's conhost drops a program's CSI ? 1000 h, 1002 h and 1006 h, so
the tap never heard the mouse. Microsoft's OpenConsole, which Windows
Terminal runs on, passes them through: a probe on build 26300 read
?1000h ?1002h ?1006h from OpenConsole 1.25 and none from conhost.

vendor/conpty holds conpty.dll and OpenConsole.exe from NuGet's
Microsoft.Windows.Console.ConPTY 1.25.260930003, signed by Microsoft,
MIT. build.rs copies them beside every Windows build; alacritty loads
the conpty.dll beside the executable. Each spawn names the ConPTY it
runs on and fails unless it is the bundled one with OpenConsole beside
it. The zip carries both and their license. PR #34's guess, mouse
reports on the alternate screen when no mode was heard, is dropped:
vim and less would have taken reports for arrows.
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