fix: macOS maximize button shouldn't be disabled just because the window is non-fullscreenable (#40705)
* fix: macOS maximize button shouldn't be disabled just because the window is non-fullscreenable * add test * fix test by enabling maximize button if `resizable && (maximizable || fullscreenable)` instead of `(resizable && maximizable) && fullscreenable`
This commit is contained in:
parent
22970f573b
commit
cc1b64e01c
3 changed files with 24 additions and 3 deletions
|
@ -235,6 +235,8 @@ class NativeWindowMac : public NativeWindow,
|
||||||
void InternalSetParentWindow(NativeWindow* parent, bool attach);
|
void InternalSetParentWindow(NativeWindow* parent, bool attach);
|
||||||
void SetForwardMouseMessages(bool forward);
|
void SetForwardMouseMessages(bool forward);
|
||||||
|
|
||||||
|
void UpdateZoomButton();
|
||||||
|
|
||||||
ElectronNSWindow* window_; // Weak ref, managed by widget_.
|
ElectronNSWindow* window_; // Weak ref, managed by widget_.
|
||||||
|
|
||||||
ElectronNSWindowDelegate* __strong window_delegate_;
|
ElectronNSWindowDelegate* __strong window_delegate_;
|
||||||
|
|
|
@ -879,8 +879,7 @@ void NativeWindowMac::SetResizable(bool resizable) {
|
||||||
// the maximize button and ensure fullscreenability matches user setting.
|
// the maximize button and ensure fullscreenability matches user setting.
|
||||||
SetCanResize(resizable);
|
SetCanResize(resizable);
|
||||||
SetFullScreenable(was_fullscreenable);
|
SetFullScreenable(was_fullscreenable);
|
||||||
[[window_ standardWindowButton:NSWindowZoomButton]
|
UpdateZoomButton();
|
||||||
setEnabled:resizable ? was_fullscreenable : false];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeWindowMac::IsResizable() const {
|
bool NativeWindowMac::IsResizable() const {
|
||||||
|
@ -908,19 +907,26 @@ bool NativeWindowMac::IsMinimizable() const {
|
||||||
|
|
||||||
void NativeWindowMac::SetMaximizable(bool maximizable) {
|
void NativeWindowMac::SetMaximizable(bool maximizable) {
|
||||||
maximizable_ = maximizable;
|
maximizable_ = maximizable;
|
||||||
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:maximizable];
|
UpdateZoomButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeWindowMac::IsMaximizable() const {
|
bool NativeWindowMac::IsMaximizable() const {
|
||||||
return [[window_ standardWindowButton:NSWindowZoomButton] isEnabled];
|
return [[window_ standardWindowButton:NSWindowZoomButton] isEnabled];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::UpdateZoomButton() {
|
||||||
|
[[window_ standardWindowButton:NSWindowZoomButton]
|
||||||
|
setEnabled:IsResizable() && (CanMaximize() || IsFullScreenable())];
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetFullScreenable(bool fullscreenable) {
|
void NativeWindowMac::SetFullScreenable(bool fullscreenable) {
|
||||||
SetCollectionBehavior(fullscreenable,
|
SetCollectionBehavior(fullscreenable,
|
||||||
NSWindowCollectionBehaviorFullScreenPrimary);
|
NSWindowCollectionBehaviorFullScreenPrimary);
|
||||||
// On EL Capitan this flag is required to hide fullscreen button.
|
// On EL Capitan this flag is required to hide fullscreen button.
|
||||||
SetCollectionBehavior(!fullscreenable,
|
SetCollectionBehavior(!fullscreenable,
|
||||||
NSWindowCollectionBehaviorFullScreenAuxiliary);
|
NSWindowCollectionBehaviorFullScreenAuxiliary);
|
||||||
|
|
||||||
|
UpdateZoomButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeWindowMac::IsFullScreenable() const {
|
bool NativeWindowMac::IsFullScreenable() const {
|
||||||
|
|
|
@ -5611,6 +5611,19 @@ describe('BrowserWindow module', () => {
|
||||||
expect(w2.isFullScreenable()).to.be.false('isFullScreenable');
|
expect(w2.isFullScreenable()).to.be.false('isFullScreenable');
|
||||||
expect(w3.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', () => {
|
ifdescribe(process.platform === 'darwin')('isHiddenInMissionControl state', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue