Repository navigation
fix: honor the OSC 111 background reset - #312
Merged
Merged
Conversation
the OSC 11 handler pushed a per-surface config carrying `background = <the osc color>`, which reaches ghostty's `Termio.changeConfig` and re-seeds `terminal.colors.background.default` on every surface update. That overwrote the layer OSC 111 restores (`DynamicRGB.reset()` is `override = default`), so a TUI that colored the background and reset it on exit left the pane stuck on its color, and an OSC 11 query still reported it. the renderer takes the background color from terminal state and the alpha from `background-opacity`, so the overlay only has to lift the opacity that window translucency pins to 0. `WatermarkConfig.oscBackgroundOverlayText` emits no `background` key, so `default` stays at the theme color and the reset reverts. libghostty reports set and reset through the same action with no flag telling them apart, so the host-free `OSCBackgroundPolicy` spots a reset by comparing against the surface's own baseline color (a `.color` watermark, an overlay's `--background-color`, else the theme). It also owns the per-prompt dedupe that used to sit inline in the callback. checked against a pre-fix build with the same harness: the background query after OSC 111 reported the program's color before, the theme color after. Related to #309
review follow-ups to 2ab231c. `baselineBackgroundHex()` returned the surface's own color (a `.color` session watermark, or an overlay's `--background-color`), but the OSC overlay emits no `background` key, so while it is installed the config in force is the base one and ghostty seeded `default` from the theme. A reset on those surfaces reported the theme, matched neither the baseline nor the live OSC color, and routed to `.apply` instead of `.reset` - leaving the overlay installed and the latch pinned for a program that had already exited, so every reload, opacity tick and dashboard toggle reinstalled it. Pixels were unaffected either way, since the un-clearable `override` masks `default`. `OSCBackgroundPolicy.baseline` now owns the rule and is unit-tested. `applyOverlayBackgroundColor` also runs on the reset path now, so it takes the font from `currentEffectiveFontSize()` instead of the creation size. Without that, a `--background-color` overlay zoomed with cmd-+/- snapped back to its opening size when a program reset the background.
`applyWatermarkFromSession` composed its font from `dashboardFontOverride ?? session.fontSize`, never reaching `currentFontSize()`. A split or scratch pane has its `onFontSizeChange` unwired on purpose (`ControlServer+SurfaceIO.font`), so its cmd-+/- zoom is live-only and readable nowhere else, and every re-apply snapped it back to the session's size or the config default. that was already true for `session.background` set/clear; the OSC reset path added a second trigger, since it routes a session or watermarkSession surface through the same method. Both now compose from `currentEffectiveFontSize()`, the chain the apply path and the overlay path already use. the zoom-clearing reload contract is unaffected: it nils `session.fontSize` and broadcasts the shared config before `reapplySessionConfigIfNeeded` runs, so the live read returns the freshly applied default and re-emitting it is a no-op.
n2tr2
added a commit
to n2tr2/agterm-linux
that referenced
this pull request
Oct 1, 2026
With many sessions open, a theme change froze the app: the main thread fed theme OSC 10/11 into every surface, each feed pushed color_change into libghostty's 64-slot app mailbox with a .forever fallback, and only the main thread drains that mailbox. - Theme colors reach surfaces only through config; the host feeds, the feed helpers and themeOSC/themeResetOSC are removed. - The OSC 11 latch overlay carries only opacity and font (macOS umputun#312), selected by the new LinuxBackgroundOverlayPolicy. - libghostty patch: drop ghostty_surface_feed; under must_draw_from_app_thread, renderer_health pushes .instant and a PendingHealth value is retried from App.tick after the drain. - AT-SPI scenario theme-many-sessions guards the hang and the color cases; control calls take a per-call timeout. - libghostty.md records the config-only path and the app mailbox rule. Claude-Session: https://claude.ai/code/session_01UXsFSAnftzk65uhqTTKixZ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
agterm honored
OSC 11(set background) but notOSC 111(reset), so a TUI that colors the background and restores it on exit left the pane stuck on its color. Reported with Docker Sandboxessbx, a Bubble Tea v2 app whose renderer emitsansi.ResetBackgroundColoron close.Root cause
Self-inflicted, not a libghostty limitation. The OSC 11 handler pushed a per-surface config carrying
background = <the OSC color>. That reaches ghostty'sTermio.changeConfig, which re-seedsterminal.colors.background.defaultfrom the config on every surface update.DynamicRGB.reset()isoverride = default, so OSC 111 restored the program's own color. The follow-upCOLOR_CHANGEthen carried the same hex and was dropped by the dedupe guard, and an OSC 11 query still reported the program's color, becauseget()isoverride orelse defaultand both layers held it.Fix
The renderer takes the background color from terminal state and the alpha from
background-opacity, two independent sources. So the overlay only has to lift the opacity that window translucency pins to 0, and never restates the color.defaultstays at the theme and the reset reverts.libghostty signals set and reset through the same action with no distinguishing flag, so the new host-free
OSCBackgroundPolicyidentifies a reset by the reported color equalling the surface's baseline, and owns the per-prompt dedupe that used to sit inline in the callback. While an OSC overlay is installed that baseline is the theme, since the overlay emits nobackgroundkey.Two adjacent font bugs surfaced while wiring the reset path and are fixed here. A
--background-coloroverlay and a split or scratch pane each lost their live cmd-+/- zoom on a config re-apply, because those panes haveonFontSizeChangeunwired on purpose and their zoom is readable only from the surface. Both paths now compose from the samecurrentEffectiveFontSize()chain. The split/scratch case predates this branch and also fired onsession.backgroundset/clear.Verified
A/B against a pre-fix build of the same worktree, same harness: the background query after
OSC 111reportedrgb:1212/3434/5656, the program's color, before the change and the theme color after. Checked at full opacity and under translucency.swift test1929,make test-app46,make lint --strictclean. 12 new host-free tests cover the overlay emitter and the set/reset/dedupe routing.Note on scope: an explicit
session.backgroundstill cannot override a live OSC 11, since the program'soverridelayer masks the configdefaultand the pinned libghostty exposes no API to clear it. That limitation is unchanged and documented.Fix #309