termio: send initial focus reports

When the focus reporting mode (1004) is enabled, send the current focus
state. This allows applications to track their own focus state without
first having to wait for a focus event (or query
it by sending a DECSET followed by a DECRST).

Ghostty's focus state is stored only in the renderer, where the termio
thread cannot access it. We duplicate the focus state tracking in the
Terminal struct with the addition of a new (1-bit) flag. We duplicate
the state because the renderer uses the focus state for its own purposes
(in particular, the Metal renderer uses the focus state to manage
its DisplayLink), and synchronizing access to the shared terminal state
is more cumbersome than simply tracking the focus state in the renderer
in addition to the terminal.
This commit is contained in:
Gregory Anders
2024-08-31 19:40:19 -05:00
parent 42b799e9a0
commit df06697899
6 changed files with 21 additions and 3 deletions

View File

@@ -283,6 +283,7 @@ fn drainMailbox(
.start_synchronized_output => self.startSynchronizedOutput(cb),
.linefeed_mode => |v| self.flags.linefeed_mode = v,
.child_exited_abnormally => |v| try io.childExitedAbnormally(v.exit_code, v.runtime_ms),
.focused => |v| try io.focusGained(data, v),
.write_small => |v| try io.queueWrite(
data,
v.data[0..v.len],