From 0d0aeccf0fdc01a97fba0832b9af6303995b90c1 Mon Sep 17 00:00:00 2001 From: Dmitry Zhlobo Date: Sat, 7 Dec 2024 19:46:39 +0100 Subject: [PATCH] fix unwanted resize of non-native fullscreen window Removing autoHideDock and autoHideMenuBar options cause window to resize. Fix #2516 --- macos/Sources/Helpers/Fullscreen.swift | 53 ++------------------------ 1 file changed, 3 insertions(+), 50 deletions(-) diff --git a/macos/Sources/Helpers/Fullscreen.swift b/macos/Sources/Helpers/Fullscreen.swift index bb3859e07..ca93ac533 100644 --- a/macos/Sources/Helpers/Fullscreen.swift +++ b/macos/Sources/Helpers/Fullscreen.swift @@ -167,6 +167,9 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle { self.savedState = savedState // 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) { hideDock() } @@ -176,18 +179,6 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle { 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. NotificationCenter.default.addObserver( self, @@ -218,8 +209,6 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle { // Remove all our notifications. We remove them one by one because // we don't want to remove the observers that our superclass sets. 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) // Unhide our elements @@ -311,42 +300,6 @@ class NonNativeFullscreen: FullscreenBase, FullscreenStyle { 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 private func hideDock() {