From fdaa1d863a3e8ee92cae37cecc640365396b855d Mon Sep 17 00:00:00 2001 From: BREW <81044362+b-re-w@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:22:15 +0900 Subject: [PATCH] Test: Count a parked window at its nearest monitor's scale A window opened on a 200 percent primary and parked nearest a 125 percent monitor rightly takes that monitor's scale, and the check that the scale never changed made every scene NOT_DRIVEN on such a machine. The parked window must now settle at the DPI of the monitor it is nearest, which still rejects a window that dropped to the system scale on a single 200 percent monitor. Co-Authored-By: Claude Opus 5.5 --- scripts/tests/windows-features-lib.ps1 | 12 ++++++++++++ scripts/tests/windows-features.ps1 | 13 ++++++++----- scripts/tests/windows-features.selftest.ps1 | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/scripts/tests/windows-features-lib.ps1 b/scripts/tests/windows-features-lib.ps1 index 5f4d50f..bf2944b 100644 --- a/scripts/tests/windows-features-lib.ps1 +++ b/scripts/tests/windows-features-lib.ps1 @@ -497,3 +497,15 @@ function Test-FirstFrames($Frames, $Steady, [int]$X0, [int]$X1, [int]$Y1) { function Test-VisibleBreach([bool]$OnMonitor, [string]$TestDesktop) { $OnMonitor -and -not $TestDesktop } + +# Why a parked window's scale does not count, or $null when it does. `Scales` are the layout DPIs +# the runtime traced for the window, first to last, and `MonitorDpi` is the DPI of the monitor the +# park is nearest. A window opened on one monitor and parked nearest another of another scale +# rightly takes that monitor's scale. Any other scale, such as the system scale a window level with +# a monitor's band can drop to, would run every row at a scale no person's window has there. +function Get-ParkScaleError([int[]]$Scales, [int]$MonitorDpi) { + if (-not $Scales -or $Scales.Count -eq 0 -or $MonitorDpi -le 0) { return $null } + $settled = $Scales[-1] + if ($settled -eq $MonitorDpi) { return $null } + "the parked window settled at scale $settled (first $($Scales[0])), not at its nearest monitor's $MonitorDpi" +} diff --git a/scripts/tests/windows-features.ps1 b/scripts/tests/windows-features.ps1 index c999c99..9e7755b 100644 --- a/scripts/tests/windows-features.ps1 +++ b/scripts/tests/windows-features.ps1 @@ -76,6 +76,10 @@ public static class FeatureWin{ [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h,out uint p); [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr h); [DllImport("user32.dll")] public static extern bool IsWindow(IntPtr h); + [DllImport("user32.dll")] static extern IntPtr MonitorFromWindow(IntPtr h,uint f); + [DllImport("shcore.dll")] static extern int GetDpiForMonitor(IntPtr m,int type,out uint x,out uint y); + // The effective DPI of the monitor nearest the window, or 0 when it cannot be read. + public static int NearestMonitorDpi(IntPtr h){uint x,y;return GetDpiForMonitor(MonitorFromWindow(h,2),0,out x,out y)==0?(int)x:0;} [DllImport("user32.dll")] public static extern IntPtr GetWindow(IntPtr h,uint c); [DllImport("user32.dll",CharSet=CharSet.Unicode)] public static extern int GetClassName(IntPtr h,StringBuilder s,int n); [DllImport("user32.dll",CharSet=CharSet.Unicode)] public static extern IntPtr GetProp(IntPtr h,string n); @@ -300,13 +304,12 @@ function Open-Scene($ctx, $state, $Url, $Seed, [string[]]$Extra = @()) { [FeatureWin]::PostMessage($ctx.Hwnd, 0x86, [IntPtr]1, [IntPtr]0) | Out-Null Start-Sleep 8 $dpi = Get-LayoutDpi $ctx - # The window must keep the scale it was first laid out at: a park that moves it to another scale - # would run every row at a scale no person's window has there. + # The parked window must settle at the scale of the monitor it is nearest, as a person's window + # there has; Get-ParkScaleError says why another scale does not count. $hex = '{0:x}' -f $ctx.Hwnd.ToInt64() $scales = @(Read-Log | Where-Object { $_ -match "^layout dpi: window 0x$hex at (\d+)$" } | ForEach-Object { [int]($_ -replace '.* at ', '') }) - if ($scales.Count -ge 2 -and $scales[0] -ne $scales[-1] -and -not $ctx.Error) { - $ctx.Error = "the window's scale changed after it was parked: $($scales[0]) then $($scales[-1])" - } + $parkScale = Get-ParkScaleError $scales ([FeatureWin]::NearestMonitorDpi($ctx.Hwnd)) + if ($parkScale -and -not $ctx.Error) { $ctx.Error = $parkScale } if ($dpi) { $ctx.Dpi = $dpi } elseif (-not $ctx.Error) { $ctx.Error = 'the runtime traced no scale for the window' } # Every scene checks that the attach finished: the browser laid the window out for Rivet's frame. if (-not $ctx.Error) { diff --git a/scripts/tests/windows-features.selftest.ps1 b/scripts/tests/windows-features.selftest.ps1 index 4d4ade1..3f31a29 100644 --- a/scripts/tests/windows-features.selftest.ps1 +++ b/scripts/tests/windows-features.selftest.ps1 @@ -377,5 +377,23 @@ foreach ($case in @(@($true, '', $true), @($true, 'WinSta0\rivet-test-1', $false if ($breach) { Write-Host "FAIL nfr5_only_the_persons_desktop_has_visible_monitors : $breach cases"; $failures++ } else { Write-Host 'ok nfr5_only_the_persons_desktop_has_visible_monitors' } +# A parked window counts at its nearest monitor's scale only. +$park = 0 +foreach ($case in @( + # Opened on a 200 percent primary, parked nearest a 125 percent monitor. + @(@(192, 120), 120, $true), + # One monitor at 200 percent: the window dropped to the system scale. + @(@(192, 96), 192, $false), + # Parked nearest a 125 percent monitor but left at the scale it opened at. + @(@(192), 120, $false), + @(@(120), 120, $true), + # No scale traced, or no monitor read: the scene's own checks say so. + @(@(), 120, $true), + @(@(192, 96), 0, $true))) { + if ([bool](-not (Get-ParkScaleError $case[0] $case[1])) -ne $case[2]) { $park++ } +} +if ($park) { Write-Host "FAIL nfr5_a_parked_window_counts_at_its_nearest_monitors_scale_only : $park cases"; $failures++ } +else { Write-Host 'ok nfr5_a_parked_window_counts_at_its_nearest_monitors_scale_only' } + if ($failures) { Write-Host "$failures failed"; exit 1 } Write-Host 'windows-features selftest: all passed'