## Summary
Applications cannot reliably determine whether an unfocused terminal is
still
visible, so focus reports alone are insufficient for avoiding
unnecessary
rendering.
This adds terminal visibility reporting by:
- implementing private mode 2033
- supporting `CSI ? 998 n` visibility queries and `CSI ? 999 ; Ps n`
responses
- reporting effective visibility changes while mode 2033 is enabled
- preserving host-owned visibility state across terminal resets
- treating unknown visibility conservatively as potentially visible
On GTK 4.12 and newer, surface visibility now combines widget mapping
with the
toplevel `suspended` state. This allows Ghostty to recognize windows
hidden on
another workspace or otherwise known by the compositor to be
non-visible.
Older GTK versions retain the existing conservative behavior.
## Testing
Added coverage for:
- mode 2033 support and enable/disable behavior
- explicit visibility queries
- immediate reports when enabling the mode
- visible and non-visible responses
- visibility persistence across terminal resets
- suppression of visibility queries in read-only mode
## AI disclosure
Amp assisted with the implementation, tests, commit messages, and this
pull
request description. I reviewed the resulting changes and understand how
they
interact with the terminal, termio, surface, and GTK visibility paths.
Implements: #13451
Reference: https://rockorager.dev/misc/visibility-reports/
Applications cannot infer whether an unfocused terminal remains visible, so
focus reports are insufficient for avoiding expensive rendering while a
view is hidden.
Implement private mode 2033 and the visibility query/report sequences.
Track conservative per-surface visibility, report every effective change
while enabled, and always answer explicit queries and mode enables. Keep
view visibility across terminal resets because it is owned by the host,
not terminal state.
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019fa965-aa5f-7099-85b4-a9679d2c8bd3
GTK exposes the Wayland xdg_toplevel suspended state when the
compositor knows a window is not visible. Ghostty previously only used
widget map state, so it could continue rendering a mapped surface on an
inactive workspace or behind other windows.
Combine the mapped and suspended states for surface occlusion and update
all displayed surfaces whenever the toplevel suspension state changes.
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019fa965-aa5f-7099-85b4-a9679d2c8bd3
Seems to me the grow path in `Buffer.sync` (and `syncFromArrayLists`)
multiplies by `@sizeOf(T)` twice: `req_bytes` is already a byte count,
it gets doubled into size, and then the `newBufferWithLength:` call does
`size * @sizeOf(T)` on top of that. So every reallocation ends up being
`data.len` × `@sizeOf(T)`^2 × 2 bytes instead of the intended `data.len`
× `@sizeOf(T)` × 2.
The OpenGL version of this same helper does it what seems to be the
intended way, so this looks like a mixup rather than a deliberate safety
margin.
This makes the Metal implementation match the OpenGL one: track the new
length in units of T (which also fixes self.len going stale after a
grow. It's documented as the allocated element count but was never
updated here)
Buffer.sync and Buffer.syncFromArrayLists computed the new buffer size
in bytes (req_bytes * 2) and then multiplied by @sizeOf(T) again when
passing it to newBufferWithLength:, allocating data.len * sizeOf(T)^2 * 2
bytes. For the 32-byte CellText buffers this is a 64x over-allocation
and for the 4-byte CellBg buffers 8x, per swap-chain frame (e.g. ~9.4MB
instead of ~300KB per frame for a full 120x40 screen of text).
Match the OpenGL buffer implementation: track the new length in units
of T and multiply by @sizeOf(T) exactly once.
This exposes libghostty-vt callbacks for additional terminal events.
* Desktop notifications from OSC 9/777
* Progress reports from OSC 9;4, including state and optional percentage
* Uses the `lib.Enum` progress state
* Exposes both through the existing terminal option/effect API
AI disclosure: Sol-5.6 was used extensively to write the code, I
reviewed it personally.
This change updates z2d to 0.12.1 and changes the sprite font path
insetting functionality to use the new path offset abilities released in
the update.
In addition, there has been a slight change to the drawing of E0B5 and
its respective reflection; we now add a 1-pixel horizontal line segment
to each end to force them to be perpendicular. This is because
offsetting pre-expands the curves and ultimately causes the end segments
of the curve itself to have slight non-horizontal angles, which produce
small artifacts at the ends without the forced horizontal ends.
This change updates z2d to 0.12.1 and changes the sprite font path
insetting functionality to use the new path offset abilities released in
the update.
In addition, there has been a slight change to the drawing of E0B5 and
its respective reflection; we now add a 1-pixel horizontal line segment
to each end to force them to be perpendicular. This is because
offsetting pre-expands the curves and ultimately causes the end segments
of the curve itself to have slight non-horizontal angles, which produce
small artifacts at the ends without the forced horizontal ends.
**This is an ABI breaking change for C libs.**
Fixes https://github.com/ghostty-org/ghostty/issues/13268
You can now change scrollback limits (bytes and lines) at runtime.
This breaks the ABI but makes for a much more long-term pattern:
`ghostty_terminal_new` now only takes viewport size, and you set
scrollback configurations with the generic `ghostty_terminal_set`. The
`GhosttyTerminalOptions` struct is fully removed. I think this will
serve us much better over the long term.
C API callers could configure runtime scrollback limits but could not
read them back. Add terminal data keys for the primary screen byte and
line configurations.
Return GHOSTTY_NO_VALUE for unlimited limits and keep reads stable while
an alternate screen is active. Document the configured-value semantics
and add focused coverage for defaults, updates, and unlimited values.
Terminal construction previously accepted GhosttyTerminalOptions with
dimensions and one scrollback byte limit. Remove the options struct from
the ABI and make ghostty_terminal_new accept columns and rows directly.
Add byte and line limit options to ghostty_terminal_set and forward them
to the runtime Terminal setters. NULL removes a limit, while zero bytes
disables scrollback. Update type metadata, tests, and all API examples.
Scrollback limits were fixed when a terminal screen was initialized.
Move byte and line state and enforcement into a shared Limits type so
PageList can update both constraints after initialization and resize.
Add runtime setters to PageList and Terminal. Lowering a limit prunes
eligible history immediately, while zero bytes switches the primary
screen to no-scrollback behavior and clears retained history. Keep
alternate screens unchanged.
This adds a new config `scrollback-limit-lines` to limit scrollback by
lines instead of bytes. This also renames `scrollback-limit` to
`scrollback-limit-bytes` to make it clear what it does but we have a
compatibility entry so old configurations will continue to work, so its
not breaking.
**This is NOT exclusive to `scrollback-limit-bytes`**. When both are
set, then the _first limit reached_ is used. Since lines is affected by
viewport size and bytes are affected by entries (more styles, more
graphemes, etc.), they serve somewhat different purposes and it might be
useful to set both.
The default remains 50MB of bytes, unlimited lines.
This is not exposed to libghostty yet. I have that coming as a follow up
change.
Was brought up as possibly being a build issue here:
https://codeberg.org/vancluever/translate-c/pulls/1
I do think that this is the better approach and seems to be the close
equivalent of the `.zig_ilb` option that's coming with `LazyPath` in
0.17.0 (which is how translate-c behaves there).
I was looking for something like this initially and I _think_ I might
have passed over it to start with because it was a bit hard to determine
the circumstances that `b.graph.zig_lib_directory` would be null, but
upon further examination, I think such cases would be rare if they
happened at all. Rather than default to the cwd in this event though I
just get it to error out - that way we'll know if it ever is the case!
Move DECRQSS response encoding into the terminal DCS handler so both the
full termio path and libghostty-vt terminal stream emit the same
replies. The C API stream now maintains and releases DCS parser state
and forwards responses through write_pty.
Move DECRQSS response encoding into the terminal DCS handler so both
the full termio path and libghostty-vt terminal stream emit the same
replies. The C API stream now maintains and releases DCS parser state
and forwards responses through write_pty.
The custom memset accepted its fill value as u8 even though C callers
pass int. Accept c_int and explicitly truncate it to the low byte, which
is what other implementations of this do.
DECRQSS previously serialized every active underline as SGR 4, which
caused double, curly, dotted, and dashed styles to round-trip as single
underlines.
Emit the 4:n form for extended underline styles while retaining the
legacy 4 form for single underlines, and cover every supported style.
Since the renderer thread now emits scrollbar events on almost every
frame, there's always a `.scrollbar` message for the dying surface in
the app mailbox.
The OS runtime seems to schedule `appTick` and `ghostty_surface_free`
differently across macOS pre-26, 26 and 27.
On macOS 26.x, `ghostty_app_free` happens after
`App.scrollbar(_:target:v:)`, leaving `surface.userdata` pointing at a
freed `SurfaceView`.
When `deinit` runs on the main thread, free the surface synchronously
instead of detaching to a task. This fixes both crashes mentioned in
https://github.com/ghostty-org/ghostty/pull/9512 and
https://github.com/ghostty-org/ghostty/issues/13359.
### AI Disclosure
I used Claude to analyze the backtrace, but the code is written and
tested by myself.
DECRQSS previously serialized every active underline as SGR 4,
which caused double, curly, dotted, and dashed styles to round-trip
as single underlines.
Emit the 4:n form for extended underline styles while retaining the
legacy 4 form for single underlines, and cover every supported style.
The custom memset accepted its fill value as u8 even though C callers
pass int. Accept c_int and explicitly truncate it to the low byte, which
is what other implementations of this do.
This PR provides an implementation for the
[vicinae-hotkey-v1](https://github.com/vicinaehq/vicinae-wayland-protocols/tree/main/staging/vicinae-hotkey)
protocol, as discussed
[here](https://github.com/ghostty-org/ghostty/discussions/13453).
This is a wayland protocol that allows the client to dynamically
negotiate global shortcuts with the compositor. Unlike the portal, the
clients are free to bind, rebind, and unbind global shortcuts they
reserve.
Here are a few advantages of using this over the global shortcut portal
for ghostty specifically:
- `vicinae-hotkey-v1` lets the client know the state of its bindings at
all time, if a global bind is not granted by the compositor the cllient
is notified with a descriptive error message which is designed to help
the user understand what the problem might be. In my implementation, I
decided I would show a desktop notification to the user in case a global
shortcut reservation fails.
- Global binds set in the config cannot drift from what is actually
registered, cannot be unilaterally changed by the user in compositor
settings, and do not pollute the global shortcut namespace permanently.
Reservations are only active while ghostty is running.
- The protocol provides the client with an input serial that can be used
to generate an `xdg_activation` token, allowing ghostty to steal focus
when one of its global shortcut is used. Currently ghostty doesn't have
an input serial to pass to `xdg_activation`. I didn't wire it for now,
in order keep things simple. But I guess it will be a nice to have.
---
AI disclosure: most of the code was written by Fable 5 (Claude Code), as
zig is not my primary language.
From an implementation perspective: I made it so that
`vicinae-hotkey-v1` is used to manage global shortcuts over the portal
when the global is advertised by the compositor. If it's not available,
we fallback on the portal like before.
At this time the protocol is implemented by Hyprland (since
[v0.56.0](https://github.com/hyprwm/Hyprland/pull/15010)) and there is
an open PR for [niri](https://github.com/niri-wm/niri/pull/4145). There
is also an official [wayland-protocols
proposal](https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/525).
As for the clients, for now the only implementer (that I know of) is
[vicinae](https://github.com/vicinaehq/vicinae).
The idea would be to merge this `vicinae-hotkey-v1` implementation and
then have it be superseded by the upstream version later, assuming it is
turned into an official extension protocol following the
wayland-protocols process.
PS: sorry for the diff noise about all the .po changes, I'm not sure
whether this is intended or not, but I did regenerate the translations
as asked