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.
This commit is contained in:
Thorsten Ball
2024-09-28 16:06:00 +02:00
parent 870a1dae3d
commit 9bdefc3a4f

View File

@ -24,7 +24,7 @@ class FullScreenHandler {
default: default:
false false
} }
if isInFullscreen { if isInFullscreen {
if useNonNativeFullscreen || isInNonNativeFullscreen { if useNonNativeFullscreen || isInNonNativeFullscreen {
leaveFullscreen(window: window) leaveFullscreen(window: window)
@ -110,7 +110,8 @@ class FullScreenHandler {
window.styleMask.remove(.titled) window.styleMask.remove(.titled)
// Set frame to screen size, accounting for the menu bar if needed // 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) window.setFrame(frame, display: true)
// Focus window // Focus window
@ -141,14 +142,16 @@ class FullScreenHandler {
NSApp.presentationOptions.remove(.autoHideDock) 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 (subtractMenu) {
if let menuHeight = NSApp.mainMenu?.menuBarHeight { if let menuHeight = NSApp.mainMenu?.menuBarHeight {
var padding: CGFloat = 0 var padding: CGFloat = 0
// Detect the notch. If there is a safe area on top it includes the // 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. // 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; 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 return screen.frame
} }