Skip to content

darwin: keep the traffic lights centered when the title changes - #5

Merged
xiaoyumuxi merged 1 commit into
mainfrom
fix/title-keeps-traffic-lights
Nov 11, 2026
Merged

xiaoyumuxi merged 1 commit into
mainfrom
fix/title-keeps-traffic-lights

Conversation

@xiaoyumuxi

Copy link
Copy Markdown

What this changes

setWindowTitle: on macOS places the traffic lights again after it sets the window title, when the window has a custom titlebar.

Why

A new title makes AppKit lay the titlebar out again. During that layout AppKit moves the zoom button back to the system's height, and it posts no NSViewFrameDidChangeNotification for that last move, so keepTrafficLightsCentered never sees it. In a custom titlebar taller than the system's, the green button ends up above the red and yellow ones until the next resize. Lithe IDE (1lck/Lithe-IDEA#1799) sets the title when a project opens (Window.SetTitle, #1), so its 40 pt titlebar showed the green button 4 pt higher than the other two.

The same layout leaves the close and minimize buttons, and the container, where Viva put them. Only the zoom button moves without a notification.

How it was verified

  • test -z "$(gofmt -l $(git ls-files '*.go'))": no Go file changed.
  • go vet ./internal/platform/darwin and go vet -tags vivahead ./internal/platform/darwin ./headless/...
  • go test ./internal/platform/darwin ./app/... ./headless/... -count=1: all pass.
    • Without the fix, TestNativeTrafficLightPlacementAndWindowLevel fails with traffic light 2 is at y=377.00, the close button at 375.00 after the title changed.
  • go test ./... -count=1: not run in full; only the packages above.
  • benchmarks: no paint, layout or input path changed.
  • a real window on macOS 27 (Darwin 27.3), Apple Silicon.
    • A standalone AppKit window built the way Viva builds a custom titlebar: 40 pt strip, ordered front off screen.
    • Before the fix the zoom button's center is 16 pt below the top after the title changes, and the other two are at 20 pt.
    • Placing the buttons right after the title change holds them at 20 pt, also after the run loop turns and after the window becomes key.

Visual evidence

  • Changed: the traffic lights of a WindowCustomTitlebar window with TitlebarHeight above 28, after Window.SetTitle.
  • Reach it by: open such a window and call SetTitle once it is shown.
  • On: macOS 27.
  • Protected by: the "after the title changed" checks in internal/platform/darwin/testdata/traffic_lights.m.

Where the boundary sits

Framework. It is the macOS backend's own titlebar placement.

Cost

Nothing for windows without a custom titlebar. With one, a title change runs viva_place_traffic_lights, which is idempotent and touches three views.

Upstream

vivaui/viva has no Window.SetTitle yet (#1 was not proposed upstream), so this fix cannot go upstream on its own. It belongs with SetTitle when that is proposed.

Setting the window title lays the titlebar out again, and AppKit puts the
zoom button back at the system's height without posting the frame change
keepTrafficLightsCentered listens for. In a custom titlebar taller than
the system's, the green button then sits above the other two until the
next resize. setWindowTitle: now places the buttons again itself.
@xiaoyumuxi
xiaoyumuxi merged commit 4dd479b into main Nov 11, 2026
xiaoyumuxi added a commit to 1lck/Lithe-IDEA that referenced this pull request Nov 11, 2026
窗口标题跟随项目后(815a7f772),AppKit 重新布局标题栏,把绿色按钮放回系统默认高度,
而且不发出帧变化通知,40pt 标题栏里绿色按钮比红、黄两个高 4pt。
Viva 在 Lithe-IDEA/Lithe-viva#5 修复:改标题后重新摆放按钮;desktop/go.mod 固定到 4dd479b。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant