From d8872ff6aee4408e2b084e4139d6601b7999f2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pl=C3=ADnio=20Larrubia?= Date: Tue, 28 May 2024 09:57:50 -0300 Subject: [PATCH] May Update Hotfix 2 (#170) * Removing all the properties changed to **Enable-WindowsSpotlight** - Fix Remove-ItemPropertyVerified * Add warning when path was not found using Remove-ItemPropertyVerified * Fixed `Remove-ItemPropertyVerified` inaccurately reporting success - The property is now removed correctly, accepting more paths * Change resolution check to use the primary monitor's working area. (#168) Fixes oversized windows on multiple monitor setups when using dpi scaling. * Use Pascal Casing inside Get-CurrentResolution.psm1 - Remove unused variable $bounds --------- Co-authored-by: Haxy --- src/lib/ui/Get-CurrentResolution.psm1 | 43 +++++---------------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/src/lib/ui/Get-CurrentResolution.psm1 b/src/lib/ui/Get-CurrentResolution.psm1 index 864d4121..8efad0b2 100644 --- a/src/lib/ui/Get-CurrentResolution.psm1 +++ b/src/lib/ui/Get-CurrentResolution.psm1 @@ -5,45 +5,16 @@ function Get-CurrentResolution() { [OutputType([System.Object[]])] param () - # Adapted from: https://www.reddit.com/r/PowerShell/comments/67no9x/comment/dgrry3b/?utm_source=share&utm_medium=web2x&context=3 - $NumberOfScreens = (Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams | Where-Object { $_.Active -like "True" }).Active.Count - $ScreenWidth = $null - $ScreenHeight = $null + Add-Type -AssemblyName System.Windows.Forms - Write-Verbose "Num. of Monitors: $NumberOfScreens" + # Get the primary screen's working area, which takes DPI scaling into account + $PrimaryScreen = [System.Windows.Forms.Screen]::PrimaryScreen + $WorkingArea = $PrimaryScreen.WorkingArea - If ($NumberOfScreens -eq 1) { - # Accepts Scaling/DPI - [System.Windows.Forms.SystemInformation]::VirtualScreen | ForEach-Object { - Write-Verbose "W: $($_.Width) | H: $($_.Height)" + $ScreenWidth = $WorkingArea.Width + $ScreenHeight = $WorkingArea.Height - If (!$ScreenWidth -or !$ScreenHeight) { - $ScreenWidth = $_.Width - $ScreenHeight = $_.Height - } + Write-Verbose "Primary Monitor: Width: $ScreenWidth, Height: $ScreenHeight (DPI Scaled)" - If (($_.Width) -and ($_.Width -le $ScreenWidth)) { - $ScreenWidth = $_.Width - $ScreenHeight = $_.Height - } - } - } Else { - # Doesn't accepts Scaling/DPI (rollback method) - Get-CimInstance -Class "Win32_VideoController" | ForEach-Object { - Write-Verbose "W: $($_.CurrentHorizontalResolution) | H: $($_.CurrentVerticalResolution)" - - If (!$ScreenWidth -or !$ScreenHeight) { - $ScreenWidth = $_.CurrentHorizontalResolution - $ScreenHeight = $_.CurrentVerticalResolution - } - - If (($_.CurrentHorizontalResolution) -and ($_.CurrentHorizontalResolution -le $ScreenWidth)) { - $ScreenWidth = $_.CurrentHorizontalResolution - $ScreenHeight = $_.CurrentVerticalResolution - } - } - } - - Write-Verbose "Width: $ScreenWidth, Height: $ScreenHeight" return $ScreenWidth, $ScreenHeight }