Skip to content

terminal: report modifyOtherKeys state via XTQMODKEYS#13332

Open
aymanbagabas wants to merge 3 commits into
ghostty-org:mainfrom
aymanbagabas:aymanbagabas/vt-modify-other-keys-query
Open

terminal: report modifyOtherKeys state via XTQMODKEYS#13332
aymanbagabas wants to merge 3 commits into
ghostty-org:mainfrom
aymanbagabas:aymanbagabas/vt-modify-other-keys-query

Conversation

@aymanbagabas

@aymanbagabas aymanbagabas commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Implements querying support for xterm modifyOtherKeys (XTQMODKEYS resource 4) via two forms:

  • CSI ? 4 m — the XTQMODKEYS query.
  • DCS $ q > 4 m ST — the DECRQSS form. CSI ? 4 m is technically a private SGR sequence (historically a superscript rendition), so DECRQSS is offered as a safer alternative per review feedback. Both forms are kept.

Ghostty implements mode 1 by default (ambiguous modified keys use the CSI 27 numeric form) and mode 2 when enabled, but never responded to either query, so applications could not detect support or the active mode.

Both forms reply with the XTMODKEYS control > 4 ; Pv m (CSI-prefixed for CSI ? 4 m, wrapped in DCS 1 $ r … ST for DECRQSS), where Pv is 2 when mode 2 is active and 1 otherwise. Pv is never 0 because the mode 1 encoding is always active and cannot be disabled. The reply payload is shared via Terminal.modifyOtherKeysReport and unit tested.

Discussion: #13331

AI disclosure

Implemented with AI assistance (GitHub Copilot CLI, model Claude Opus 4.8). I reviewed, understand, and can explain all of the code and its interaction with the key encoder without AI aid, per the AI Usage Policy.

Ghostty implements xterm modifyOtherKeys mode 1 by default (ambiguous
modified keys are encoded in the CSI 27 numeric form) and mode 2 when
enabled, but it never responded to the query `CSI ? 4 m`, so
applications couldn't detect support or the active mode.

Parse `CSI ? 4 m` (XTQMODKEYS resource 4) and reply with
`CSI > 4 ; Pv m`, where Pv is 2 when mode 2 is active and 1 otherwise.
Pv is never 0 because the mode 1 encoding is always active and cannot
be disabled.

Discussion: ghostty-org#13331

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9b663367-2ceb-4a1d-b634-28f22ef0a653
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
@ghostty-bot ghostty-bot Bot added the vt Control sequence related label Jul 14, 2026
@jcollie

jcollie commented Jul 14, 2026

Copy link
Copy Markdown
Member

Initial read-through looks good but I'm on mobile so maybe I missed something.

Comment thread src/terminal/stream_terminal.zig
Comment thread src/termio/stream_handler.zig Outdated
Comment thread src/terminal/stream.zig
- Short-circuit the libghostty-vt query handler when no write_pty
  effect is configured.
- Drop the pointless debug log in the termio query handler.
- Add parser unit tests covering CSI ? 4 m and the ignored resources.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9b663367-2ceb-4a1d-b634-28f22ef0a653
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
@aymanbagabas
aymanbagabas requested a review from mitchellh July 15, 2026 13:38
@aymanbagabas

Copy link
Copy Markdown
Contributor Author

Thank you @jcollie @mitchellh for the review. Addressed the review comments and also added DECRQSS report support.

@aymanbagabas
aymanbagabas marked this pull request as ready for review July 15, 2026 13:42
@aymanbagabas
aymanbagabas requested a review from a team as a code owner July 15, 2026 13:42
Comment thread src/terminal/Terminal.zig
CSI ? 4 m is technically a private SGR sequence, which historically
indicated a superscript rendition. Support the DECRQSS form
(DCS $ q > 4 m ST) as a safer alternative, as suggested in review, while
keeping the CSI form.

Both query forms reply with the XTMODKEYS control `> 4 ; Pv m`, now shared
via Terminal.modifyOtherKeysReport so the emitted bytes are unit tested.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9b663367-2ceb-4a1d-b634-28f22ef0a653
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
@aymanbagabas
aymanbagabas force-pushed the aymanbagabas/vt-modify-other-keys-query branch from fe66d80 to b60a83f Compare July 16, 2026 13:09
@aymanbagabas
aymanbagabas requested a review from jcollie July 16, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vt Control sequence related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants