From 9bdefc3a4f149c044c7e6f882505ceac2d13766f Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Sat, 28 Sep 2024 16:06:00 +0200 Subject: [PATCH] macOS non-native fullscreen: fix wrong position if tabbed This fixes a bug where the non-native fullscreen window would be slightly off screen and at the bottom there'd be a gap. Turns out we need to take the height of the tab bar into account, even if the non-native tabbing is activated. --- macos/Sources/Helpers/FullScreenHandler.swift | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/macos/Sources/Helpers/FullScreenHandler.swift b/macos/Sources/Helpers/FullScreenHandler.swift index d12809d71..742bb26c1 100644 --- a/macos/Sources/Helpers/FullScreenHandler.swift +++ b/macos/Sources/Helpers/FullScreenHandler.swift @@ -24,7 +24,7 @@ class FullScreenHandler { default: false } - + if isInFullscreen { if useNonNativeFullscreen || isInNonNativeFullscreen { leaveFullscreen(window: window) @@ -110,7 +110,8 @@ class FullScreenHandler { window.styleMask.remove(.titled) // Set frame to screen size, accounting for the menu bar if needed - let frame = calculateFullscreenFrame(screen: screen, subtractMenu: !hideMenu) + let windowHasTabs = previousTabGroup?.windows.isEmpty == false + let frame = calculateFullscreenFrame(screen: screen, subtractMenu: !hideMenu, windowHasTabs: windowHasTabs) window.setFrame(frame, display: true) // Focus window @@ -141,14 +142,16 @@ class FullScreenHandler { NSApp.presentationOptions.remove(.autoHideDock) } - func calculateFullscreenFrame(screen: NSScreen, subtractMenu: Bool)->NSRect { + func calculateFullscreenFrame(screen: NSScreen, subtractMenu: Bool, windowHasTabs: Bool)->NSRect { + let hasNotch = screen.safeAreaInsets.top > 0 + if (subtractMenu) { if let menuHeight = NSApp.mainMenu?.menuBarHeight { var padding: CGFloat = 0 // Detect the notch. If there is a safe area on top it includes the // menu height as a safe area so we also subtract that from it. - if (screen.safeAreaInsets.top > 0) { + if (hasNotch) { padding = screen.safeAreaInsets.top - menuHeight; } @@ -160,6 +163,17 @@ class FullScreenHandler { ) } } + + if (windowHasTabs && !hasNotch) { + // TODO: Figure out a proper way to get to the tabBarHeight + let tabBarHeight: CGFloat = 28; + return NSMakeRect( + screen.frame.minX, + screen.frame.minY - tabBarHeight, + screen.frame.width, + screen.frame.height + ) + } return screen.frame }