Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: macOS maximize button shouldn't be disabled just because the window is non-fullscreenable #40705

Merged
merged 3 commits into from Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions shell/browser/native_window_mac.h
Expand Up @@ -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_;
Expand Down
12 changes: 9 additions & 3 deletions shell/browser/native_window_mac.mm
Expand Up @@ -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() {
Expand Down Expand Up @@ -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:IsResizable() && (CanMaximize() || 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() {
Expand Down
13 changes: 13 additions & 0 deletions spec/api-browser-window-spec.ts
Expand Up @@ -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', () => {
Expand Down