Skip to content

Commit 6d29863

Browse files
fix: prevent traffic light buttons flashing on deminiaturize (#50209)
* fix: prevent traffic light buttons flashing on deminiaturize When a window with a custom `trafficLightPosition` is minimized and restored, macOS re-layouts the title bar container during the deminiaturize animation, causing the traffic light buttons to briefly appear at their default position before being repositioned. Fix this by hiding the buttons container in `windowWillMiniaturize` and restoring them (with a redraw to the correct position) in `windowDidDeminiaturize`. Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * chore: address feedback from review Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
1 parent 01b99cd commit 6d29863

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

shell/browser/native_window_mac.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ class NativeWindowMac : public NativeWindow,
170170
void NotifyWindowDidFailToEnterFullScreen();
171171
void NotifyWindowWillLeaveFullScreen();
172172

173+
// Hide/show traffic light buttons around miniaturize/deminiaturize to
174+
// prevent them from flashing at the default position during the restore
175+
// animation when a custom trafficLightPosition is configured.
176+
void HideTrafficLights();
177+
void RestoreTrafficLights();
178+
173179
// Cleanup observers when window is getting closed. Note that the destructor
174180
// can be called much later after window gets closed, so we should not do
175181
// cleanup in destructor.

shell/browser/native_window_mac.mm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,18 @@ static bool FromV8(v8::Isolate* isolate,
15331533
[buttons_proxy_ redraw];
15341534
}
15351535

1536+
void NativeWindowMac::HideTrafficLights() {
1537+
if (buttons_proxy_)
1538+
[buttons_proxy_ setVisible:NO];
1539+
}
1540+
1541+
void NativeWindowMac::RestoreTrafficLights() {
1542+
if (buttons_proxy_ && window_button_visibility_.value_or(true)) {
1543+
[buttons_proxy_ redraw];
1544+
[buttons_proxy_ setVisible:YES];
1545+
}
1546+
}
1547+
15361548
// In simpleFullScreen mode, update the frame for new bounds.
15371549
void NativeWindowMac::UpdateFrame() {
15381550
NSWindow* window = GetNativeWindow().GetNativeNSWindow();

shell/browser/ui/cocoa/electron_ns_window_delegate.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ - (void)windowWillMiniaturize:(NSNotification*)notification {
256256
shell_->SetWindowLevel(NSNormalWindowLevel);
257257
shell_->UpdateWindowOriginalFrame();
258258
shell_->DetachChildren();
259+
// Hide the traffic light buttons container before miniaturize so that
260+
// when the window is restored, macOS does not render the buttons at
261+
// their default position during the deminiaturize animation.
262+
shell_->HideTrafficLights();
259263
}
260264

261265
- (void)windowDidMiniaturize:(NSNotification*)notification {
@@ -273,6 +277,10 @@ - (void)windowDidDeminiaturize:(NSNotification*)notification {
273277
shell_->set_wants_to_be_visible(true);
274278
shell_->AttachChildren();
275279
shell_->SetWindowLevel(level_);
280+
// Reposition traffic light buttons and make them visible again.
281+
// They were hidden in windowWillMiniaturize to prevent a flash at
282+
// the default (0,0) position during the restore animation.
283+
shell_->RestoreTrafficLights();
276284
shell_->NotifyWindowRestore();
277285
}
278286

0 commit comments

Comments
 (0)