Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions apps/desktop/src/app/shell/app-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,21 @@ function subscribeWindowSize(cb: () => void) {
}
}

const viewportIsFullscreen = () =>
window.innerWidth >= window.screen.width && window.innerHeight >= window.screen.height
export const viewportIsFullscreen = () => {
if (window.innerWidth < window.screen.width || window.innerHeight < window.screen.height) {
return false
}
// On macOS, true fullscreen (green button) hides the menu bar, making
// screen.availHeight equal to screen.height. "Zoom" (double-click titlebar
// to fill the screen) keeps the menu bar visible, so availHeight < height.
// In zoom mode the traffic-light buttons are still visible at the top-left,
// so we must NOT treat it as fullscreen β€” otherwise the titlebar controls
// shift underneath them (issue #45264).
if (window.screen.availHeight < window.screen.height) {
return false
}
return true
}

export function AppShell({
children,
Expand Down
44 changes: 43 additions & 1 deletion apps/desktop/src/app/shell/titlebar.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { describe, expect, it } from 'vitest'
// @vitest-environment jsdom
import { describe, expect, it, vi, afterEach } from 'vitest'

import {
TITLEBAR_CONTROL_OFFSET_X,
TITLEBAR_EDGE_INSET,
TITLEBAR_FALLBACK_WINDOW_BUTTON_X,
titlebarControlsPosition
} from './titlebar'
import { viewportIsFullscreen } from './app-shell'

describe('titlebarControlsPosition', () => {
it('offsets controls from visible traffic lights', () => {
Expand All @@ -24,3 +26,43 @@ describe('titlebarControlsPosition', () => {
expect(titlebarControlsPosition(undefined).left).toBe(TITLEBAR_FALLBACK_WINDOW_BUTTON_X + TITLEBAR_CONTROL_OFFSET_X)
})
})

describe('viewportIsFullscreen', () => {
afterEach(() => {
vi.restoreAllMocks()
})

function mockScreen(overrides: Partial<Screen>) {
const defaults = { width: 1920, height: 1080, availHeight: 1080, availWidth: 1920 }
Object.defineProperty(window, 'screen', { value: { ...defaults, ...overrides }, configurable: true })
}

it('returns false when viewport is smaller than screen', () => {
mockScreen({ width: 1920, height: 1080 })
vi.stubGlobal('innerWidth', 1600)
vi.stubGlobal('innerHeight', 900)
expect(viewportIsFullscreen()).toBe(false)
})

it('returns true for true macOS fullscreen (menu bar hidden, availHeight equals height)', () => {
mockScreen({ width: 1920, height: 1080, availHeight: 1080, availWidth: 1920 })
vi.stubGlobal('innerWidth', 1920)
vi.stubGlobal('innerHeight', 1080)
expect(viewportIsFullscreen()).toBe(true)
})

it('returns false for macOS zoom (menu bar visible, availHeight < height) β€” #45264', () => {
// macOS menu bar is 25px; availHeight is screen.height minus menu bar
mockScreen({ width: 1920, height: 1080, availHeight: 1055, availWidth: 1920 })
vi.stubGlobal('innerWidth', 1920)
vi.stubGlobal('innerHeight', 1055)
expect(viewportIsFullscreen()).toBe(false)
})

it('returns true on Windows/Linux where availHeight equals height (no menu bar)', () => {
mockScreen({ width: 1920, height: 1080, availHeight: 1080, availWidth: 1920 })
vi.stubGlobal('innerWidth', 1920)
vi.stubGlobal('innerHeight', 1080)
expect(viewportIsFullscreen()).toBe(true)
})
})
Loading