^[control-codes
live in libghostty-vt

Private modes

?1004 Focus Events

View as Markdown

Have the terminal tell the program when its window gains or loses the keyboard focus.

CSI ? 1004 h/l
xterm
Mouse Tracking

With CSI ? 1004 h set, the terminal sends CSI I to the program when its window gains the keyboard focus and CSI O when it loses it, so that an editor can, for instance, reload a file that changed while it was in the background. CSI ? 1004 l stops the reports. It is xterm’s, listed with the mouse tracking modes, but it can be set with or without any of them (dpmodes, SendFocusButton). It is off to begin with, and RIS turns it off.

Focus changes come from the window, not from the data a case writes, so the cases check what DECRQM says and that setting the mode sends nothing on its own. libghostty-vt passes them.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984Nonot in the manual
VT510manual, 1st ed., 1993Nonot in the manual; not in Table 5-6
xtermpatch 412, xterm-411aYes
libghostty-vt0f171f6Yes
kitty0.49.1, run in a VMYespasses the 3 cases that show it working
foot1.28.0, run in a VMPartlyfails FOCUS-3, FOCUS-4 of the 3 cases that show it working
xterm.js headless6.0.0, run as a libraryYespasses the 3 cases that show it working
alacritty_terminal0.26.0, run as a libraryYespasses the 3 cases that show it working
ConEmubuild 230724, its documentationYeslisted among the mouse modes, as FOCUS_EVENT_MOUSE; ANSI escape codes
rxvt-unicode9.31, run in a VMPartlyfails FOCUS-4 of the 3 cases that show it working
VTE0.84.1, run as a libraryPartlyfails FOCUS-3, FOCUS-4 of the 3 cases that show it working

Validation

FOCUS-1: Off to begin with

\e[?1004$p
|____|
reply \e[?1004;2$y

FOCUS-2: Setting it sends nothing

A
\e[?1004h
B
|AB__|
cursor 1,3
reply none

FOCUS-3: Set and reset

\e[?1004h
\e[?1004$p
\e[?1004l
\e[?1004$p
|____|
reply \e[?1004;1$y\e[?1004;2$y

FOCUS-4: RIS turns it off

\e[?1004h
\ec
\e[?1004$p
|____|
reply \e[?1004;2$y
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.