fix: fullscreen for windows without rounded corners (#47681)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-07-08 15:21:13 +02:00 committed by GitHub
parent 3a6d7e0c22
commit 130f00dfcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 67 additions and 10 deletions

View file

@ -175,6 +175,8 @@ class NativeWindowMac : public NativeWindow,
// cleanup in destructor.
void Cleanup();
void SetBorderless(bool borderless);
void UpdateVibrancyRadii(bool fullscreen);
void UpdateWindowOriginalFrame();

View file

@ -154,13 +154,6 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
NSUInteger styleMask = NSWindowStyleMaskTitled;
// The NSWindowStyleMaskFullSizeContentView style removes rounded corners
// for frameless window.
const bool rounded_corner =
options.ValueOrDefault(options::kRoundedCorners, true);
if (!rounded_corner && !has_frame())
styleMask = NSWindowStyleMaskBorderless;
if (minimizable)
styleMask |= NSWindowStyleMaskMiniaturizable;
if (closable)
@ -220,6 +213,11 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
SetParentWindow(parent);
}
const bool rounded_corner =
options.ValueOrDefault(options::kRoundedCorners, true);
if (!rounded_corner && !has_frame())
SetBorderless(!rounded_corner);
if (transparent()) {
// Setting the background color to clear will also hide the shadow.
[window_ setBackgroundColor:[NSColor clearColor]];
@ -768,6 +766,11 @@ void NativeWindowMac::MoveTop() {
[window_ orderWindowByShuffling:NSWindowAbove relativeTo:0];
}
void NativeWindowMac::SetBorderless(bool borderless) {
SetStyleMask(!borderless, NSWindowStyleMaskTitled);
SetStyleMask(borderless, NSWindowStyleMaskBorderless);
}
void NativeWindowMac::SetResizable(bool resizable) {
ScopedDisableResize disable_resize;
SetStyleMask(resizable, NSWindowStyleMaskResizable);

View file

@ -375,9 +375,6 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
}
- (BOOL)toggleFullScreenMode:(id)sender {
if (!shell_->has_frame() && !shell_->HasStyleMask(NSWindowStyleMaskTitled))
return NO;
bool is_simple_fs = shell_->IsSimpleFullScreen();
bool always_simple_fs = shell_->always_simple_fullscreen();

View file

@ -24,6 +24,8 @@ class NativeWindowMac;
int level_;
bool is_resizable_;
bool is_borderless_;
// Whether the window is currently minimized. Used to work
// around a macOS bug with child window minimization.
bool is_minimized_;

View file

@ -299,6 +299,8 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
- (void)windowWillEnterFullScreen:(NSNotification*)notification {
// Store resizable mask so it can be restored after exiting fullscreen.
is_resizable_ = shell_->HasStyleMask(NSWindowStyleMaskResizable);
// Store borderless mask so it can be restored after exiting fullscreen.
is_borderless_ = !shell_->HasStyleMask(NSWindowStyleMaskTitled);
shell_->set_is_transitioning_fullscreen(true);
@ -306,6 +308,8 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
// Set resizable to true before entering fullscreen.
shell_->SetResizable(true);
// Set borderless to false before entering fullscreen.
shell_->SetBorderless(false);
}
- (void)windowDidEnterFullScreen:(NSNotification*)notification {
@ -341,6 +345,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
shell_->set_is_transitioning_fullscreen(false);
shell_->SetResizable(is_resizable_);
shell_->SetBorderless(is_borderless_);
shell_->NotifyWindowLeaveFullScreen();
if (shell_->HandleDeferredClose())