fix(display): correct window HiDPI advice and fullscreen fallback

This commit is contained in:
cxykhaos committed 2026-12-02 22:08:50 +08:00
1 parent 10ce7eb0dd
commit 037047ea43
4 files changed
+59 -9

No files matched your search

+40 -1
View File
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict'
import test from 'node:test'
import { loadTestModule } from './load-test-module.mjs'
const { windowDisplayPresets, recommendedDisplayPresets, recommendedResolution } =
const { windowDisplayPresets, fullscreenDisplayPresets, recommendedDisplayPresets, recommendedResolution, hostDisplayAdvice, canKeepDisplayPreset } =
await loadTestModule(`export * from './lib/format'`)
function profile(width, height) {
@@ -52,6 +52,45 @@ test('native guest HiDPI metadata is preserved when scaling into a window', () =
assert.equal(preset.scaleToFit, true)
})
test('window HiDPI presets suppress only the contradictory fullscreen advice', () => {
const host = { ...profile(2560, 1600), fullscreen_hidpi: true, hidpi_advice: 'fullscreen' }
const tr = (key) => key
assert.equal(hostDisplayAdvice(host, tr, windowDisplayPresets(host, false)), 'hidpiTipFullscreen')
assert.equal(hostDisplayAdvice(host, tr, windowDisplayPresets(host, true)), undefined)
assert.equal(hostDisplayAdvice({ ...host, hidpi_advice: 'scale' }, tr, windowDisplayPresets(host, true)), 'hidpiTipScale')
assert.equal(hostDisplayAdvice({ ...host, hidpi_advice: 'unavailable' }, tr, windowDisplayPresets(host, true)), 'hidpiTipUnavailable')
})
test('fullscreen round trips return to fit presets instead of implicitly opting into scaling', () => {
for (const fixedModeSupported of [false, true]) {
const host = profile(2560, 1440)
const windows = windowDisplayPresets(host, fixedModeSupported)
const full = fullscreenDisplayPresets(host)
const switchMode = (resolution, borderless) => {
const list = borderless ? full : windows
return list.some((p) => canKeepDisplayPreset(p, resolution, borderless))
? resolution
: list.find((p) => p.recommended)?.resolution ?? list[0].resolution
}
const native = switchMode('1920x1080', true)
assert.equal(native, '2560x1440')
assert.equal(switchMode(native, false), '1920x1080')
assert.equal(switchMode('1600x900', false), '1600x900')
}
const native = windowDisplayPresets(profile(2560, 1440), true).at(-1)
assert.equal(native.scaleToFit, true) // Still available for explicit window-mode selection.
assert.equal(canKeepDisplayPreset(native, '2560 × 1440', true), true)
assert.equal(canKeepDisplayPreset(native, '2560 × 1440', false), false)
})
test('new scaled window presets stay within the supported 5K bounds', () => {
for (const [width, height] of [[6016, 3384], [7680, 2160], [5120, 3202]]) {
const host = profile(width, height)
assert.strictEqual(windowDisplayPresets(host, true), host.display_presets)
}
assert.equal(windowDisplayPresets(profile(5120, 3200), true).at(-1).resolution, '5120x3200')
})
test('the effective target profile determines the added window resolution', () => {
const primary = profile(3840, 2160)
const target = { ...primary, primary_display: { width: 2560, height: 1600, scale_pct: 150 } }
+7 -4
View File
@@ -18,6 +18,7 @@ import {
memorySafeLimitGB,
parseMemoryGB,
recommendedCPUs,
canKeepDisplayPreset,
fullscreenDisplayPresets,
FullscreenDisplayPreset,
hidpiLooksLike,
@@ -129,6 +130,8 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported
start: true,
})
const set = (patch: Partial<CreateOpts>) => setOpts((o) => ({ ...o, ...patch }))
const windowPresets = windowDisplayPresets(host, fixedModeSupported)
const fullscreenPresets = fullscreenDisplayPresets(host)
const buildPayload = (): CreateOpts => {
const p: CreateOpts = { ...opts, offline: opts.source_mode === 'offline' }
@@ -556,14 +559,14 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported
title={tr('resolution')}
disabled={opts.graphics !== 'reims-vgpu'}
reason={tr('gpuSvgaReason')}
desc={[hostDisplayDesc(host, tr), !opts.borderless ? hostDisplayAdvice(host, tr) : undefined].filter(Boolean).join(' · ') || undefined}
desc={[hostDisplayDesc(host, tr), !opts.borderless ? hostDisplayAdvice(host, tr, windowPresets) : undefined].filter(Boolean).join(' · ') || undefined}
control={
<PopupSelect
id="vm-res"
label={tr('resolution')}
value={opts.resolution}
onChange={(resolution) => set({ resolution })}
options={(opts.borderless ? fullscreenDisplayPresets(host) : windowDisplayPresets(host, fixedModeSupported)).map((p: FullscreenDisplayPreset) => ({
options={(opts.borderless ? fullscreenPresets : windowPresets).map((p: FullscreenDisplayPreset) => ({
value: p.resolution,
label: p.label,
detail: [
@@ -629,8 +632,8 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported
label={tr('fullscreenLaunch')}
checked={!!opts.borderless}
onChange={(borderless) => {
const list = borderless ? fullscreenDisplayPresets(host) : windowDisplayPresets(host, fixedModeSupported)
const keep = list.some((p) => p.resolution === opts.resolution)
const list = borderless ? fullscreenPresets : windowPresets
const keep = list.some((p) => canKeepDisplayPreset(p, opts.resolution, borderless))
const fallback = list.find((p) => p.recommended)?.resolution ?? list[0]?.resolution ?? opts.resolution
set(keep ? { borderless } : { borderless, resolution: fallback })
}}
+3 -2
View File
@@ -17,6 +17,7 @@ import {
memorySafeLimitGB,
parseMemoryGB,
recommendedCPUs,
canKeepDisplayPreset,
fullscreenDisplayPresets,
FullscreenDisplayPreset,
hidpiLooksLike,
@@ -985,11 +986,11 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, driverID, stats
const selectedGPUHint = gpuCompatHint(locale, selectedGPU)
const vgpu = form.graphics !== 'vmware-svga'
const targetDisp = activeTargetDisplay
const hidpiAdvice = hostDisplayAdvice(displayProfile, tr)
const hidpiAdvice = hostDisplayAdvice(displayProfile, tr, presets)
const resValue = customRes ? CUSTOM : activePresets.find((p) => same('resolution', p.resolution, form.resolution))?.resolution
const toggleBorderless = (borderless: boolean) => {
const targetPresets = borderless ? fsPresets : presets
if (!customRes && !targetPresets.some((p) => same('resolution', p.resolution, form.resolution))) {
if (!customRes && !targetPresets.some((p) => canKeepDisplayPreset(p, form.resolution, borderless))) {
const nextRes = borderless
? (targetDisp && targetDisp.width > 0 && targetDisp.height > 0
? `${targetDisp.width}x${targetDisp.height}`
+9 -2
View File
@@ -280,7 +280,8 @@ export function hostDisplayDesc(
// How to get a HiDPI (sharp-text) macOS desktop when no window size gives
// one on this screen; undefined when one does.
export function hostDisplayAdvice(host: HostReport, tr: Tr): string | undefined {
export function hostDisplayAdvice(host: HostReport, tr: Tr, windowPresets: DisplayPreset[] = recommendedDisplayPresets(host)): string | undefined {
if (host.hidpi_advice === 'fullscreen' && windowPresets.some((p) => p.hidpi)) return undefined
const tip: Record<string, I18nKey> = {
fullscreen: 'hidpiTipFullscreen',
scale: 'hidpiTipScale',
@@ -310,11 +311,17 @@ export interface FullscreenDisplayPreset extends DisplayPreset {
scaleToFit?: boolean
}
/** Scaling into a window is opt-in, not an automatic fullscreen-to-window fallback. */
export function canKeepDisplayPreset(preset: FullscreenDisplayPreset, resolution: string | undefined, borderless: boolean): boolean {
const normalize = (value: string) => value.trim().toLowerCase().replace(/\s+/g, '').replace('×', 'x')
return resolution !== undefined && normalize(preset.resolution) === normalize(resolution) && (borderless || !preset.scaleToFit)
}
/** Preserve fit recommendations; fixed-mode runtimes can scale native guest pixels into a window. */
export function windowDisplayPresets(host: HostReport, fixedModeSupported: boolean): FullscreenDisplayPreset[] {
const presets = recommendedDisplayPresets(host)
const d = host.primary_display
if (!fixedModeSupported || !d || d.width < 2560 || d.height < 1440) return presets
if (!fixedModeSupported || !d || d.width < 2560 || d.height < 1440 || d.width > 5120 || d.height > 3200) return presets
const resolution = `${d.width}x${d.height}`
if (presets.some((p) => p.resolution === resolution)) return presets
return [...presets, {