From 8de8cb302ef18c0f756fd726563e6bf8fed58c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Zahola?= Date: Tue, 5 Dec 2023 17:35:54 +0100 Subject: [PATCH 1/3] fix: macOS maximize button shouldn't be disabled just because the window is non-fullscreenable --- shell/browser/native_window_mac.h | 2 ++ shell/browser/native_window_mac.mm | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/shell/browser/native_window_mac.h b/shell/browser/native_window_mac.h index 6ce521b5e95e4..777b63a66aafc 100644 --- a/shell/browser/native_window_mac.h +++ b/shell/browser/native_window_mac.h @@ -238,6 +238,8 @@ class NativeWindowMac : public NativeWindow, void InternalSetParentWindow(NativeWindow* parent, bool attach); void SetForwardMouseMessages(bool forward); + void UpdateZoomButton(); + ElectronNSWindow* window_; // Weak ref, managed by widget_. ElectronNSWindowDelegate* __strong window_delegate_; diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index cddd87cecbf59..42c024ca5b5db 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -887,8 +887,7 @@ void ReorderChildWindowAbove(NSWindow* child_window, NSWindow* other_window) { // the maximize button and ensure fullscreenability matches user setting. SetCanResize(resizable); SetFullScreenable(was_fullscreenable); - [[window_ standardWindowButton:NSWindowZoomButton] - setEnabled:resizable ? was_fullscreenable : false]; + UpdateZoomButton(); } bool NativeWindowMac::IsResizable() { @@ -916,19 +915,26 @@ void ReorderChildWindowAbove(NSWindow* child_window, NSWindow* other_window) { void NativeWindowMac::SetMaximizable(bool maximizable) { maximizable_ = maximizable; - [[window_ standardWindowButton:NSWindowZoomButton] setEnabled:maximizable]; + UpdateZoomButton(); } bool NativeWindowMac::IsMaximizable() { return [[window_ standardWindowButton:NSWindowZoomButton] isEnabled]; } +void NativeWindowMac::UpdateZoomButton() { + [[window_ standardWindowButton:NSWindowZoomButton] + setEnabled:(CanMaximize() && IsResizable()) || IsFullScreenable()]; +} + void NativeWindowMac::SetFullScreenable(bool fullscreenable) { SetCollectionBehavior(fullscreenable, NSWindowCollectionBehaviorFullScreenPrimary); // On EL Capitan this flag is required to hide fullscreen button. SetCollectionBehavior(!fullscreenable, NSWindowCollectionBehaviorFullScreenAuxiliary); + + UpdateZoomButton(); } bool NativeWindowMac::IsFullScreenable() { From caeb8d479e0c3b323a67a7414dce70d77e789451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Zahola?= Date: Tue, 5 Dec 2023 18:07:49 +0100 Subject: [PATCH 2/3] add test --- spec/api-browser-window-spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 050e05c3ea1e6..a76215278aee3 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -5611,6 +5611,19 @@ describe('BrowserWindow module', () => { expect(w2.isFullScreenable()).to.be.false('isFullScreenable'); expect(w3.isFullScreenable()).to.be.false('isFullScreenable'); }); + + it('does not disable maximize button if window is resizable', () => { + const w = new BrowserWindow({ + resizable: true, + fullscreenable: false + }); + + expect(w.isMaximizable()).to.be.true('isMaximizable'); + + w.setResizable(false); + + expect(w.isMaximizable()).to.be.false('isMaximizable'); + }); }); ifdescribe(process.platform === 'darwin')('isHiddenInMissionControl state', () => { From f3c10b86bcf8606205e370f577b7dae4752d372b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Zahola?= Date: Mon, 11 Dec 2023 17:00:11 +0100 Subject: [PATCH 3/3] fix test by enabling maximize button if `resizable && (maximizable || fullscreenable)` instead of `(resizable && maximizable) && fullscreenable` --- shell/browser/native_window_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 42c024ca5b5db..738b9c9deb23e 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -924,7 +924,7 @@ void ReorderChildWindowAbove(NSWindow* child_window, NSWindow* other_window) { void NativeWindowMac::UpdateZoomButton() { [[window_ standardWindowButton:NSWindowZoomButton] - setEnabled:(CanMaximize() && IsResizable()) || IsFullScreenable()]; + setEnabled:IsResizable() && (CanMaximize() || IsFullScreenable())]; } void NativeWindowMac::SetFullScreenable(bool fullscreenable) {