Skip to content

Fix Ctrl+Alt terminal input on Windows by repairing xterm's AltGr misclassification - #8810

Merged
AmethystLiang merged 4 commits into
stablyai:mainfrom
bbingz:fix/8734-windows-ctrl-alt-terminal-input
Jul 16, 2026
Merged

AmethystLiang merged 4 commits into
stablyai:mainfrom
bbingz:fix/8734-windows-ctrl-alt-terminal-input

Conversation

@bbingz

@bbingz bbingz commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • repair xterm's Windows third-level-shift misclassification so genuine Ctrl+Alt chords reach xterm's own protocol-aware key encoders instead of being silently dropped
  • xterm's keyboard service already computes the correct bytes for every input protocol (legacy ESC-prefixed, kitty CSI-u, win32-input-mode) before _isThirdLevelShift discards them; the fix is a narrow runtime wrapper on that predicate — Orca adds no encoder of its own
  • rescue only provably-genuine chords: Windows Chromium client, Ctrl+Alt held, no Meta, and getModifierState('AltGraph') === false. Chromium simulates the AltGraph modifier layout-wide whenever the active layout maps AltGr characters (crbug 762557), so a false AltGraph state proves the chord cannot compose text
  • the wrapper only ever weakens a third-level verdict to false; macOS option handling, AltGr composition, IME, and handled application shortcuts are untouched by construction. Firefox web clients (no AltGraph-simulation guarantee) keep stock behavior
  • reuse the shared terminal PTY write observer in the shortcut E2E instead of retaining a duplicate local spy

Fixes #8734.

Why not encode in Orca's key handler

An earlier revision intercepted the chord in attachCustomKeyEventHandler and injected hand-rolled ESC-prefixed bytes. Review found four defects inherent to duplicating the encoder: kitty-protocol TUIs (neovim, helix, fish 4) received legacy bytes behind their negotiated protocol; Ctrl+Alt+2 aliased to plain Alt+2 and Ctrl+Alt+[ emitted a bare CSI introducer; letters keyed off physical code (wrong for Dvorak/Colemak); and the injected path skipped xterm's stock stopPropagation. Routing rescued chords through xterm's own encoders resolves all four and additionally fixes Ctrl+Alt+Shift chords and Ctrl+Alt+F-keys, giving full parity with Linux client behavior.

Screenshots

No visual change.

Testing

  • pnpm typecheck
  • focused lint (oxlint + max-lines ratchet) on all touched files
  • Added or updated high-quality tests that would catch regressions

Focused checks:

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/lib/pane-manager src/renderer/src/components/terminal-pane — 216 files, 2688 passed
  • Contract tests construct a real Terminal and pin, against the actual xterm build: (1) the internal seam exists — an xterm upgrade that removes _isThirdLevelShift fails CI loudly instead of silently regressing; (2) rescued chords produce xterm-encoder output: legacy ESC+0x15 / ESC 2 / ESC ; for Ctrl+Alt+U/2/;, and CSI 117;7u for the same chord once kitty progressive flags are negotiated
  • Windows Electron E2E Windows forwards genuine Ctrl+Alt text chords verifies the exact bytes at the main-process PTY write boundary (byte expectations unchanged from the previous revision — they match xterm's legacy encoder output exactly)
  • Real ConPTY probe (previous revision, bytes identical): ESC + Ctrl-U through node-pty made Windows PowerShell ReadKey report U, char=0x0015, modifiers=Alt, Control

Notes

  • Failure mode: if a future xterm upgrade removes the internal seam, installWindowsCtrlAltChordRepair returns false and behavior degrades to today's dropped-chord behavior — never to wrong bytes. The contract test additionally turns that into a CI failure.
  • Known limitation (pre-existing, not a regression): on AltGr layouts (German, French, Polish, …) Chromium reports AltGraph for every Ctrl+Alt chord, so genuine chords there remain indistinguishable from AltGr composition and are still dropped — same as before this PR. Unavoidable without misreading AltGr typing.
  • The decision is based on the client OS/engine where xterm performs the classification, not the PTY host: a Windows client attached to a Linux SSH PTY gets the same repaired classification, and the bytes flow through the existing onData transport paths.

Security Audit

No new external data source, dependency, IPC method, filesystem access, or privilege. The change narrows one keyboard-classification predicate; all emitted bytes are produced by xterm's existing encoders on the existing trusted terminal input path.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Windows-specific Ctrl+Alt terminal input resolution for genuine chords, including Alt-prefixed letter encoding and forwarding of digits and punctuation. Integrates the resolver into the terminal pane keyboard handler, which writes resolved bytes directly and bypasses subsequent xterm handling. Adds unit tests for modifier, composition, and event-state cases, and adds Windows end-to-end assertions for PTY writes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The change addresses #8734 by forwarding genuine Windows Ctrl+Alt chords while preserving AltGraph, IME, shortcuts, and PTY delivery.
Out of Scope Changes check ✅ Passed The PTY write-spy refactor is test plumbing tied directly to the new E2E coverage, and no unrelated feature work is introduced.
Title check ✅ Passed The title clearly states the main change: fixing Windows Ctrl+Alt terminal input by addressing xterm AltGr misclassification.
Description check ✅ Passed The description is mostly complete and covers summary, screenshots, testing, notes, and security, though the AI Review Report section is missing.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

bbingz and others added 2 commits July 15, 2026 23:17
…own key encoders

Replace the hand-rolled Alt-prefix encoder in the custom key handler with a
narrow repair of xterm's third-level-shift classification. xterm's keyboard
service already computes the correct bytes for every input protocol (legacy
ESC-prefixed, kitty CSI-u, win32-input-mode) before _isThirdLevelShift
discards them on Windows Ctrl+Alt; rescuing only provably-genuine chords
(Chromium's layout-wide AltGraph simulation, crbug 762557) lets those
encoders deliver protocol-correct, layout-aware bytes with no duplicated
encoding knowledge in Orca.

Fixes vs the previous approach: kitty-mode TUIs now receive CSI-u instead of
legacy bytes, digits/punctuation no longer alias to plain Alt chords,
letters follow the logical layout (Dvorak/Colemak), Ctrl+Alt+Shift and
Ctrl+Alt+F-keys gain Linux parity, and handled keys get xterm's stock
preventDefault/stopPropagation. Firefox web clients keep stock behavior; a
real-Terminal contract test fails loudly if an xterm upgrade removes the
seam, degrading at runtime to the historical dropped-chord behavior.

Co-authored-by: Orca <[email protected]>
@AmethystLiang
AmethystLiang force-pushed the fix/8734-windows-ctrl-alt-terminal-input branch from 2763988 to 0b6dc2c Compare July 16, 2026 07:41
@AmethystLiang AmethystLiang changed the title Fix Ctrl+Alt terminal input on Windows Fix Ctrl+Alt terminal input on Windows by repairing xterm's AltGr misclassification Jul 16, 2026
- Extract a shared getCore() helper in the test file to dedupe repeated
  `_core` casts across third-level-shift and keyboard-service lookups.
- Correct the AltGraph comment: Chromium simulates AltGraph per composing
  keypress, not for the whole Ctrl+Alt press duration.
- Warn via console when xterm no longer exposes `_core._isThirdLevelShift`,
  so a silent classification-repair failure is diagnosable in the wild.
The comment previously implied Chromium always sets AltGraph=true for
composable chords; the revised wording states the actual mechanism
(Alt+Ctrl modifiers get replaced by AltGraph) so the inverse case is
unambiguous.
@AmethystLiang
AmethystLiang requested review from AmethystLiang and removed request for Jinwoo-H July 16, 2026 20:18
@AmethystLiang

Copy link
Copy Markdown
Contributor

reviewing it

@AmethystLiang
AmethystLiang merged commit 8461df2 into stablyai:main Jul 16, 2026
3 checks passed
@bbingz
bbingz deleted the fix/8734-windows-ctrl-alt-terminal-input branch August 1, 2026 00:47
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…classification (stablyai#8810)

* fix(terminal): forward Windows Ctrl Alt chords

* fix(terminal): route rescued Windows Ctrl+Alt chords through xterm's own key encoders

Replace the hand-rolled Alt-prefix encoder in the custom key handler with a
narrow repair of xterm's third-level-shift classification. xterm's keyboard
service already computes the correct bytes for every input protocol (legacy
ESC-prefixed, kitty CSI-u, win32-input-mode) before _isThirdLevelShift
discards them on Windows Ctrl+Alt; rescuing only provably-genuine chords
(Chromium's layout-wide AltGraph simulation, crbug 762557) lets those
encoders deliver protocol-correct, layout-aware bytes with no duplicated
encoding knowledge in Orca.

Fixes vs the previous approach: kitty-mode TUIs now receive CSI-u instead of
legacy bytes, digits/punctuation no longer alias to plain Alt chords,
letters follow the logical layout (Dvorak/Colemak), Ctrl+Alt+Shift and
Ctrl+Alt+F-keys gain Linux parity, and handled keys get xterm's stock
preventDefault/stopPropagation. Firefox web clients keep stock behavior; a
real-Terminal contract test fails loudly if an xterm upgrade removes the
seam, degrading at runtime to the historical dropped-chord behavior.

Co-authored-by: Orca <[email protected]>

* Refactor Windows Ctrl+Alt chord test helpers and clarify AltGraph commen

- Extract a shared getCore() helper in the test file to dedupe repeated
  `_core` casts across third-level-shift and keyboard-service lookups.
- Correct the AltGraph comment: Chromium simulates AltGraph per composing
  keypress, not for the whole Ctrl+Alt press duration.
- Warn via console when xterm no longer exposes `_core._isThirdLevelShift`,
  so a silent classification-repair failure is diagnosable in the wild.

* Clarify comment explaining why Windows Ctrl+Alt chords bypass AltGraph c

The comment previously implied Chromium always sets AltGraph=true for
composable chords; the revised wording states the actual mechanism
(Alt+Ctrl modifiers get replaced by AltGraph) so the inverse case is
unambiguous.

---------

Co-authored-by: Jinjing <[email protected]>
Co-authored-by: Orca <[email protected]>
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.

[Bug]: Ctrl+Alt chords are swallowed by terminal input on Windows

3 participants