Repository navigation
fix(titlebar): read the window title in child views, not WindowContentView.body - #548
Conversation
…tView.body WindowContentView.body read the active session's displayName twice, for the OS title token and for the visible title row, so every OSC title tick invalidated the whole body and re-ran SwiftUI's graph and layout for the window. WindowAccessor.updateNSView then ran the full WindowAppearance.sync when only the title had changed. WindowTitleSync and TitlebarLabel read the session and window names in their own bodies; the parent passes the store and ids and no title, so a title tick reaches those two views and NSWindow.title alone. WindowAccessor writes the title on a token change and keeps the blend on attach, key, main, fullscreen, appearance and accessibility changes, which already carry every other blend input. In a 20 s Time Profiler recording of a 10 Hz title spinner, sidebar hidden, WindowContentView.body had zero main-thread samples after this change against 212 before it; the two child bodies and the NSWindow title write carry the tick, and WindowAppearance.sync no longer appears in it. Fix #516
…tale notes the custom-name lookup was an extension of an agtermCore type declared in an app-target view file; it now sits beside windowName(for:) with a test, and the dashboard title uses it instead of its own copy. the WindowContentView comment on the title accessor said the parent body reads the title, the inverse of what it does. windows.md said TitleProbeView sets frameAutosaveName; it persists the frame under the window UUID in UserDefaults and restores it once on attach. Related to #516
Deploying agterm with
|
| Latest commit: |
c91cf97
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f2415b4a.agterm.pages.dev |
| Branch Preview URL: | https://title-off-body.agterm.pages.dev |
There was a problem hiding this comment.
🟡 Changes recommended
TitlebarLabel.body currently contains let composition = composition, which should not compile due to self-referential initialization and needs self.composition (or a rename).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR reduces SwiftUI invalidation/layout work caused by frequent OSC title updates by moving window-title reads out of WindowContentView.body into dedicated child views, and by splitting “OS window title write” from “full titlebar blend” behavior in WindowAccessor. It also centralizes custom window-name lookup in agtermCore’s WindowLibrary and adds hosted + host-free tests for the new behavior.
Changes:
- Introduce
WindowTitleSyncandTitlebarLabelto localize session/window-title reads to child views (avoiding re-runningWindowContentView.bodyon OSC title ticks). - Change
WindowAccessor.updateNSViewto writeNSWindow.titleon token changes without re-running the fullWindowAppearance.syncblend. - Add new
WindowLibrary.customWindowName(for:)inagtermCoreand update dashboard/window title composition plus tests.
File summaries
| File | Description |
|---|---|
| agtermTests/WindowContentView+TitlebarTests.swift | Hosted tests ensuring OS window title follows OSC/session/window rename updates without re-rooting the view. |
| agtermTests/WindowAccessorTests.swift | Hosted tests asserting title writes don’t trigger full blend, and pre-attach title survives attachment. |
| agtermCore/Tests/agtermCoreTests/WindowLibraryTests.swift | Unit tests for customWindowName(for:) behavior (auto-name/unknown id handling). |
| agtermCore/Sources/agtermCore/WindowLibrary.swift | Adds customWindowName(for:) API to centralize “custom name” lookup. |
| agterm/Views/WindowContentView+Titlebar.swift | Refactors titlebar label/title sync into child views (TitlebarLabel, WindowTitleSync). |
| agterm/Views/WindowContentView+Dashboard.swift | Uses customWindowName(for:) for dashboard window title suffix. |
| agterm/Views/WindowContentView.swift | Switches .background(WindowAccessor(...)) to .background(windowTitleSync) to isolate title reads. |
| agterm/Views/WindowAppearance.swift | Updates comment to reflect new re-application triggers (key/main/fullscreen + appearance). |
| agterm/Views/WindowAccessor.swift | Updates representable to write title on token changes and keep blend on attach/notifications. |
| .claude/rules/windows.md | Updates documentation of the window frame persistence/restore approach for TitleProbeView. |
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| var body: some View { | ||
| let composition = composition | ||
| VStack(alignment: .leading, spacing: 1) { |
umputun#548 moved the title write off the full blend, but NSWindow.title is still assigned on every OSC title tick. WindowAppearance.sync hides it and the custom header draws the visible title, so it only feeds the Window menu, Mission Control and the window switcher. Each assignment runs AppKit's title machinery (NSWindowTitleController, NSTitledFrame.setTitle), about 1.3 ms, which an agent's spinner pays ~10 times a second; umputun#548's own profile still shows _dosetTitle at 213 ms. The first write after a quiet interval lands at once, later ones within 0.5 s collapse into one trailing write carrying the final value. Blend-pass writes stay immediate and do not restart the interval, so a title set right after attach is not deferred.
PR B for #516, after #547.
WindowContentView.bodyread the active session'sdisplayNametwice, for the OS title token and for the visible title row, so every OSC title tick invalidated the whole body and re-ran SwiftUI's graph and layout for the window.WindowAccessor.updateNSViewthen ran the fullWindowAppearance.syncwhen onlyNSWindow.titlehad changed.two child views now own those reads.
WindowTitleSyncresolves the OS title in its own body and hostsWindowAccessor;TitlebarLabelresolvesTitlebarCompositionfor the visible row, and the zoom titlebar reuses it. The parent passes the store and ids and no title.WindowAccessorwriteswindow.titleon a token change and keeps the blend on attach, key, main, fullscreen, appearance and accessibility changes, which already carry every other blend input. The custom window name lookup moved intoWindowLibrarynext towindowName(for:), and the dashboard title uses it.tests: hosted, a
TitleProbeViewtitle write leaves a separator sentinel the full blend would reset, a title set before attach survives attachment, andWindowTitleSynchosted inNSHostingViewfollows an OSC title, a session rename and a window rename toNSWindow.title. Host-free, thecustomWindowName(for:)cases.profile, Time Profiler, Debug builds of a8bbaa5 and this branch, isolated state, sidebar hidden, one session printing numbered OSC 2 titles at about 10 Hz, two recordings of about 20 s each, main thread only. Values are inclusive main-thread sample weight in ms:
WindowContentView.body.getterWindowTitleSync.body/TitlebarLabel.bodyWindowAppearance.sync-[NSWindow _dosetTitle:andDefeatWrap:]GraphHost.flushTransactionsthese are sample weights over two separately timed recordings, not update counts and not a per-tick or total-CPU saving: the baseline tick count was not recorded, so the two workloads are not matched. The SwiftUI Instruments template hung on finalization here, so there is no SwiftUI-lane update count; the parent body had zero samples in the patched recording while the two child bodies and the title write were present. @dimonb, could you rerun your harness against this patch to measure the per-tick change?
Fix #516