From b025fafe3884ab055a65ce5ebfc6548617907e2f Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Wed, 11 Nov 2026 17:55:53 +0800 Subject: [PATCH] darwin: keep the traffic lights centered when the title changes 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. --- internal/platform/darwin/native.m | 6 ++++++ internal/platform/darwin/testdata/traffic_lights.m | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/internal/platform/darwin/native.m b/internal/platform/darwin/native.m index 5eb7c1678..4e62135b3 100644 --- a/internal/platform/darwin/native.m +++ b/internal/platform/darwin/native.m @@ -6250,6 +6250,12 @@ - (void)setWindowTitle:(NSString *)title { _title = [title copy]; if (_window != nil) { _window.title = _title; + /* A new title lays the titlebar out again, and AppKit sets the zoom + * button back at the system's height without reporting the move as a + * frame change, so keepTrafficLightsCentered never hears of it. */ + if (_windowMode == VIVA_WINDOW_CUSTOM_TITLEBAR) { + viva_place_traffic_lights(_window, _titlebarHeight); + } } } diff --git a/internal/platform/darwin/testdata/traffic_lights.m b/internal/platform/darwin/testdata/traffic_lights.m index bdcae84fd..e6c7e15c5 100644 --- a/internal/platform/darwin/testdata/traffic_lights.m +++ b/internal/platform/darwin/testdata/traffic_lights.m @@ -121,6 +121,13 @@ int main(void) { window.titlebarAppearsTransparent = NO; window.titlebarAppearsTransparent = YES; assertCenter(window, 18, "after the titlebar was restyled"); + // A new title lays the titlebar out too, and AppKit moves the zoom + // button back without reporting it as a frame change. + [delegate setWindowTitle:@"project"]; + assertCenter(window, 18, "after the title changed"); + assertAligned(window, "after the title changed"); + [delegate setWindowTitle:@"project - file"]; + assertAligned(window, "after the title changed again"); [delegate setAlwaysOnTop:YES]; assert(window.level == NSFloatingWindowLevel); [delegate setAlwaysOnTop:NO];