mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: macOS maximize button shouldn't be disabled just because the window is non-fullscreenable (#40895)
* fix: macOS maximize button shouldn't be disabled just because the window is non-fullscreenable Co-authored-by: Tamás Zahola <tzahola@gmail.com> * add test Co-authored-by: Tamás Zahola <tzahola@gmail.com> * fix test by enabling maximize button if `resizable && (maximizable || fullscreenable)` instead of `(resizable && maximizable) && fullscreenable` Co-authored-by: Tamás Zahola <tzahola@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Tamás Zahola <tzahola@gmail.com>
This commit is contained in:
@@ -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_;
|
||||
|
||||
@@ -863,8 +863,7 @@ void NativeWindowMac::SetResizable(bool resizable) {
|
||||
// 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() {
|
||||
@@ -892,19 +891,26 @@ bool NativeWindowMac::IsMinimizable() {
|
||||
|
||||
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() {
|
||||
|
||||
@@ -5622,6 +5622,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', () => {
|
||||
|
||||
Reference in New Issue
Block a user