155 lines
4.5 KiB
PowerShell
155 lines
4.5 KiB
PowerShell
<#
|
|
Generate-FancyZones 'Sz 4K' $(
|
|
# Generate-FancyZones 'Playground' $(
|
|
[ordered]@{
|
|
Q =@(01,01),@(01,13),@(13,01),@(13,13);
|
|
NT=@(01,01),@(10,01),@(13,01),@(16,01);
|
|
X1=@(10,01);
|
|
N1=@(16,01),@(10,01),@(01,01);
|
|
W1=@(10,01),@(13,01);
|
|
S1=@(10,01),@(22,01);
|
|
N3=@(01,11),@(16,01);
|
|
X3=@(01,11),(10,11);
|
|
XL=@(01,14),(7,14);
|
|
XX=@(01,11),(7,11);
|
|
F3=@(01,11);
|
|
}) -Verbose -WhatIf
|
|
|
|
Generate-FancyZones 'Sz 1920x1080' $(
|
|
# Generate-FancyZones 'Playground' $(
|
|
[ordered]@{
|
|
BNT=@(01,01);
|
|
BW1=@(11,01);
|
|
BW2=@(11,12);
|
|
BSQ=@(11,01),@(11,12),@(15,01),@(15,12)
|
|
}) -Verbose -WhatIf
|
|
|
|
#>
|
|
|
|
<#
|
|
#>
|
|
[CmdletBinding()]param(
|
|
|
|
[ArgumentCompleter({ param (
|
|
$commandName,
|
|
$parameterName,
|
|
$wordToComplete,
|
|
$commandAst,
|
|
$fakeBoundParameters
|
|
)
|
|
$local:ptDataPath = Join-Path $env:LOCALAPPDATA "Microsoft\PowerToys"
|
|
$local:fzJsonPath = Join-Path $ptDataPath "FancyZones\zones-settings.json"
|
|
Get-Content $fzJsonPath | ConvertFrom-Json |
|
|
Select-Object -ExpandProperty 'custom-zone-sets' |
|
|
Where-Object 'type' -eq 'canvas' |
|
|
Select-Object -ExpandProperty name |
|
|
ForEach-Object {
|
|
"'$_'"
|
|
}
|
|
})]
|
|
[Parameter(Mandatory,Position=0)]
|
|
[string]$FancyZoneName,
|
|
[int]$RatioW=24,[int]$RatioH=24,
|
|
[ValidateNotNullOrEmpty()]
|
|
$presetSizes=[ordered]@{
|
|
N1 = @(9,10)
|
|
W1 = @(12,10)
|
|
X1 = @(15,10)
|
|
F1 = @(24,10)
|
|
N2 = @(9,12)
|
|
X2 = @(15,12)
|
|
F2 = @(24,12)
|
|
N3 = @(9,14)
|
|
W3 = @(12,14)
|
|
X3 = @(15,14)
|
|
XL = @(18,11)
|
|
XX = @(18,14)
|
|
F3 = @(24,14)
|
|
NT = @(9,24)
|
|
WT = @(12,24)
|
|
XT = @(15,24)
|
|
S1 = @(3,10)
|
|
Q = @(12,12)
|
|
|
|
BNT = @(10,24)
|
|
BW1 = @(14,11)
|
|
BW2 = @(14,13)
|
|
BSQ = @(10,13)
|
|
},
|
|
[Parameter(ParameterSetName="AutoSections",
|
|
Mandatory,Position=1)]
|
|
$AutoSections,
|
|
[Parameter(ParameterSetName="Sections",
|
|
Mandatory,ValueFromRemainingArguments)]
|
|
[int[][]]$Sections,
|
|
[switch]$WhatIf
|
|
)
|
|
|
|
$local:ptDataPath = Join-Path $env:LOCALAPPDATA "Microsoft\PowerToys"
|
|
$local:fzJsonPath = Join-Path $ptDataPath "FancyZones\zones-settings.json"
|
|
$fzJson = Get-Content $fzJsonPath | ConvertFrom-Json
|
|
|
|
$local:fancyZone = $fzJson.'custom-zone-sets' |
|
|
Where-Object 'type' -eq 'canvas' |
|
|
Where-Object 'name' -eq $FancyZoneName
|
|
|
|
if( -not $fancyZone ) {
|
|
Write-Error "`nFancy Zone $FancyZoneName not matched to a valid zone`n`n"
|
|
return
|
|
}
|
|
|
|
$local:TotalWidth = $fancyZone.info.'ref-width'
|
|
$local:TotalHeight = $fancyZone.info.'ref-height'
|
|
|
|
$local:wFactor = $TotalWidth / $RatioW
|
|
$local:hFactor = $TotalHeight / $RatioH
|
|
|
|
Write-Verbose "$(
|
|
)$($fancyZone.uuid) - $($fancyZone.name)`n$(" "*10
|
|
)W = $TotalWidth / $RatioW = $([Math]::Round($wFactor,3)); $(
|
|
)H = $TotalHeight / $RatioH = $([Math]::Round($hFactor,3));"
|
|
|
|
$fancyZone.info.zones = @()
|
|
if( $AutoSections ) {
|
|
foreach( $local:p in $AutoSections.Keys ) {
|
|
$local:psW = [Math]::Round(($presetSizes."$p")[0] * $wFactor,0)
|
|
$local:psH = [Math]::Round(($presetSizes."$p")[1] * $hFactor,0)
|
|
$local:pairs = $AutoSections[$p]
|
|
if( $pairs[0] -is [int] ) {
|
|
$pairs = , $pairs
|
|
}
|
|
foreach( $local:s in $pairs ) {
|
|
Write-Verbose "$p : $($s | Join-String -Separator ", ")"
|
|
$fancyZone.info.zones += [ordered]@{
|
|
X = [Math]::Round(($s[0] - 1) * $wFactor,0)
|
|
Y = [Math]::Round(($s[1] - 1) * $hFactor,0)
|
|
width = $psW
|
|
height = $psH
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
foreach ( $local:s in $Sections ) {
|
|
$fancyZone.info.zones += [ordered]@{
|
|
X = [Math]::Round($s[0] * $wFactor,0)
|
|
Y = [Math]::Round($s[1] * $hFactor,0)
|
|
width = [Math]::Round($s[2] * $wFactor,0)
|
|
height = [Math]::Round($s[3] * $hFactor,0)
|
|
}
|
|
}
|
|
}
|
|
|
|
$fzJson.'custom-zone-sets' |
|
|
Where-Object name -eq $FancyZoneName |
|
|
ForEach-Object {
|
|
$_.info.zones = $fancyZone.info.zones
|
|
}
|
|
|
|
if( -not $WhatIf -and -not $WhatIfPreference ) {
|
|
if( -not (Test-Path "$fzJsonPath.bak") ) {
|
|
Copy-Item $fzJsonPath "$fzJsonPath.bak"
|
|
}
|
|
$fzJson | ConvertTo-Json -Depth 5 | ForEach-Object { $_ -replace '\.0(,?\r?\n)','$1' } | Out-File $fzJsonPath
|
|
} else {
|
|
$fancyZone | ConvertTo-Json -Depth 5 | ForEach-Object { $_ -replace '\.0(,?\r?\n)','$1' }
|
|
} |