Skip to content
Merged
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
12 changes: 12 additions & 0 deletions scripts/tests/windows-features-lib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
13 changes: 8 additions & 5 deletions scripts/tests/windows-features.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions scripts/tests/windows-features.selftest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Loading