fix unwanted resize of non-native fullscreen window

Removing autoHideDock and autoHideMenuBar options cause window to
resize.

Fix #2516
This commit is contained in:
Dmitry Zhlobo
2024-12-07 19:46:39 +01:00
parent 2fb92dd4aa
commit 0d0aeccf0f

View File

@ -167,6 +167,9 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle {
self.savedState = savedState self.savedState = savedState
// We hide the dock if the window is on a screen with the dock. // We hide the dock if the window is on a screen with the dock.
// This is crazy but at least on macOS 15.0, you must hide the dock
// FIRST then hide the menu. If you do the opposite, it does not
// work.
if (savedState.dock) { if (savedState.dock) {
hideDock() hideDock()
} }
@ -176,18 +179,6 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle {
hideMenu() hideMenu()
} }
// When this window becomes or resigns main we need to run some logic.
NotificationCenter.default.addObserver(
self,
selector: #selector(windowDidBecomeMain),
name: NSWindow.didBecomeMainNotification,
object: window)
NotificationCenter.default.addObserver(
self,
selector: #selector(windowDidResignMain),
name: NSWindow.didResignMainNotification,
object: window)
// When we change screens we need to redo everything. // When we change screens we need to redo everything.
NotificationCenter.default.addObserver( NotificationCenter.default.addObserver(
self, self,
@ -218,8 +209,6 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle {
// Remove all our notifications. We remove them one by one because // Remove all our notifications. We remove them one by one because
// we don't want to remove the observers that our superclass sets. // we don't want to remove the observers that our superclass sets.
let center = NotificationCenter.default let center = NotificationCenter.default
center.removeObserver(self, name: NSWindow.didBecomeMainNotification, object: window)
center.removeObserver(self, name: NSWindow.didResignMainNotification, object: window)
center.removeObserver(self, name: NSWindow.didChangeScreenNotification, object: window) center.removeObserver(self, name: NSWindow.didChangeScreenNotification, object: window)
// Unhide our elements // Unhide our elements
@ -311,42 +300,6 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle {
exit() exit()
} }
@objc func windowDidBecomeMain(_ notification: Notification) {
guard let savedState else { return }
// This should always be true due to how we register but just be sure
guard let object = notification.object as? NSWindow,
object == window else { return }
// This is crazy but at least on macOS 15.0, you must hide the dock
// FIRST then hide the menu. If you do the opposite, it does not
// work.
if savedState.dock {
hideDock()
}
if (properties.hideMenu) {
hideMenu()
}
}
@objc func windowDidResignMain(_ notification: Notification) {
guard let savedState else { return }
// This should always be true due to how we register but just be sure
guard let object = notification.object as? NSWindow,
object == window else { return }
if (properties.hideMenu) {
unhideMenu()
}
if savedState.dock {
unhideDock()
}
}
// MARK: Dock // MARK: Dock
private func hideDock() { private func hideDock() {