Repository navigation
How it works
A terminal does not tell anyone that it is showing a password prompt. What gives a prompt away is the mode of its pseudo-terminal: echo is off while line input is still on. Shells and full-screen programs turn both off; ordinary line input keeps both on. macOS Ghostty uses the same heuristic for its secure input.
While terminals are quiet the service sleeps: it wakes when the kernel reports, through inotify, that some terminal printed something, and checks the mode of only the terminals that printed. While a terminal keeps printing, or a prompt is up, it looks every 200 ms instead (focus can move and a prompt can end without any output); see Resource use for what that costs. A prompt nearly always prints its text, so waking on output is enough; the one exception is #6.
The layout is switched only if the prompting terminal belongs to the focused window, which is decided by walking the process tree from the terminal up to the window's process. Inside tmux that walk ends at the tmux server, so tmux itself is asked which pane is active and which of its clients — ordinary processes inside a terminal window — shows that session. When the prompt ends, or focus moves elsewhere, the previous layout is restored.
Graphical applications are a different story: they do tell the input method
what kind of field has focus, and mark password fields — the same fact macOS
acts on. The fcitx5 addon (libpasswordlayout.so) follows focus and that mark.
It never talks to the compositor on fcitx5's own thread, which every key press
goes through; a worker thread applies only the latest wish, so hopping across
fields costs at most one switch and a slow compositor cannot delay typing.
The terminal service and the addon hold Latin under separate names (tty and
im). The layout that was active before the first of them asked for Latin is
restored after the last one lets go; it is kept in
$XDG_RUNTIME_DIR/password-layout/state.
Scripts can hold Latin the same way under a name of their own: see "From your own scripts" in the README.