ai-battery 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +369 -365
- package/bin/ai-battery-hud +0 -0
- package/bin/ai-battery-hud.js +0 -0
- package/bin/ai-battery-hud.ps1 +2 -2
- package/bin/ai-battery-run +80 -16
- package/bin/ai-battery-run-win.js +0 -0
- package/bin/ai-battery.js +0 -0
- package/bin/codex-wrapper-win.cjs +167 -167
- package/docs/RELEASING.md +64 -62
- package/docs/claude-statusline-preview.svg +37 -37
- package/docs/terminal-preview.svg +44 -44
- package/lib/cli.js +22 -10
- package/lib/platforms/process-scanner.js +7 -4
- package/lib/platforms/windows/codex-runner.js +49 -8
- package/lib/platforms/windows/hud/controls.ps1 +403 -403
- package/lib/platforms/windows/hud/dock.ps1 +731 -731
- package/lib/platforms/windows/hud/main.ps1 +1277 -1277
- package/lib/platforms/windows/hud/native.ps1 +169 -169
- package/lib/platforms/windows/hud/rendering.ps1 +382 -382
- package/lib/platforms/windows/hud/snapshot.ps1 +358 -358
- package/lib/platforms/windows/hud/windowing.ps1 +331 -331
- package/package.json +75 -76
- package/scripts/windows-rowpty-smoke.ps1 +766 -766
- package/scripts/wsl-windows-rowpty-smoke.sh +0 -0
- package/vendor/rowpty/RowPty.cs +2668 -2668
- package/lib/README.md +0 -20
|
@@ -3,30 +3,30 @@ $script:dockSession = [Int64]$DockSession
|
|
|
3
3
|
$script:dockSessions = @{}
|
|
4
4
|
$script:dockSessionTrackingEnabled = $false
|
|
5
5
|
$script:dockLastSessionSweepUtc = [datetime]::MinValue
|
|
6
|
-
$script:dockRequestLastWriteUtc = [datetime]::MinValue
|
|
7
|
-
$script:dockLastPlacement = $null
|
|
8
|
-
$script:dockSpaceReserved = $false
|
|
9
|
-
$script:dockTargetWasZoomed = $false
|
|
10
|
-
$script:dockBorderAdjusted = $false
|
|
11
|
-
$script:dockOriginalBorderColor = [AiBatteryNative]::DWMWA_COLOR_DEFAULT
|
|
12
|
-
$script:dockMoveSizeActive = $false
|
|
13
|
-
$script:dockGlobalDragActive = $false
|
|
14
|
-
$script:dockObservedFrameDragActive = $false
|
|
15
|
-
$script:dockObservedRawRectKey = ""
|
|
6
|
+
$script:dockRequestLastWriteUtc = [datetime]::MinValue
|
|
7
|
+
$script:dockLastPlacement = $null
|
|
8
|
+
$script:dockSpaceReserved = $false
|
|
9
|
+
$script:dockTargetWasZoomed = $false
|
|
10
|
+
$script:dockBorderAdjusted = $false
|
|
11
|
+
$script:dockOriginalBorderColor = [AiBatteryNative]::DWMWA_COLOR_DEFAULT
|
|
12
|
+
$script:dockMoveSizeActive = $false
|
|
13
|
+
$script:dockGlobalDragActive = $false
|
|
14
|
+
$script:dockObservedFrameDragActive = $false
|
|
15
|
+
$script:dockObservedRawRectKey = ""
|
|
16
16
|
$script:dockSnapPreviewActive = $false
|
|
17
17
|
$script:dockShellSnapFlyoutActive = $false
|
|
18
18
|
$script:dockTargetForegroundAtUtc = [datetime]::MinValue
|
|
19
|
-
$script:dockPendingMoveSizeState = $null
|
|
20
|
-
$script:dockShowAfterMoveSizeUtc = [datetime]::MinValue
|
|
21
|
-
$script:dockFastTrackingUntilUtc = [datetime]::MinValue
|
|
22
|
-
$script:dockActiveTrackingInterval = 16
|
|
23
|
-
$script:dockIdleTrackingInterval = 150
|
|
24
|
-
$script:dockUnavailableSinceUtc = [datetime]::MinValue
|
|
25
|
-
$script:dockFrameInsetsValid = $false
|
|
26
|
-
$script:dockFrameInsetLeft = 0
|
|
27
|
-
$script:dockFrameInsetTop = 0
|
|
28
|
-
$script:dockFrameInsetRight = 0
|
|
29
|
-
$script:dockFrameInsetBottom = 0
|
|
19
|
+
$script:dockPendingMoveSizeState = $null
|
|
20
|
+
$script:dockShowAfterMoveSizeUtc = [datetime]::MinValue
|
|
21
|
+
$script:dockFastTrackingUntilUtc = [datetime]::MinValue
|
|
22
|
+
$script:dockActiveTrackingInterval = 16
|
|
23
|
+
$script:dockIdleTrackingInterval = 150
|
|
24
|
+
$script:dockUnavailableSinceUtc = [datetime]::MinValue
|
|
25
|
+
$script:dockFrameInsetsValid = $false
|
|
26
|
+
$script:dockFrameInsetLeft = 0
|
|
27
|
+
$script:dockFrameInsetTop = 0
|
|
28
|
+
$script:dockFrameInsetRight = 0
|
|
29
|
+
$script:dockFrameInsetBottom = 0
|
|
30
30
|
$script:dockTargetFrameChangedAtUtc = [datetime]::MinValue
|
|
31
31
|
|
|
32
32
|
function Get-DockSessionKey([Int64]$Session, [string]$Provider) {
|
|
@@ -162,151 +162,151 @@ function Test-DockProviderActiveForTarget([string]$Provider, [Int64]$Hwnd) {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
function Test-DockBottomPlacement {
|
|
165
|
-
return $script:dockTuiStatusline -and $script:dockPlacementMode -eq "bottom"
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function Set-DockPlacementMode([string]$Placement) {
|
|
169
|
-
$next = if ($Placement -eq "tabs") { "tabs" } else { "bottom" }
|
|
170
|
-
if ($script:dockPlacementMode -eq $next) { return }
|
|
171
|
-
if (Test-DockBottomPlacement) {
|
|
172
|
-
Restore-DockTargetSpace
|
|
173
|
-
}
|
|
174
|
-
$script:dockPlacementMode = $next
|
|
175
|
-
$script:dockJoinOverlap = if ($next -eq "bottom") { [math]::Max(1, (Scale-HudValue 8)) } else { 0 }
|
|
176
|
-
$form.Padding = [System.Windows.Forms.Padding]::new(0)
|
|
177
|
-
$form.Height = $script:dockStripHeight + $script:dockJoinOverlap
|
|
178
|
-
$script:dockLastPlacement = $null
|
|
179
|
-
$form.Invalidate()
|
|
180
|
-
if ($script:dockTuiPaintPanel) { $script:dockTuiPaintPanel.Invalidate() }
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function Hide-DockTargetBorder {
|
|
184
|
-
if ($script:dockBorderAdjusted) { return }
|
|
185
|
-
$target = $script:dockTargetHandle
|
|
186
|
-
if ($target -eq [IntPtr]::Zero -or -not [AiBatteryNative]::IsWindow($target)) { return }
|
|
187
|
-
$original = [AiBatteryNative]::DWMWA_COLOR_DEFAULT
|
|
188
|
-
try {
|
|
189
|
-
$read = [AiBatteryNative]::DwmGetWindowAttribute(
|
|
190
|
-
$target,
|
|
191
|
-
[AiBatteryNative]::DWMWA_BORDER_COLOR,
|
|
192
|
-
[ref]$original,
|
|
193
|
-
4
|
|
194
|
-
)
|
|
195
|
-
if ($read -ne 0) { return }
|
|
196
|
-
$none = [AiBatteryNative]::DWMWA_COLOR_NONE
|
|
197
|
-
$write = [AiBatteryNative]::DwmSetWindowAttribute(
|
|
198
|
-
$target,
|
|
199
|
-
[AiBatteryNative]::DWMWA_BORDER_COLOR,
|
|
200
|
-
[ref]$none,
|
|
201
|
-
4
|
|
202
|
-
)
|
|
203
|
-
if ($write -eq 0) {
|
|
204
|
-
$script:dockOriginalBorderColor = [int]$original
|
|
205
|
-
$script:dockBorderAdjusted = $true
|
|
206
|
-
}
|
|
207
|
-
} catch { }
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function Restore-DockTargetBorder {
|
|
211
|
-
if (-not $script:dockBorderAdjusted) { return }
|
|
212
|
-
$target = $script:dockTargetHandle
|
|
213
|
-
$original = [int]$script:dockOriginalBorderColor
|
|
214
|
-
$script:dockBorderAdjusted = $false
|
|
215
|
-
$script:dockOriginalBorderColor = [AiBatteryNative]::DWMWA_COLOR_DEFAULT
|
|
216
|
-
if ($target -eq [IntPtr]::Zero -or -not [AiBatteryNative]::IsWindow($target)) { return }
|
|
217
|
-
try {
|
|
218
|
-
[AiBatteryNative]::DwmSetWindowAttribute(
|
|
219
|
-
$target,
|
|
220
|
-
[AiBatteryNative]::DWMWA_BORDER_COLOR,
|
|
221
|
-
[ref]$original,
|
|
222
|
-
4
|
|
223
|
-
) | Out-Null
|
|
224
|
-
} catch { }
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function Get-DockMonitorWorkArea([IntPtr]$Handle) {
|
|
228
|
-
$monitor = [AiBatteryNative]::MonitorFromWindow($Handle, [AiBatteryNative]::MONITOR_DEFAULTTONEAREST)
|
|
229
|
-
if ($monitor -eq [IntPtr]::Zero) { return $null }
|
|
230
|
-
$info = New-Object AiBatteryMonitorInfo
|
|
231
|
-
$info.CbSize = [System.Runtime.InteropServices.Marshal]::SizeOf($info)
|
|
232
|
-
if (-not [AiBatteryNative]::GetMonitorInfo($monitor, [ref]$info)) { return $null }
|
|
233
|
-
return [PSCustomObject]@{
|
|
234
|
-
Left = [int]$info.Work.Left
|
|
235
|
-
Top = [int]$info.Work.Top
|
|
236
|
-
Right = [int]$info.Work.Right
|
|
237
|
-
Bottom = [int]$info.Work.Bottom
|
|
238
|
-
Width = [int]($info.Work.Right - $info.Work.Left)
|
|
239
|
-
Height = [int]($info.Work.Bottom - $info.Work.Top)
|
|
240
|
-
MonitorLeft = [int]$info.Monitor.Left
|
|
241
|
-
MonitorTop = [int]$info.Monitor.Top
|
|
242
|
-
MonitorRight = [int]$info.Monitor.Right
|
|
243
|
-
MonitorBottom = [int]$info.Monitor.Bottom
|
|
244
|
-
MonitorWidth = [int]($info.Monitor.Right - $info.Monitor.Left)
|
|
245
|
-
MonitorHeight = [int]($info.Monitor.Bottom - $info.Monitor.Top)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
function Reserve-DockTargetSpace {
|
|
250
|
-
if (-not (Test-DockBottomPlacement) -or $script:dockSpaceReserved) { return }
|
|
251
|
-
$target = $script:dockTargetHandle
|
|
252
|
-
if ($target -eq [IntPtr]::Zero -or -not [AiBatteryNative]::IsWindow($target)) { return }
|
|
253
|
-
$stripHeight = [math]::Max(1, [int]$script:dockStripHeight)
|
|
254
|
-
$rect = Get-WindowRectObject $target
|
|
255
|
-
if (-not $rect -or $rect.Height -le ($stripHeight * 4)) { return }
|
|
256
|
-
|
|
257
|
-
$script:dockTargetWasZoomed = [AiBatteryNative]::IsZoomed($target)
|
|
258
|
-
if ($script:dockTargetWasZoomed) {
|
|
259
|
-
$work = Get-DockMonitorWorkArea $target
|
|
260
|
-
if (-not $work -or $work.Height -le ($stripHeight * 4)) { return }
|
|
261
|
-
[AiBatteryNative]::ShowWindow($target, [AiBatteryNative]::SW_RESTORE) | Out-Null
|
|
262
|
-
[System.Windows.Forms.Application]::DoEvents()
|
|
263
|
-
[AiBatteryNative]::SetWindowPos(
|
|
264
|
-
$target,
|
|
265
|
-
[AiBatteryNative]::HWND_TOP,
|
|
266
|
-
$work.Left,
|
|
267
|
-
$work.Top,
|
|
268
|
-
$work.Width,
|
|
269
|
-
($work.Height - $stripHeight),
|
|
270
|
-
([AiBatteryNative]::SWP_NOZORDER -bor [AiBatteryNative]::SWP_NOACTIVATE)
|
|
271
|
-
) | Out-Null
|
|
272
|
-
} else {
|
|
273
|
-
[AiBatteryNative]::SetWindowPos(
|
|
274
|
-
$target,
|
|
275
|
-
[AiBatteryNative]::HWND_TOP,
|
|
276
|
-
$rect.Left,
|
|
277
|
-
$rect.Top,
|
|
278
|
-
$rect.Width,
|
|
279
|
-
($rect.Height - $stripHeight),
|
|
280
|
-
([AiBatteryNative]::SWP_NOZORDER -bor [AiBatteryNative]::SWP_NOACTIVATE)
|
|
281
|
-
) | Out-Null
|
|
282
|
-
}
|
|
283
|
-
$script:dockSpaceReserved = $true
|
|
284
|
-
Write-HudDockDebug "reserved $stripHeight px below terminal (wasZoomed=$($script:dockTargetWasZoomed))"
|
|
285
|
-
}
|
|
286
|
-
|
|
165
|
+
return $script:dockTuiStatusline -and $script:dockPlacementMode -eq "bottom"
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function Set-DockPlacementMode([string]$Placement) {
|
|
169
|
+
$next = if ($Placement -eq "tabs") { "tabs" } else { "bottom" }
|
|
170
|
+
if ($script:dockPlacementMode -eq $next) { return }
|
|
171
|
+
if (Test-DockBottomPlacement) {
|
|
172
|
+
Restore-DockTargetSpace
|
|
173
|
+
}
|
|
174
|
+
$script:dockPlacementMode = $next
|
|
175
|
+
$script:dockJoinOverlap = if ($next -eq "bottom") { [math]::Max(1, (Scale-HudValue 8)) } else { 0 }
|
|
176
|
+
$form.Padding = [System.Windows.Forms.Padding]::new(0)
|
|
177
|
+
$form.Height = $script:dockStripHeight + $script:dockJoinOverlap
|
|
178
|
+
$script:dockLastPlacement = $null
|
|
179
|
+
$form.Invalidate()
|
|
180
|
+
if ($script:dockTuiPaintPanel) { $script:dockTuiPaintPanel.Invalidate() }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function Hide-DockTargetBorder {
|
|
184
|
+
if ($script:dockBorderAdjusted) { return }
|
|
185
|
+
$target = $script:dockTargetHandle
|
|
186
|
+
if ($target -eq [IntPtr]::Zero -or -not [AiBatteryNative]::IsWindow($target)) { return }
|
|
187
|
+
$original = [AiBatteryNative]::DWMWA_COLOR_DEFAULT
|
|
188
|
+
try {
|
|
189
|
+
$read = [AiBatteryNative]::DwmGetWindowAttribute(
|
|
190
|
+
$target,
|
|
191
|
+
[AiBatteryNative]::DWMWA_BORDER_COLOR,
|
|
192
|
+
[ref]$original,
|
|
193
|
+
4
|
|
194
|
+
)
|
|
195
|
+
if ($read -ne 0) { return }
|
|
196
|
+
$none = [AiBatteryNative]::DWMWA_COLOR_NONE
|
|
197
|
+
$write = [AiBatteryNative]::DwmSetWindowAttribute(
|
|
198
|
+
$target,
|
|
199
|
+
[AiBatteryNative]::DWMWA_BORDER_COLOR,
|
|
200
|
+
[ref]$none,
|
|
201
|
+
4
|
|
202
|
+
)
|
|
203
|
+
if ($write -eq 0) {
|
|
204
|
+
$script:dockOriginalBorderColor = [int]$original
|
|
205
|
+
$script:dockBorderAdjusted = $true
|
|
206
|
+
}
|
|
207
|
+
} catch { }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function Restore-DockTargetBorder {
|
|
211
|
+
if (-not $script:dockBorderAdjusted) { return }
|
|
212
|
+
$target = $script:dockTargetHandle
|
|
213
|
+
$original = [int]$script:dockOriginalBorderColor
|
|
214
|
+
$script:dockBorderAdjusted = $false
|
|
215
|
+
$script:dockOriginalBorderColor = [AiBatteryNative]::DWMWA_COLOR_DEFAULT
|
|
216
|
+
if ($target -eq [IntPtr]::Zero -or -not [AiBatteryNative]::IsWindow($target)) { return }
|
|
217
|
+
try {
|
|
218
|
+
[AiBatteryNative]::DwmSetWindowAttribute(
|
|
219
|
+
$target,
|
|
220
|
+
[AiBatteryNative]::DWMWA_BORDER_COLOR,
|
|
221
|
+
[ref]$original,
|
|
222
|
+
4
|
|
223
|
+
) | Out-Null
|
|
224
|
+
} catch { }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function Get-DockMonitorWorkArea([IntPtr]$Handle) {
|
|
228
|
+
$monitor = [AiBatteryNative]::MonitorFromWindow($Handle, [AiBatteryNative]::MONITOR_DEFAULTTONEAREST)
|
|
229
|
+
if ($monitor -eq [IntPtr]::Zero) { return $null }
|
|
230
|
+
$info = New-Object AiBatteryMonitorInfo
|
|
231
|
+
$info.CbSize = [System.Runtime.InteropServices.Marshal]::SizeOf($info)
|
|
232
|
+
if (-not [AiBatteryNative]::GetMonitorInfo($monitor, [ref]$info)) { return $null }
|
|
233
|
+
return [PSCustomObject]@{
|
|
234
|
+
Left = [int]$info.Work.Left
|
|
235
|
+
Top = [int]$info.Work.Top
|
|
236
|
+
Right = [int]$info.Work.Right
|
|
237
|
+
Bottom = [int]$info.Work.Bottom
|
|
238
|
+
Width = [int]($info.Work.Right - $info.Work.Left)
|
|
239
|
+
Height = [int]($info.Work.Bottom - $info.Work.Top)
|
|
240
|
+
MonitorLeft = [int]$info.Monitor.Left
|
|
241
|
+
MonitorTop = [int]$info.Monitor.Top
|
|
242
|
+
MonitorRight = [int]$info.Monitor.Right
|
|
243
|
+
MonitorBottom = [int]$info.Monitor.Bottom
|
|
244
|
+
MonitorWidth = [int]($info.Monitor.Right - $info.Monitor.Left)
|
|
245
|
+
MonitorHeight = [int]($info.Monitor.Bottom - $info.Monitor.Top)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function Reserve-DockTargetSpace {
|
|
250
|
+
if (-not (Test-DockBottomPlacement) -or $script:dockSpaceReserved) { return }
|
|
251
|
+
$target = $script:dockTargetHandle
|
|
252
|
+
if ($target -eq [IntPtr]::Zero -or -not [AiBatteryNative]::IsWindow($target)) { return }
|
|
253
|
+
$stripHeight = [math]::Max(1, [int]$script:dockStripHeight)
|
|
254
|
+
$rect = Get-WindowRectObject $target
|
|
255
|
+
if (-not $rect -or $rect.Height -le ($stripHeight * 4)) { return }
|
|
256
|
+
|
|
257
|
+
$script:dockTargetWasZoomed = [AiBatteryNative]::IsZoomed($target)
|
|
258
|
+
if ($script:dockTargetWasZoomed) {
|
|
259
|
+
$work = Get-DockMonitorWorkArea $target
|
|
260
|
+
if (-not $work -or $work.Height -le ($stripHeight * 4)) { return }
|
|
261
|
+
[AiBatteryNative]::ShowWindow($target, [AiBatteryNative]::SW_RESTORE) | Out-Null
|
|
262
|
+
[System.Windows.Forms.Application]::DoEvents()
|
|
263
|
+
[AiBatteryNative]::SetWindowPos(
|
|
264
|
+
$target,
|
|
265
|
+
[AiBatteryNative]::HWND_TOP,
|
|
266
|
+
$work.Left,
|
|
267
|
+
$work.Top,
|
|
268
|
+
$work.Width,
|
|
269
|
+
($work.Height - $stripHeight),
|
|
270
|
+
([AiBatteryNative]::SWP_NOZORDER -bor [AiBatteryNative]::SWP_NOACTIVATE)
|
|
271
|
+
) | Out-Null
|
|
272
|
+
} else {
|
|
273
|
+
[AiBatteryNative]::SetWindowPos(
|
|
274
|
+
$target,
|
|
275
|
+
[AiBatteryNative]::HWND_TOP,
|
|
276
|
+
$rect.Left,
|
|
277
|
+
$rect.Top,
|
|
278
|
+
$rect.Width,
|
|
279
|
+
($rect.Height - $stripHeight),
|
|
280
|
+
([AiBatteryNative]::SWP_NOZORDER -bor [AiBatteryNative]::SWP_NOACTIVATE)
|
|
281
|
+
) | Out-Null
|
|
282
|
+
}
|
|
283
|
+
$script:dockSpaceReserved = $true
|
|
284
|
+
Write-HudDockDebug "reserved $stripHeight px below terminal (wasZoomed=$($script:dockTargetWasZoomed))"
|
|
285
|
+
}
|
|
286
|
+
|
|
287
287
|
function Restore-DockTargetSpace {
|
|
288
|
-
if (-not $script:dockSpaceReserved -and -not $script:dockBorderAdjusted) { return }
|
|
289
|
-
$target = $script:dockTargetHandle
|
|
290
|
-
$hadReservedSpace = $script:dockSpaceReserved
|
|
291
|
-
$script:dockSpaceReserved = $false
|
|
292
|
-
Restore-DockTargetBorder
|
|
293
|
-
if (-not $hadReservedSpace -or $target -eq [IntPtr]::Zero -or -not [AiBatteryNative]::IsWindow($target)) { return }
|
|
294
|
-
if ($script:dockTargetWasZoomed) {
|
|
295
|
-
[AiBatteryNative]::ShowWindow($target, [AiBatteryNative]::SW_MAXIMIZE) | Out-Null
|
|
296
|
-
} else {
|
|
297
|
-
$rect = Get-WindowRectObject $target
|
|
298
|
-
if ($rect) {
|
|
299
|
-
[AiBatteryNative]::SetWindowPos(
|
|
300
|
-
$target,
|
|
301
|
-
[AiBatteryNative]::HWND_TOP,
|
|
302
|
-
$rect.Left,
|
|
303
|
-
$rect.Top,
|
|
304
|
-
$rect.Width,
|
|
305
|
-
($rect.Height + [math]::Max(1, [int]$script:dockStripHeight)),
|
|
306
|
-
([AiBatteryNative]::SWP_NOZORDER -bor [AiBatteryNative]::SWP_NOACTIVATE)
|
|
307
|
-
) | Out-Null
|
|
308
|
-
}
|
|
309
|
-
}
|
|
288
|
+
if (-not $script:dockSpaceReserved -and -not $script:dockBorderAdjusted) { return }
|
|
289
|
+
$target = $script:dockTargetHandle
|
|
290
|
+
$hadReservedSpace = $script:dockSpaceReserved
|
|
291
|
+
$script:dockSpaceReserved = $false
|
|
292
|
+
Restore-DockTargetBorder
|
|
293
|
+
if (-not $hadReservedSpace -or $target -eq [IntPtr]::Zero -or -not [AiBatteryNative]::IsWindow($target)) { return }
|
|
294
|
+
if ($script:dockTargetWasZoomed) {
|
|
295
|
+
[AiBatteryNative]::ShowWindow($target, [AiBatteryNative]::SW_MAXIMIZE) | Out-Null
|
|
296
|
+
} else {
|
|
297
|
+
$rect = Get-WindowRectObject $target
|
|
298
|
+
if ($rect) {
|
|
299
|
+
[AiBatteryNative]::SetWindowPos(
|
|
300
|
+
$target,
|
|
301
|
+
[AiBatteryNative]::HWND_TOP,
|
|
302
|
+
$rect.Left,
|
|
303
|
+
$rect.Top,
|
|
304
|
+
$rect.Width,
|
|
305
|
+
($rect.Height + [math]::Max(1, [int]$script:dockStripHeight)),
|
|
306
|
+
([AiBatteryNative]::SWP_NOZORDER -bor [AiBatteryNative]::SWP_NOACTIVATE)
|
|
307
|
+
) | Out-Null
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
310
|
$script:dockTargetWasZoomed = $false
|
|
311
311
|
}
|
|
312
312
|
|
|
@@ -394,153 +394,153 @@ function Update-DockSessionLifetime {
|
|
|
394
394
|
}
|
|
395
395
|
|
|
396
396
|
function Repair-DockTargetSpaceAfterShellLayout {
|
|
397
|
-
if (-not (Test-DockBottomPlacement) -or -not $script:dockSpaceReserved) { return }
|
|
398
|
-
$target = $script:dockTargetHandle
|
|
399
|
-
$rect = Get-WindowRectObject $target
|
|
400
|
-
$frame = Get-DockTargetFrame $target
|
|
401
|
-
$work = Get-DockMonitorWorkArea $target
|
|
402
|
-
if (-not $rect -or -not $frame -or -not $work) { return }
|
|
403
|
-
$stripHeight = [math]::Max(1, [int]$script:dockStripHeight)
|
|
404
|
-
$tolerance = [math]::Max(2, (Scale-HudValue 3))
|
|
405
|
-
$coversMonitor = $rect.Left -le ($work.MonitorLeft + 2) -and
|
|
406
|
-
$rect.Top -le ($work.MonitorTop + 2) -and
|
|
407
|
-
$rect.Right -ge ($work.MonitorRight - 2) -and
|
|
408
|
-
$rect.Bottom -ge ($work.MonitorBottom - 2)
|
|
409
|
-
$bottomLimit = if ($coversMonitor) { $work.MonitorBottom } else { $work.Bottom }
|
|
410
|
-
$topLimit = if ($coversMonitor) { $work.MonitorTop } else { $work.Top }
|
|
411
|
-
$leftLimit = if ($coversMonitor) { $work.MonitorLeft } else { $work.Left }
|
|
412
|
-
$rightLimit = if ($coversMonitor) { $work.MonitorRight } else { $work.Right }
|
|
413
|
-
$desiredFrameBottom = $bottomLimit - $stripHeight
|
|
414
|
-
$fillsShellHeight = [math]::Abs([int]$frame.Top - $topLimit) -le $tolerance -and
|
|
415
|
-
[int]$frame.Bottom -ge ($desiredFrameBottom - $tolerance) -and
|
|
416
|
-
[int]$frame.Bottom -le ($bottomLimit + $tolerance)
|
|
417
|
-
$touchesShellSide = [math]::Abs([int]$frame.Left - $leftLimit) -le $tolerance -or
|
|
418
|
-
[math]::Abs([int]$frame.Right - $rightLimit) -le $tolerance
|
|
419
|
-
if (-not $fillsShellHeight -or -not $touchesShellSide) { return }
|
|
420
|
-
|
|
421
|
-
# GetWindowRect includes invisible resize margins. Adjusting its bottom to the
|
|
422
|
-
# monitor edge therefore leaves a gap after a snap/maximize transition. Move
|
|
423
|
-
# the raw height by the visible DWM-frame delta instead, in either direction.
|
|
424
|
-
$bottomDelta = $desiredFrameBottom - [int]$frame.Bottom
|
|
425
|
-
if ([math]::Abs($bottomDelta) -le 1) { return }
|
|
426
|
-
$nextHeight = $rect.Height + $bottomDelta
|
|
427
|
-
if ($nextHeight -le ($stripHeight * 4)) { return }
|
|
428
|
-
[AiBatteryNative]::SetWindowPos(
|
|
429
|
-
$target,
|
|
430
|
-
[AiBatteryNative]::HWND_TOP,
|
|
431
|
-
$rect.Left,
|
|
432
|
-
$rect.Top,
|
|
433
|
-
$rect.Width,
|
|
434
|
-
$nextHeight,
|
|
435
|
-
([AiBatteryNative]::SWP_NOZORDER -bor [AiBatteryNative]::SWP_NOACTIVATE)
|
|
436
|
-
) | Out-Null
|
|
437
|
-
$script:dockLastPlacement = $null
|
|
438
|
-
Write-HudDockDebug "repaired shell layout frameBottom=$($frame.Bottom) desired=$desiredFrameBottom delta=$bottomDelta"
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function Test-DockTargetCloaked([IntPtr]$Handle) {
|
|
442
|
-
$cloaked = 0
|
|
443
|
-
try {
|
|
444
|
-
$hr = [AiBatteryNative]::DwmGetWindowAttribute($Handle, [AiBatteryNative]::DWMWA_CLOAKED, [ref]$cloaked, 4)
|
|
445
|
-
if ($hr -eq 0) { return $cloaked -ne 0 }
|
|
446
|
-
} catch { }
|
|
447
|
-
return $false
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function Get-DockTargetFrame([IntPtr]$Handle) {
|
|
451
|
-
# A zero-sized rect (the ConPTY pseudo-console window reports one) is
|
|
452
|
-
# treated as no frame so the caller hides rather than mis-places the HUD.
|
|
453
|
-
# During snap/restore animations GetWindowRect changes before DWM publishes
|
|
454
|
-
# new extended bounds. Keep the measured invisible-frame insets and apply
|
|
455
|
-
# them to the synchronous rect while fast tracking is active.
|
|
456
|
-
$raw = New-Object AiBatteryRect
|
|
457
|
-
$hasRaw = [AiBatteryNative]::GetWindowRect($Handle, [ref]$raw) -and ($raw.Right - $raw.Left) -gt 0
|
|
458
|
-
$fastTracking = $script:dockMoveSizeActive -or $script:dockGlobalDragActive -or
|
|
459
|
-
$script:dockObservedFrameDragActive -or
|
|
460
|
-
[datetime]::UtcNow -lt $script:dockFastTrackingUntilUtc
|
|
461
|
-
if (-not $fastTracking) {
|
|
462
|
-
try { [AiBatteryNative]::DwmFlush() | Out-Null } catch { }
|
|
463
|
-
}
|
|
464
|
-
$rect = New-Object AiBatteryRect
|
|
465
|
-
try {
|
|
466
|
-
$hr = [AiBatteryNative]::DwmGetWindowAttributeRect($Handle, [AiBatteryNative]::DWMWA_EXTENDED_FRAME_BOUNDS, [ref]$rect, [System.Runtime.InteropServices.Marshal]::SizeOf([type][AiBatteryRect]))
|
|
467
|
-
if ($hr -eq 0 -and ($rect.Right - $rect.Left) -gt 0) {
|
|
468
|
-
if ($hasRaw) {
|
|
469
|
-
$leftInset = [int]$rect.Left - [int]$raw.Left
|
|
470
|
-
$topInset = [int]$rect.Top - [int]$raw.Top
|
|
471
|
-
$rightInset = [int]$raw.Right - [int]$rect.Right
|
|
472
|
-
$bottomInset = [int]$raw.Bottom - [int]$rect.Bottom
|
|
473
|
-
$maxInset = [math]::Max(16, (Scale-HudValue 32))
|
|
474
|
-
if ($leftInset -ge 0 -and $leftInset -le $maxInset -and
|
|
475
|
-
$topInset -ge 0 -and $topInset -le $maxInset -and
|
|
476
|
-
$rightInset -ge 0 -and $rightInset -le $maxInset -and
|
|
477
|
-
$bottomInset -ge 0 -and $bottomInset -le $maxInset) {
|
|
478
|
-
$script:dockFrameInsetLeft = $leftInset
|
|
479
|
-
$script:dockFrameInsetTop = $topInset
|
|
480
|
-
$script:dockFrameInsetRight = $rightInset
|
|
481
|
-
$script:dockFrameInsetBottom = $bottomInset
|
|
482
|
-
$script:dockFrameInsetsValid = $true
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
if ($fastTracking -and $hasRaw -and $script:dockFrameInsetsValid) {
|
|
486
|
-
$live = New-Object AiBatteryRect
|
|
487
|
-
$live.Left = [int]$raw.Left + $script:dockFrameInsetLeft
|
|
488
|
-
$live.Top = [int]$raw.Top + $script:dockFrameInsetTop
|
|
489
|
-
$live.Right = [int]$raw.Right - $script:dockFrameInsetRight
|
|
490
|
-
$live.Bottom = [int]$raw.Bottom - $script:dockFrameInsetBottom
|
|
491
|
-
if (($live.Right - $live.Left) -gt 0 -and ($live.Bottom - $live.Top) -gt 0) { return $live }
|
|
492
|
-
}
|
|
493
|
-
return $rect
|
|
494
|
-
}
|
|
495
|
-
} catch { }
|
|
496
|
-
if ($hasRaw) { return $raw }
|
|
497
|
-
return $null
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
function Test-DockTargetUsesSquareCorners($Frame) {
|
|
501
|
-
if (-not (Test-DockBottomPlacement) -or -not $Frame) { return $false }
|
|
502
|
-
$work = Get-DockMonitorWorkArea $script:dockTargetHandle
|
|
503
|
-
if (-not $work) { return $false }
|
|
504
|
-
$tolerance = [math]::Max(2, (Scale-HudValue 3))
|
|
505
|
-
$stripHeight = [math]::Max(1, [int]$script:dockStripHeight)
|
|
506
|
-
$reservedHeight = if ($script:dockSpaceReserved) { $stripHeight } else { 0 }
|
|
507
|
-
$fillsWorkHeight = [math]::Abs([int]$Frame.Top - $work.Top) -le $tolerance -and
|
|
508
|
-
[math]::Abs([int]$Frame.Bottom - ($work.Bottom - $reservedHeight)) -le $tolerance -and
|
|
509
|
-
([math]::Abs([int]$Frame.Left - $work.Left) -le $tolerance -or
|
|
510
|
-
[math]::Abs([int]$Frame.Right - $work.Right) -le $tolerance)
|
|
511
|
-
$fillsMonitorHeight = [math]::Abs([int]$Frame.Top - $work.MonitorTop) -le $tolerance -and
|
|
512
|
-
[math]::Abs([int]$Frame.Bottom - ($work.MonitorBottom - $reservedHeight)) -le $tolerance -and
|
|
513
|
-
([math]::Abs([int]$Frame.Left - $work.MonitorLeft) -le $tolerance -or
|
|
514
|
-
[math]::Abs([int]$Frame.Right - $work.MonitorRight) -le $tolerance)
|
|
515
|
-
return $fillsWorkHeight -or $fillsMonitorHeight
|
|
516
|
-
}
|
|
517
|
-
|
|
397
|
+
if (-not (Test-DockBottomPlacement) -or -not $script:dockSpaceReserved) { return }
|
|
398
|
+
$target = $script:dockTargetHandle
|
|
399
|
+
$rect = Get-WindowRectObject $target
|
|
400
|
+
$frame = Get-DockTargetFrame $target
|
|
401
|
+
$work = Get-DockMonitorWorkArea $target
|
|
402
|
+
if (-not $rect -or -not $frame -or -not $work) { return }
|
|
403
|
+
$stripHeight = [math]::Max(1, [int]$script:dockStripHeight)
|
|
404
|
+
$tolerance = [math]::Max(2, (Scale-HudValue 3))
|
|
405
|
+
$coversMonitor = $rect.Left -le ($work.MonitorLeft + 2) -and
|
|
406
|
+
$rect.Top -le ($work.MonitorTop + 2) -and
|
|
407
|
+
$rect.Right -ge ($work.MonitorRight - 2) -and
|
|
408
|
+
$rect.Bottom -ge ($work.MonitorBottom - 2)
|
|
409
|
+
$bottomLimit = if ($coversMonitor) { $work.MonitorBottom } else { $work.Bottom }
|
|
410
|
+
$topLimit = if ($coversMonitor) { $work.MonitorTop } else { $work.Top }
|
|
411
|
+
$leftLimit = if ($coversMonitor) { $work.MonitorLeft } else { $work.Left }
|
|
412
|
+
$rightLimit = if ($coversMonitor) { $work.MonitorRight } else { $work.Right }
|
|
413
|
+
$desiredFrameBottom = $bottomLimit - $stripHeight
|
|
414
|
+
$fillsShellHeight = [math]::Abs([int]$frame.Top - $topLimit) -le $tolerance -and
|
|
415
|
+
[int]$frame.Bottom -ge ($desiredFrameBottom - $tolerance) -and
|
|
416
|
+
[int]$frame.Bottom -le ($bottomLimit + $tolerance)
|
|
417
|
+
$touchesShellSide = [math]::Abs([int]$frame.Left - $leftLimit) -le $tolerance -or
|
|
418
|
+
[math]::Abs([int]$frame.Right - $rightLimit) -le $tolerance
|
|
419
|
+
if (-not $fillsShellHeight -or -not $touchesShellSide) { return }
|
|
420
|
+
|
|
421
|
+
# GetWindowRect includes invisible resize margins. Adjusting its bottom to the
|
|
422
|
+
# monitor edge therefore leaves a gap after a snap/maximize transition. Move
|
|
423
|
+
# the raw height by the visible DWM-frame delta instead, in either direction.
|
|
424
|
+
$bottomDelta = $desiredFrameBottom - [int]$frame.Bottom
|
|
425
|
+
if ([math]::Abs($bottomDelta) -le 1) { return }
|
|
426
|
+
$nextHeight = $rect.Height + $bottomDelta
|
|
427
|
+
if ($nextHeight -le ($stripHeight * 4)) { return }
|
|
428
|
+
[AiBatteryNative]::SetWindowPos(
|
|
429
|
+
$target,
|
|
430
|
+
[AiBatteryNative]::HWND_TOP,
|
|
431
|
+
$rect.Left,
|
|
432
|
+
$rect.Top,
|
|
433
|
+
$rect.Width,
|
|
434
|
+
$nextHeight,
|
|
435
|
+
([AiBatteryNative]::SWP_NOZORDER -bor [AiBatteryNative]::SWP_NOACTIVATE)
|
|
436
|
+
) | Out-Null
|
|
437
|
+
$script:dockLastPlacement = $null
|
|
438
|
+
Write-HudDockDebug "repaired shell layout frameBottom=$($frame.Bottom) desired=$desiredFrameBottom delta=$bottomDelta"
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function Test-DockTargetCloaked([IntPtr]$Handle) {
|
|
442
|
+
$cloaked = 0
|
|
443
|
+
try {
|
|
444
|
+
$hr = [AiBatteryNative]::DwmGetWindowAttribute($Handle, [AiBatteryNative]::DWMWA_CLOAKED, [ref]$cloaked, 4)
|
|
445
|
+
if ($hr -eq 0) { return $cloaked -ne 0 }
|
|
446
|
+
} catch { }
|
|
447
|
+
return $false
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function Get-DockTargetFrame([IntPtr]$Handle) {
|
|
451
|
+
# A zero-sized rect (the ConPTY pseudo-console window reports one) is
|
|
452
|
+
# treated as no frame so the caller hides rather than mis-places the HUD.
|
|
453
|
+
# During snap/restore animations GetWindowRect changes before DWM publishes
|
|
454
|
+
# new extended bounds. Keep the measured invisible-frame insets and apply
|
|
455
|
+
# them to the synchronous rect while fast tracking is active.
|
|
456
|
+
$raw = New-Object AiBatteryRect
|
|
457
|
+
$hasRaw = [AiBatteryNative]::GetWindowRect($Handle, [ref]$raw) -and ($raw.Right - $raw.Left) -gt 0
|
|
458
|
+
$fastTracking = $script:dockMoveSizeActive -or $script:dockGlobalDragActive -or
|
|
459
|
+
$script:dockObservedFrameDragActive -or
|
|
460
|
+
[datetime]::UtcNow -lt $script:dockFastTrackingUntilUtc
|
|
461
|
+
if (-not $fastTracking) {
|
|
462
|
+
try { [AiBatteryNative]::DwmFlush() | Out-Null } catch { }
|
|
463
|
+
}
|
|
464
|
+
$rect = New-Object AiBatteryRect
|
|
465
|
+
try {
|
|
466
|
+
$hr = [AiBatteryNative]::DwmGetWindowAttributeRect($Handle, [AiBatteryNative]::DWMWA_EXTENDED_FRAME_BOUNDS, [ref]$rect, [System.Runtime.InteropServices.Marshal]::SizeOf([type][AiBatteryRect]))
|
|
467
|
+
if ($hr -eq 0 -and ($rect.Right - $rect.Left) -gt 0) {
|
|
468
|
+
if ($hasRaw) {
|
|
469
|
+
$leftInset = [int]$rect.Left - [int]$raw.Left
|
|
470
|
+
$topInset = [int]$rect.Top - [int]$raw.Top
|
|
471
|
+
$rightInset = [int]$raw.Right - [int]$rect.Right
|
|
472
|
+
$bottomInset = [int]$raw.Bottom - [int]$rect.Bottom
|
|
473
|
+
$maxInset = [math]::Max(16, (Scale-HudValue 32))
|
|
474
|
+
if ($leftInset -ge 0 -and $leftInset -le $maxInset -and
|
|
475
|
+
$topInset -ge 0 -and $topInset -le $maxInset -and
|
|
476
|
+
$rightInset -ge 0 -and $rightInset -le $maxInset -and
|
|
477
|
+
$bottomInset -ge 0 -and $bottomInset -le $maxInset) {
|
|
478
|
+
$script:dockFrameInsetLeft = $leftInset
|
|
479
|
+
$script:dockFrameInsetTop = $topInset
|
|
480
|
+
$script:dockFrameInsetRight = $rightInset
|
|
481
|
+
$script:dockFrameInsetBottom = $bottomInset
|
|
482
|
+
$script:dockFrameInsetsValid = $true
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if ($fastTracking -and $hasRaw -and $script:dockFrameInsetsValid) {
|
|
486
|
+
$live = New-Object AiBatteryRect
|
|
487
|
+
$live.Left = [int]$raw.Left + $script:dockFrameInsetLeft
|
|
488
|
+
$live.Top = [int]$raw.Top + $script:dockFrameInsetTop
|
|
489
|
+
$live.Right = [int]$raw.Right - $script:dockFrameInsetRight
|
|
490
|
+
$live.Bottom = [int]$raw.Bottom - $script:dockFrameInsetBottom
|
|
491
|
+
if (($live.Right - $live.Left) -gt 0 -and ($live.Bottom - $live.Top) -gt 0) { return $live }
|
|
492
|
+
}
|
|
493
|
+
return $rect
|
|
494
|
+
}
|
|
495
|
+
} catch { }
|
|
496
|
+
if ($hasRaw) { return $raw }
|
|
497
|
+
return $null
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function Test-DockTargetUsesSquareCorners($Frame) {
|
|
501
|
+
if (-not (Test-DockBottomPlacement) -or -not $Frame) { return $false }
|
|
502
|
+
$work = Get-DockMonitorWorkArea $script:dockTargetHandle
|
|
503
|
+
if (-not $work) { return $false }
|
|
504
|
+
$tolerance = [math]::Max(2, (Scale-HudValue 3))
|
|
505
|
+
$stripHeight = [math]::Max(1, [int]$script:dockStripHeight)
|
|
506
|
+
$reservedHeight = if ($script:dockSpaceReserved) { $stripHeight } else { 0 }
|
|
507
|
+
$fillsWorkHeight = [math]::Abs([int]$Frame.Top - $work.Top) -le $tolerance -and
|
|
508
|
+
[math]::Abs([int]$Frame.Bottom - ($work.Bottom - $reservedHeight)) -le $tolerance -and
|
|
509
|
+
([math]::Abs([int]$Frame.Left - $work.Left) -le $tolerance -or
|
|
510
|
+
[math]::Abs([int]$Frame.Right - $work.Right) -le $tolerance)
|
|
511
|
+
$fillsMonitorHeight = [math]::Abs([int]$Frame.Top - $work.MonitorTop) -le $tolerance -and
|
|
512
|
+
[math]::Abs([int]$Frame.Bottom - ($work.MonitorBottom - $reservedHeight)) -le $tolerance -and
|
|
513
|
+
([math]::Abs([int]$Frame.Left - $work.MonitorLeft) -le $tolerance -or
|
|
514
|
+
[math]::Abs([int]$Frame.Right - $work.MonitorRight) -le $tolerance)
|
|
515
|
+
return $fillsWorkHeight -or $fillsMonitorHeight
|
|
516
|
+
}
|
|
517
|
+
|
|
518
518
|
function Write-HudDockDebug([string]$Message) {
|
|
519
|
-
if (-not $env:AI_BATTERY_HUD_DEBUG_LOG) { return }
|
|
520
|
-
try {
|
|
521
|
-
Add-Content -LiteralPath $env:AI_BATTERY_HUD_DEBUG_LOG -Value "$([datetime]::UtcNow.ToString('o')) $Message"
|
|
522
|
-
} catch { }
|
|
519
|
+
if (-not $env:AI_BATTERY_HUD_DEBUG_LOG) { return }
|
|
520
|
+
try {
|
|
521
|
+
Add-Content -LiteralPath $env:AI_BATTERY_HUD_DEBUG_LOG -Value "$([datetime]::UtcNow.ToString('o')) $Message"
|
|
522
|
+
} catch { }
|
|
523
523
|
}
|
|
524
524
|
|
|
525
525
|
if ($DockWindowHandle -ne 0 -and $DockSession -ne 0) {
|
|
526
526
|
Add-DockSession ([Int64]$DockWindowHandle) ([Int64]$DockSession) ([int]$DockOwnerPid) ([string]$DockProvider) ([string]$DockMarkerPath)
|
|
527
527
|
}
|
|
528
|
-
|
|
529
|
-
function Set-DockPendingMoveSizeState([bool]$Active) {
|
|
530
|
-
$script:dockPendingMoveSizeState = $Active
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
function Test-DockGlobalTargetDragActive {
|
|
534
|
-
if ($script:dockTargetHandle -eq [IntPtr]::Zero) { return $false }
|
|
535
|
-
$leftButtonDown = Test-DockLeftButtonDown
|
|
536
|
-
return $leftButtonDown -and [AiBatteryNative]::GetForegroundWindow() -eq $script:dockTargetHandle
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
function Test-DockLeftButtonDown {
|
|
540
|
-
return (([int][AiBatteryNative]::GetAsyncKeyState(1)) -band 0x8000) -ne 0
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
function Update-DockGlobalDragState {
|
|
528
|
+
|
|
529
|
+
function Set-DockPendingMoveSizeState([bool]$Active) {
|
|
530
|
+
$script:dockPendingMoveSizeState = $Active
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function Test-DockGlobalTargetDragActive {
|
|
534
|
+
if ($script:dockTargetHandle -eq [IntPtr]::Zero) { return $false }
|
|
535
|
+
$leftButtonDown = Test-DockLeftButtonDown
|
|
536
|
+
return $leftButtonDown -and [AiBatteryNative]::GetForegroundWindow() -eq $script:dockTargetHandle
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function Test-DockLeftButtonDown {
|
|
540
|
+
return (([int][AiBatteryNative]::GetAsyncKeyState(1)) -band 0x8000) -ne 0
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function Update-DockGlobalDragState {
|
|
544
544
|
$active = Test-DockGlobalTargetDragActive
|
|
545
545
|
if ($script:dockGlobalDragActive -eq $active) { return }
|
|
546
546
|
$script:dockGlobalDragActive = $active
|
|
@@ -551,91 +551,91 @@ function Update-DockGlobalDragState {
|
|
|
551
551
|
$script:dockLastPlacement = $null
|
|
552
552
|
$script:dockFastTrackingUntilUtc = [datetime]::MaxValue
|
|
553
553
|
Write-HudDockDebug "dock global drag tracking started"
|
|
554
|
-
} else {
|
|
555
|
-
$script:dockFastTrackingUntilUtc = [datetime]::UtcNow.AddMilliseconds(350)
|
|
556
|
-
Write-HudDockDebug "dock global drag tracking ended"
|
|
557
|
-
}
|
|
558
|
-
Update-DockTrackingInterval
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
function Update-DockObservedFrameDragState {
|
|
562
|
-
if ($script:dockTargetHandle -eq [IntPtr]::Zero -or
|
|
563
|
-
-not [AiBatteryNative]::IsWindow($script:dockTargetHandle)) {
|
|
564
|
-
$script:dockObservedFrameDragActive = $false
|
|
565
|
-
$script:dockObservedRawRectKey = ""
|
|
566
|
-
return
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
$rect = New-Object AiBatteryRect
|
|
570
|
-
if (-not [AiBatteryNative]::GetWindowRect($script:dockTargetHandle, [ref]$rect)) { return }
|
|
571
|
-
$key = "{0},{1},{2},{3}" -f $rect.Left, $rect.Top, $rect.Right, $rect.Bottom
|
|
572
|
-
$changed = $script:dockObservedRawRectKey -ne "" -and $script:dockObservedRawRectKey -ne $key
|
|
573
|
-
$script:dockObservedRawRectKey = $key
|
|
574
|
-
$leftButtonDown = Test-DockLeftButtonDown
|
|
575
|
-
|
|
576
|
-
if (-not $leftButtonDown) {
|
|
577
|
-
if ($script:dockObservedFrameDragActive) {
|
|
578
|
-
$script:dockFastTrackingUntilUtc = [datetime]::UtcNow.AddMilliseconds(350)
|
|
579
|
-
Write-HudDockDebug "dock observed frame drag ended"
|
|
580
|
-
}
|
|
581
|
-
$script:dockObservedFrameDragActive = $false
|
|
582
|
-
Update-DockTrackingInterval
|
|
583
|
-
return
|
|
584
|
-
}
|
|
585
|
-
if (-not $changed -or $script:dockObservedFrameDragActive) { return }
|
|
586
|
-
|
|
587
|
-
$script:dockObservedFrameDragActive = $true
|
|
588
|
-
$script:dockLastPlacement = $null
|
|
589
|
-
$script:dockFastTrackingUntilUtc = [datetime]::MaxValue
|
|
590
|
-
Write-HudDockDebug "dock observed frame drag started"
|
|
591
|
-
Update-DockTrackingInterval
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
function Set-DockTrackingInterval([int]$Milliseconds) {
|
|
595
|
-
$timerVariable = Get-Variable -Name topMostTimer -Scope Script -ErrorAction SilentlyContinue
|
|
596
|
-
if (-not $timerVariable -or -not $timerVariable.Value) { return }
|
|
597
|
-
$trackingTimer = $timerVariable.Value
|
|
598
|
-
$nextInterval = [math]::Max(15, $Milliseconds)
|
|
599
|
-
if ($trackingTimer.Interval -ne $nextInterval) {
|
|
600
|
-
$trackingTimer.Interval = $nextInterval
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
function Update-DockTrackingInterval {
|
|
605
|
-
if ($script:dockMoveSizeActive -or $script:dockGlobalDragActive -or
|
|
606
|
-
$script:dockObservedFrameDragActive -or
|
|
607
|
-
[datetime]::UtcNow -lt $script:dockFastTrackingUntilUtc) {
|
|
608
|
-
Set-DockTrackingInterval $script:dockActiveTrackingInterval
|
|
609
|
-
} else {
|
|
610
|
-
Set-DockTrackingInterval $script:dockIdleTrackingInterval
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
554
|
+
} else {
|
|
555
|
+
$script:dockFastTrackingUntilUtc = [datetime]::UtcNow.AddMilliseconds(350)
|
|
556
|
+
Write-HudDockDebug "dock global drag tracking ended"
|
|
557
|
+
}
|
|
558
|
+
Update-DockTrackingInterval
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function Update-DockObservedFrameDragState {
|
|
562
|
+
if ($script:dockTargetHandle -eq [IntPtr]::Zero -or
|
|
563
|
+
-not [AiBatteryNative]::IsWindow($script:dockTargetHandle)) {
|
|
564
|
+
$script:dockObservedFrameDragActive = $false
|
|
565
|
+
$script:dockObservedRawRectKey = ""
|
|
566
|
+
return
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
$rect = New-Object AiBatteryRect
|
|
570
|
+
if (-not [AiBatteryNative]::GetWindowRect($script:dockTargetHandle, [ref]$rect)) { return }
|
|
571
|
+
$key = "{0},{1},{2},{3}" -f $rect.Left, $rect.Top, $rect.Right, $rect.Bottom
|
|
572
|
+
$changed = $script:dockObservedRawRectKey -ne "" -and $script:dockObservedRawRectKey -ne $key
|
|
573
|
+
$script:dockObservedRawRectKey = $key
|
|
574
|
+
$leftButtonDown = Test-DockLeftButtonDown
|
|
575
|
+
|
|
576
|
+
if (-not $leftButtonDown) {
|
|
577
|
+
if ($script:dockObservedFrameDragActive) {
|
|
578
|
+
$script:dockFastTrackingUntilUtc = [datetime]::UtcNow.AddMilliseconds(350)
|
|
579
|
+
Write-HudDockDebug "dock observed frame drag ended"
|
|
580
|
+
}
|
|
581
|
+
$script:dockObservedFrameDragActive = $false
|
|
582
|
+
Update-DockTrackingInterval
|
|
583
|
+
return
|
|
584
|
+
}
|
|
585
|
+
if (-not $changed -or $script:dockObservedFrameDragActive) { return }
|
|
586
|
+
|
|
587
|
+
$script:dockObservedFrameDragActive = $true
|
|
588
|
+
$script:dockLastPlacement = $null
|
|
589
|
+
$script:dockFastTrackingUntilUtc = [datetime]::MaxValue
|
|
590
|
+
Write-HudDockDebug "dock observed frame drag started"
|
|
591
|
+
Update-DockTrackingInterval
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function Set-DockTrackingInterval([int]$Milliseconds) {
|
|
595
|
+
$timerVariable = Get-Variable -Name topMostTimer -Scope Script -ErrorAction SilentlyContinue
|
|
596
|
+
if (-not $timerVariable -or -not $timerVariable.Value) { return }
|
|
597
|
+
$trackingTimer = $timerVariable.Value
|
|
598
|
+
$nextInterval = [math]::Max(15, $Milliseconds)
|
|
599
|
+
if ($trackingTimer.Interval -ne $nextInterval) {
|
|
600
|
+
$trackingTimer.Interval = $nextInterval
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function Update-DockTrackingInterval {
|
|
605
|
+
if ($script:dockMoveSizeActive -or $script:dockGlobalDragActive -or
|
|
606
|
+
$script:dockObservedFrameDragActive -or
|
|
607
|
+
[datetime]::UtcNow -lt $script:dockFastTrackingUntilUtc) {
|
|
608
|
+
Set-DockTrackingInterval $script:dockActiveTrackingInterval
|
|
609
|
+
} else {
|
|
610
|
+
Set-DockTrackingInterval $script:dockIdleTrackingInterval
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
614
|
function Test-DockSnapPreviewActive {
|
|
615
|
-
$leftButtonDown = Test-DockLeftButtonDown
|
|
616
|
-
$recentFrameChange = ([datetime]::UtcNow - $script:dockTargetFrameChangedAtUtc).TotalMilliseconds -le 350
|
|
617
|
-
# MOVESIZE events can refer to an internal Windows Terminal HWND. In that
|
|
618
|
-
# case, use the foreground/left-button fallback only after the target frame
|
|
619
|
-
# has actually moved. Once a preview is entered, keep it active while the
|
|
620
|
-
# button remains down even though Windows freezes the target frame.
|
|
621
|
-
$dragActive = $leftButtonDown -and (
|
|
622
|
-
$script:dockMoveSizeActive -or
|
|
623
|
-
$script:dockObservedFrameDragActive -or
|
|
624
|
-
($script:dockGlobalDragActive -and ($recentFrameChange -or $script:dockSnapPreviewActive))
|
|
625
|
-
)
|
|
626
|
-
if (-not $dragActive) { return $false }
|
|
627
|
-
$point = [System.Windows.Forms.Cursor]::Position
|
|
628
|
-
$screen = [System.Windows.Forms.Screen]::FromPoint($point)
|
|
629
|
-
if (-not $screen) { return $false }
|
|
630
|
-
$bounds = $screen.Bounds
|
|
631
|
-
# Windows Terminal owns mouse capture during a native title-bar drag, so
|
|
632
|
-
# WinForms MouseButtons can report None. MOVESIZESTART already proves that a
|
|
633
|
-
# drag is active; cursor proximity is the reliable snap-preview signal.
|
|
634
|
-
$edge = if ($script:dockSnapPreviewActive) {
|
|
635
|
-
[math]::Max(12, (Scale-HudValue 32))
|
|
636
|
-
} else {
|
|
637
|
-
[math]::Max(8, (Scale-HudValue 20))
|
|
638
|
-
}
|
|
615
|
+
$leftButtonDown = Test-DockLeftButtonDown
|
|
616
|
+
$recentFrameChange = ([datetime]::UtcNow - $script:dockTargetFrameChangedAtUtc).TotalMilliseconds -le 350
|
|
617
|
+
# MOVESIZE events can refer to an internal Windows Terminal HWND. In that
|
|
618
|
+
# case, use the foreground/left-button fallback only after the target frame
|
|
619
|
+
# has actually moved. Once a preview is entered, keep it active while the
|
|
620
|
+
# button remains down even though Windows freezes the target frame.
|
|
621
|
+
$dragActive = $leftButtonDown -and (
|
|
622
|
+
$script:dockMoveSizeActive -or
|
|
623
|
+
$script:dockObservedFrameDragActive -or
|
|
624
|
+
($script:dockGlobalDragActive -and ($recentFrameChange -or $script:dockSnapPreviewActive))
|
|
625
|
+
)
|
|
626
|
+
if (-not $dragActive) { return $false }
|
|
627
|
+
$point = [System.Windows.Forms.Cursor]::Position
|
|
628
|
+
$screen = [System.Windows.Forms.Screen]::FromPoint($point)
|
|
629
|
+
if (-not $screen) { return $false }
|
|
630
|
+
$bounds = $screen.Bounds
|
|
631
|
+
# Windows Terminal owns mouse capture during a native title-bar drag, so
|
|
632
|
+
# WinForms MouseButtons can report None. MOVESIZESTART already proves that a
|
|
633
|
+
# drag is active; cursor proximity is the reliable snap-preview signal.
|
|
634
|
+
$edge = if ($script:dockSnapPreviewActive) {
|
|
635
|
+
[math]::Max(12, (Scale-HudValue 32))
|
|
636
|
+
} else {
|
|
637
|
+
[math]::Max(8, (Scale-HudValue 20))
|
|
638
|
+
}
|
|
639
639
|
return $point.X -le ($bounds.Left + $edge) -or
|
|
640
640
|
$point.X -ge ($bounds.Right - $edge - 1) -or
|
|
641
641
|
$point.Y -le ($bounds.Top + $edge)
|
|
@@ -669,9 +669,9 @@ function Test-DockShellSnapFlyoutActive {
|
|
|
669
669
|
}
|
|
670
670
|
|
|
671
671
|
function Update-DockSnapPreviewVisibility {
|
|
672
|
-
# Normal movement remains visible. This branch only hides at a snap edge;
|
|
673
|
-
# global drag tracking covers terminals whose MOVESIZE event uses a child
|
|
674
|
-
# HWND and must not itself be treated as a reason to hide.
|
|
672
|
+
# Normal movement remains visible. This branch only hides at a snap edge;
|
|
673
|
+
# global drag tracking covers terminals whose MOVESIZE event uses a child
|
|
674
|
+
# HWND and must not itself be treated as a reason to hide.
|
|
675
675
|
$shellPreview = Test-DockShellSnapFlyoutActive
|
|
676
676
|
$script:dockShellSnapFlyoutActive = $shellPreview
|
|
677
677
|
if (-not $script:dockMoveSizeActive -and
|
|
@@ -680,28 +680,28 @@ function Update-DockSnapPreviewVisibility {
|
|
|
680
680
|
-not $script:dockSnapPreviewActive -and
|
|
681
681
|
-not $shellPreview) { return $false }
|
|
682
682
|
$preview = $shellPreview -or (Test-DockSnapPreviewActive)
|
|
683
|
-
if ($script:dockSnapPreviewActive -ne $preview) {
|
|
684
|
-
$script:dockSnapPreviewActive = $preview
|
|
685
|
-
if ($preview) {
|
|
686
|
-
Write-HudDockDebug "dock hide: snap preview edge entered"
|
|
687
|
-
Set-HudHiddenForDock $true
|
|
688
|
-
} elseif (-not (Test-DockLeftButtonDown)) {
|
|
689
|
-
# Mouse release can be observed before MOVESIZEEND. Keep the HUD hidden
|
|
690
|
-
# until DWM has published the final snapped frame.
|
|
691
|
-
$script:dockShowAfterMoveSizeUtc = [datetime]::UtcNow.AddMilliseconds(120)
|
|
692
|
-
$script:dockFastTrackingUntilUtc = [datetime]::UtcNow.AddMilliseconds(350)
|
|
693
|
-
Write-HudDockDebug "dock snap preview released; waiting for final frame"
|
|
694
|
-
} else {
|
|
695
|
-
Write-HudDockDebug "dock show: snap preview edge left"
|
|
696
|
-
Set-HudHiddenForDock $false
|
|
697
|
-
$script:dockLastPlacement = $null
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
return $preview
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
function Apply-DockPendingMoveSizeState {
|
|
704
|
-
if ($null -eq $script:dockPendingMoveSizeState) { return }
|
|
683
|
+
if ($script:dockSnapPreviewActive -ne $preview) {
|
|
684
|
+
$script:dockSnapPreviewActive = $preview
|
|
685
|
+
if ($preview) {
|
|
686
|
+
Write-HudDockDebug "dock hide: snap preview edge entered"
|
|
687
|
+
Set-HudHiddenForDock $true
|
|
688
|
+
} elseif (-not (Test-DockLeftButtonDown)) {
|
|
689
|
+
# Mouse release can be observed before MOVESIZEEND. Keep the HUD hidden
|
|
690
|
+
# until DWM has published the final snapped frame.
|
|
691
|
+
$script:dockShowAfterMoveSizeUtc = [datetime]::UtcNow.AddMilliseconds(120)
|
|
692
|
+
$script:dockFastTrackingUntilUtc = [datetime]::UtcNow.AddMilliseconds(350)
|
|
693
|
+
Write-HudDockDebug "dock snap preview released; waiting for final frame"
|
|
694
|
+
} else {
|
|
695
|
+
Write-HudDockDebug "dock show: snap preview edge left"
|
|
696
|
+
Set-HudHiddenForDock $false
|
|
697
|
+
$script:dockLastPlacement = $null
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
return $preview
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function Apply-DockPendingMoveSizeState {
|
|
704
|
+
if ($null -eq $script:dockPendingMoveSizeState) { return }
|
|
705
705
|
$active = [bool]$script:dockPendingMoveSizeState
|
|
706
706
|
$script:dockPendingMoveSizeState = $null
|
|
707
707
|
if ($script:dockMoveSizeActive -eq $active) { return }
|
|
@@ -709,36 +709,36 @@ function Apply-DockPendingMoveSizeState {
|
|
|
709
709
|
if ($active) {
|
|
710
710
|
$script:dockLastPlacement = $null
|
|
711
711
|
$script:dockSnapPreviewActive = $false
|
|
712
|
-
$script:dockShowAfterMoveSizeUtc = [datetime]::MinValue
|
|
713
|
-
$script:dockFastTrackingUntilUtc = [datetime]::MaxValue
|
|
714
|
-
Update-DockTrackingInterval
|
|
715
|
-
Write-HudDockDebug "dock move/size tracking started"
|
|
716
|
-
} else {
|
|
717
|
-
$wasSnapPreview = $script:dockSnapPreviewActive
|
|
718
|
-
$script:dockSnapPreviewActive = $false
|
|
719
|
-
$script:dockFastTrackingUntilUtc = [datetime]::UtcNow.AddMilliseconds(350)
|
|
720
|
-
Update-DockTrackingInterval
|
|
721
|
-
if ($wasSnapPreview) {
|
|
722
|
-
# Let DWM publish the snapped extended frame before showing at its edge.
|
|
723
|
-
$script:dockShowAfterMoveSizeUtc = [datetime]::UtcNow.AddMilliseconds(120)
|
|
724
|
-
Write-HudDockDebug "dock snap preview ended; waiting for final frame"
|
|
725
|
-
} else {
|
|
726
|
-
$script:dockShowAfterMoveSizeUtc = [datetime]::MinValue
|
|
727
|
-
Write-HudDockDebug "dock move/size tracking ended"
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
function Test-DockUnavailablePastGrace([string]$Reason) {
|
|
733
|
-
$now = [datetime]::UtcNow
|
|
734
|
-
if ($script:dockUnavailableSinceUtc -eq [datetime]::MinValue) {
|
|
735
|
-
$script:dockUnavailableSinceUtc = $now
|
|
736
|
-
Write-HudDockDebug "dock transient unavailable: $Reason"
|
|
737
|
-
return $false
|
|
738
|
-
}
|
|
739
|
-
return ($now - $script:dockUnavailableSinceUtc).TotalMilliseconds -ge 500
|
|
740
|
-
}
|
|
741
|
-
|
|
712
|
+
$script:dockShowAfterMoveSizeUtc = [datetime]::MinValue
|
|
713
|
+
$script:dockFastTrackingUntilUtc = [datetime]::MaxValue
|
|
714
|
+
Update-DockTrackingInterval
|
|
715
|
+
Write-HudDockDebug "dock move/size tracking started"
|
|
716
|
+
} else {
|
|
717
|
+
$wasSnapPreview = $script:dockSnapPreviewActive
|
|
718
|
+
$script:dockSnapPreviewActive = $false
|
|
719
|
+
$script:dockFastTrackingUntilUtc = [datetime]::UtcNow.AddMilliseconds(350)
|
|
720
|
+
Update-DockTrackingInterval
|
|
721
|
+
if ($wasSnapPreview) {
|
|
722
|
+
# Let DWM publish the snapped extended frame before showing at its edge.
|
|
723
|
+
$script:dockShowAfterMoveSizeUtc = [datetime]::UtcNow.AddMilliseconds(120)
|
|
724
|
+
Write-HudDockDebug "dock snap preview ended; waiting for final frame"
|
|
725
|
+
} else {
|
|
726
|
+
$script:dockShowAfterMoveSizeUtc = [datetime]::MinValue
|
|
727
|
+
Write-HudDockDebug "dock move/size tracking ended"
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function Test-DockUnavailablePastGrace([string]$Reason) {
|
|
733
|
+
$now = [datetime]::UtcNow
|
|
734
|
+
if ($script:dockUnavailableSinceUtc -eq [datetime]::MinValue) {
|
|
735
|
+
$script:dockUnavailableSinceUtc = $now
|
|
736
|
+
Write-HudDockDebug "dock transient unavailable: $Reason"
|
|
737
|
+
return $false
|
|
738
|
+
}
|
|
739
|
+
return ($now - $script:dockUnavailableSinceUtc).TotalMilliseconds -ge 500
|
|
740
|
+
}
|
|
741
|
+
|
|
742
742
|
function Clear-DockUnavailableGrace {
|
|
743
743
|
$script:dockUnavailableSinceUtc = [datetime]::MinValue
|
|
744
744
|
}
|
|
@@ -779,12 +779,12 @@ function Update-HudDockPlacement {
|
|
|
779
779
|
if ($script:dockTargetHandle -eq [IntPtr]::Zero) { return }
|
|
780
780
|
if (-not $form -or $form.IsDisposed) { return }
|
|
781
781
|
Update-HudDockDpi | Out-Null
|
|
782
|
-
Apply-DockPendingMoveSizeState
|
|
783
|
-
Update-DockObservedFrameDragState
|
|
784
|
-
Update-DockGlobalDragState
|
|
785
|
-
Update-DockTrackingInterval
|
|
786
|
-
if (Update-DockSnapPreviewVisibility) { return }
|
|
787
|
-
if ([datetime]::UtcNow -lt $script:dockShowAfterMoveSizeUtc) { return }
|
|
782
|
+
Apply-DockPendingMoveSizeState
|
|
783
|
+
Update-DockObservedFrameDragState
|
|
784
|
+
Update-DockGlobalDragState
|
|
785
|
+
Update-DockTrackingInterval
|
|
786
|
+
if (Update-DockSnapPreviewVisibility) { return }
|
|
787
|
+
if ([datetime]::UtcNow -lt $script:dockShowAfterMoveSizeUtc) { return }
|
|
788
788
|
$target = $script:dockTargetHandle
|
|
789
789
|
if (-not [AiBatteryNative]::IsWindow($target)) {
|
|
790
790
|
$closedTarget = [Int64]$target
|
|
@@ -792,138 +792,138 @@ function Update-HudDockPlacement {
|
|
|
792
792
|
Remove-DockSessionsForTarget $closedTarget
|
|
793
793
|
Select-DockTargetFromActiveSessions "terminal window closed"
|
|
794
794
|
return
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
$targetIconic = [AiBatteryNative]::IsIconic($target)
|
|
798
|
-
$targetVisible = [AiBatteryNative]::IsWindowVisible($target) -and
|
|
799
|
-
-not $targetIconic -and
|
|
800
|
-
-not (Test-DockTargetCloaked $target)
|
|
801
|
-
if (-not $targetVisible) {
|
|
802
|
-
if (-not $targetIconic -and -not (Test-DockUnavailablePastGrace "visibility/cloak transition")) {
|
|
803
|
-
return
|
|
804
|
-
}
|
|
805
|
-
Write-HudDockDebug "dock hide: target not visible (visible=$([AiBatteryNative]::IsWindowVisible($target)) iconic=$([AiBatteryNative]::IsIconic($target)))"
|
|
806
|
-
Restore-DockTargetBorder
|
|
807
|
-
$script:dockLastPlacement = $null
|
|
808
|
-
Set-HudHiddenForDock $true
|
|
809
|
-
return
|
|
810
|
-
}
|
|
811
|
-
Clear-DockUnavailableGrace
|
|
812
|
-
|
|
813
|
-
if (Test-DockBottomPlacement) {
|
|
814
|
-
Reserve-DockTargetSpace
|
|
815
|
-
Repair-DockTargetSpaceAfterShellLayout
|
|
816
|
-
# Keep the terminal's native side border. The HUD overlaps and covers its
|
|
817
|
-
# bottom edge, then continues that border on its three exposed sides.
|
|
818
|
-
Restore-DockTargetBorder
|
|
819
|
-
}
|
|
820
|
-
$frame = Get-DockTargetFrame $target
|
|
821
|
-
if (-not $frame) {
|
|
822
|
-
if (-not (Test-DockUnavailablePastGrace "missing DWM frame")) { return }
|
|
823
|
-
Write-HudDockDebug "dock hide: no frame rect for target"
|
|
824
|
-
Restore-DockTargetBorder
|
|
825
|
-
Set-HudHiddenForDock $true
|
|
826
|
-
return
|
|
827
|
-
}
|
|
828
|
-
Clear-DockUnavailableGrace
|
|
829
|
-
$nextSquareCorners = Test-DockTargetUsesSquareCorners $frame
|
|
830
|
-
if ($script:dockSquareCorners -ne $nextSquareCorners) {
|
|
831
|
-
$script:dockSquareCorners = $nextSquareCorners
|
|
832
|
-
$script:dockLastPlacement = $null
|
|
833
|
-
$form.Invalidate()
|
|
834
|
-
}
|
|
835
|
-
if (Test-DockBottomPlacement) {
|
|
836
|
-
$horizontalInset = [math]::Max(0, [int]$script:dockHorizontalInset)
|
|
837
|
-
# GDI+ clips the right half-pixel border at the window edge, while the left
|
|
838
|
-
# half is anti-aliased outward. Trim only that optical overhang and keep the
|
|
839
|
-
# already aligned right edge fixed.
|
|
840
|
-
$leftOpticalInset = [math]::Max(0, [int]$script:dockLeftOpticalInset)
|
|
841
|
-
$stripWidth = [math]::Max(1, [int]($frame.Right - $frame.Left) - ($horizontalInset * 2) - $leftOpticalInset)
|
|
842
|
-
$stripHeight = [math]::Max(1, [int]$script:dockStripHeight)
|
|
843
|
-
$joinOverlap = [math]::Max(1, [int]$script:dockJoinOverlap)
|
|
844
|
-
$renderHeight = $stripHeight + $joinOverlap
|
|
845
|
-
$x = [int]$frame.Left + $horizontalInset + $leftOpticalInset
|
|
846
|
-
$anchorBottom = [int]$frame.Bottom
|
|
847
|
-
$y = $anchorBottom - $joinOverlap
|
|
848
|
-
$placement = "{0},{1},{2},{3},{4}" -f $x, $y, $stripWidth, $renderHeight, $script:dockSquareCorners
|
|
849
|
-
if ($script:dockLastPlacement -ne $placement) {
|
|
850
|
-
$script:dockLastPlacement = $placement
|
|
851
|
-
$script:dockTargetFrameChangedAtUtc = [datetime]::UtcNow
|
|
852
|
-
Write-HudDockDebug "dock TUI strip -> $placement"
|
|
853
|
-
$form.Bounds = [System.Drawing.Rectangle]::new($x, $y, $stripWidth, $renderHeight)
|
|
854
|
-
Set-DockedTuiWindowRegion
|
|
855
|
-
Sync-HitFormBounds
|
|
856
|
-
if ($script:dockTuiPaintPanel) { $script:dockTuiPaintPanel.Invalidate() }
|
|
857
|
-
}
|
|
858
|
-
Set-HudHiddenForDock $false
|
|
859
|
-
Sync-HudDockZOrder $target
|
|
860
|
-
return
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
if ($script:dockTuiStatusline -and $script:dockPlacementMode -eq "tabs") {
|
|
864
|
-
$dpi = 96
|
|
865
|
-
try {
|
|
866
|
-
$windowDpi = [AiBatteryNative]::GetDpiForWindow($target)
|
|
867
|
-
if ($windowDpi -gt 0) { $dpi = [int]$windowDpi }
|
|
868
|
-
} catch { }
|
|
869
|
-
$dockScale = $dpi / 96.0
|
|
870
|
-
$captionReserve = [int][math]::Round(150 * $dockScale)
|
|
871
|
-
$edgeMargin = [int][math]::Round(8 * $dockScale)
|
|
872
|
-
$minimumWidth = [int][math]::Round(260 * $dockScale)
|
|
873
|
-
$desiredWidth = [int][math]::Round(620 * $dockScale)
|
|
874
|
-
$availableWidth = [int]($frame.Right - $frame.Left) - $captionReserve - ($edgeMargin * 2)
|
|
875
|
-
if ($availableWidth -lt $minimumWidth) {
|
|
876
|
-
Write-HudDockDebug "dock tabs hide: available width $availableWidth"
|
|
877
|
-
Set-HudHiddenForDock $true
|
|
878
|
-
return
|
|
879
|
-
}
|
|
880
|
-
$width = [math]::Min($desiredWidth, $availableWidth)
|
|
881
|
-
$height = [math]::Max(1, [int]$script:dockStripHeight)
|
|
882
|
-
$x = [int]$frame.Right - $captionReserve - $edgeMargin - $width
|
|
883
|
-
$y = [int]$frame.Top + [int][math]::Round(6 * $dockScale)
|
|
884
|
-
$placement = "tabs,{0},{1},{2},{3}" -f $x, $y, $width, $height
|
|
885
|
-
if ($script:dockLastPlacement -ne $placement) {
|
|
886
|
-
$script:dockLastPlacement = $placement
|
|
887
|
-
$script:dockTargetFrameChangedAtUtc = [datetime]::UtcNow
|
|
888
|
-
Write-HudDockDebug "dock tabs -> $placement"
|
|
889
|
-
$form.Bounds = [System.Drawing.Rectangle]::new($x, $y, $width, $height)
|
|
890
|
-
Set-DockedTuiWindowRegion
|
|
891
|
-
Sync-HitFormBounds
|
|
892
|
-
if ($script:dockTuiPaintPanel) { $script:dockTuiPaintPanel.Invalidate() }
|
|
893
|
-
}
|
|
894
|
-
Set-HudHiddenForDock $false
|
|
895
|
-
Sync-HudDockZOrder $target
|
|
896
|
-
return
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
$dpi = 96
|
|
900
|
-
try {
|
|
901
|
-
$windowDpi = [AiBatteryNative]::GetDpiForWindow($target)
|
|
902
|
-
if ($windowDpi -gt 0) { $dpi = [int]$windowDpi }
|
|
903
|
-
} catch { }
|
|
904
|
-
$dockScale = $dpi / 96.0
|
|
905
|
-
$captionReserve = [int][math]::Round(150 * $dockScale)
|
|
906
|
-
$edgeMargin = [int][math]::Round(8 * $dockScale)
|
|
907
|
-
$x = $frame.Right - $captionReserve - $form.Width
|
|
908
|
-
$y = $frame.Top + [int][math]::Round(2 * $dockScale)
|
|
909
|
-
if ($x -lt ($frame.Left + $edgeMargin)) {
|
|
910
|
-
# The window is too narrow to host the HUD without covering its tabs.
|
|
911
|
-
Write-HudDockDebug "dock hide: narrow (x=$x frame=$($frame.Left),$($frame.Top),$($frame.Right),$($frame.Bottom) formWidth=$($form.Width) reserve=$captionReserve)"
|
|
912
|
-
Set-HudHiddenForDock $true
|
|
913
|
-
return
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
$placement = "{0},{1}" -f $x, $y
|
|
917
|
-
if ($script:dockLastPlacement -ne $placement) {
|
|
918
|
-
$script:dockLastPlacement = $placement
|
|
919
|
-
$script:dockTargetFrameChangedAtUtc = [datetime]::UtcNow
|
|
920
|
-
Write-HudDockDebug "dock placement -> $placement (frame $($frame.Left),$($frame.Top))-($($frame.Right),$($frame.Bottom))"
|
|
921
|
-
$form.Location = [System.Drawing.Point]::new([int]$x, [int]$y)
|
|
922
|
-
}
|
|
923
|
-
Set-HudHiddenForDock $false
|
|
924
|
-
Sync-HudDockZOrder $target
|
|
925
|
-
}
|
|
926
|
-
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
$targetIconic = [AiBatteryNative]::IsIconic($target)
|
|
798
|
+
$targetVisible = [AiBatteryNative]::IsWindowVisible($target) -and
|
|
799
|
+
-not $targetIconic -and
|
|
800
|
+
-not (Test-DockTargetCloaked $target)
|
|
801
|
+
if (-not $targetVisible) {
|
|
802
|
+
if (-not $targetIconic -and -not (Test-DockUnavailablePastGrace "visibility/cloak transition")) {
|
|
803
|
+
return
|
|
804
|
+
}
|
|
805
|
+
Write-HudDockDebug "dock hide: target not visible (visible=$([AiBatteryNative]::IsWindowVisible($target)) iconic=$([AiBatteryNative]::IsIconic($target)))"
|
|
806
|
+
Restore-DockTargetBorder
|
|
807
|
+
$script:dockLastPlacement = $null
|
|
808
|
+
Set-HudHiddenForDock $true
|
|
809
|
+
return
|
|
810
|
+
}
|
|
811
|
+
Clear-DockUnavailableGrace
|
|
812
|
+
|
|
813
|
+
if (Test-DockBottomPlacement) {
|
|
814
|
+
Reserve-DockTargetSpace
|
|
815
|
+
Repair-DockTargetSpaceAfterShellLayout
|
|
816
|
+
# Keep the terminal's native side border. The HUD overlaps and covers its
|
|
817
|
+
# bottom edge, then continues that border on its three exposed sides.
|
|
818
|
+
Restore-DockTargetBorder
|
|
819
|
+
}
|
|
820
|
+
$frame = Get-DockTargetFrame $target
|
|
821
|
+
if (-not $frame) {
|
|
822
|
+
if (-not (Test-DockUnavailablePastGrace "missing DWM frame")) { return }
|
|
823
|
+
Write-HudDockDebug "dock hide: no frame rect for target"
|
|
824
|
+
Restore-DockTargetBorder
|
|
825
|
+
Set-HudHiddenForDock $true
|
|
826
|
+
return
|
|
827
|
+
}
|
|
828
|
+
Clear-DockUnavailableGrace
|
|
829
|
+
$nextSquareCorners = Test-DockTargetUsesSquareCorners $frame
|
|
830
|
+
if ($script:dockSquareCorners -ne $nextSquareCorners) {
|
|
831
|
+
$script:dockSquareCorners = $nextSquareCorners
|
|
832
|
+
$script:dockLastPlacement = $null
|
|
833
|
+
$form.Invalidate()
|
|
834
|
+
}
|
|
835
|
+
if (Test-DockBottomPlacement) {
|
|
836
|
+
$horizontalInset = [math]::Max(0, [int]$script:dockHorizontalInset)
|
|
837
|
+
# GDI+ clips the right half-pixel border at the window edge, while the left
|
|
838
|
+
# half is anti-aliased outward. Trim only that optical overhang and keep the
|
|
839
|
+
# already aligned right edge fixed.
|
|
840
|
+
$leftOpticalInset = [math]::Max(0, [int]$script:dockLeftOpticalInset)
|
|
841
|
+
$stripWidth = [math]::Max(1, [int]($frame.Right - $frame.Left) - ($horizontalInset * 2) - $leftOpticalInset)
|
|
842
|
+
$stripHeight = [math]::Max(1, [int]$script:dockStripHeight)
|
|
843
|
+
$joinOverlap = [math]::Max(1, [int]$script:dockJoinOverlap)
|
|
844
|
+
$renderHeight = $stripHeight + $joinOverlap
|
|
845
|
+
$x = [int]$frame.Left + $horizontalInset + $leftOpticalInset
|
|
846
|
+
$anchorBottom = [int]$frame.Bottom
|
|
847
|
+
$y = $anchorBottom - $joinOverlap
|
|
848
|
+
$placement = "{0},{1},{2},{3},{4}" -f $x, $y, $stripWidth, $renderHeight, $script:dockSquareCorners
|
|
849
|
+
if ($script:dockLastPlacement -ne $placement) {
|
|
850
|
+
$script:dockLastPlacement = $placement
|
|
851
|
+
$script:dockTargetFrameChangedAtUtc = [datetime]::UtcNow
|
|
852
|
+
Write-HudDockDebug "dock TUI strip -> $placement"
|
|
853
|
+
$form.Bounds = [System.Drawing.Rectangle]::new($x, $y, $stripWidth, $renderHeight)
|
|
854
|
+
Set-DockedTuiWindowRegion
|
|
855
|
+
Sync-HitFormBounds
|
|
856
|
+
if ($script:dockTuiPaintPanel) { $script:dockTuiPaintPanel.Invalidate() }
|
|
857
|
+
}
|
|
858
|
+
Set-HudHiddenForDock $false
|
|
859
|
+
Sync-HudDockZOrder $target
|
|
860
|
+
return
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
if ($script:dockTuiStatusline -and $script:dockPlacementMode -eq "tabs") {
|
|
864
|
+
$dpi = 96
|
|
865
|
+
try {
|
|
866
|
+
$windowDpi = [AiBatteryNative]::GetDpiForWindow($target)
|
|
867
|
+
if ($windowDpi -gt 0) { $dpi = [int]$windowDpi }
|
|
868
|
+
} catch { }
|
|
869
|
+
$dockScale = $dpi / 96.0
|
|
870
|
+
$captionReserve = [int][math]::Round(150 * $dockScale)
|
|
871
|
+
$edgeMargin = [int][math]::Round(8 * $dockScale)
|
|
872
|
+
$minimumWidth = [int][math]::Round(260 * $dockScale)
|
|
873
|
+
$desiredWidth = [int][math]::Round(620 * $dockScale)
|
|
874
|
+
$availableWidth = [int]($frame.Right - $frame.Left) - $captionReserve - ($edgeMargin * 2)
|
|
875
|
+
if ($availableWidth -lt $minimumWidth) {
|
|
876
|
+
Write-HudDockDebug "dock tabs hide: available width $availableWidth"
|
|
877
|
+
Set-HudHiddenForDock $true
|
|
878
|
+
return
|
|
879
|
+
}
|
|
880
|
+
$width = [math]::Min($desiredWidth, $availableWidth)
|
|
881
|
+
$height = [math]::Max(1, [int]$script:dockStripHeight)
|
|
882
|
+
$x = [int]$frame.Right - $captionReserve - $edgeMargin - $width
|
|
883
|
+
$y = [int]$frame.Top + [int][math]::Round(6 * $dockScale)
|
|
884
|
+
$placement = "tabs,{0},{1},{2},{3}" -f $x, $y, $width, $height
|
|
885
|
+
if ($script:dockLastPlacement -ne $placement) {
|
|
886
|
+
$script:dockLastPlacement = $placement
|
|
887
|
+
$script:dockTargetFrameChangedAtUtc = [datetime]::UtcNow
|
|
888
|
+
Write-HudDockDebug "dock tabs -> $placement"
|
|
889
|
+
$form.Bounds = [System.Drawing.Rectangle]::new($x, $y, $width, $height)
|
|
890
|
+
Set-DockedTuiWindowRegion
|
|
891
|
+
Sync-HitFormBounds
|
|
892
|
+
if ($script:dockTuiPaintPanel) { $script:dockTuiPaintPanel.Invalidate() }
|
|
893
|
+
}
|
|
894
|
+
Set-HudHiddenForDock $false
|
|
895
|
+
Sync-HudDockZOrder $target
|
|
896
|
+
return
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
$dpi = 96
|
|
900
|
+
try {
|
|
901
|
+
$windowDpi = [AiBatteryNative]::GetDpiForWindow($target)
|
|
902
|
+
if ($windowDpi -gt 0) { $dpi = [int]$windowDpi }
|
|
903
|
+
} catch { }
|
|
904
|
+
$dockScale = $dpi / 96.0
|
|
905
|
+
$captionReserve = [int][math]::Round(150 * $dockScale)
|
|
906
|
+
$edgeMargin = [int][math]::Round(8 * $dockScale)
|
|
907
|
+
$x = $frame.Right - $captionReserve - $form.Width
|
|
908
|
+
$y = $frame.Top + [int][math]::Round(2 * $dockScale)
|
|
909
|
+
if ($x -lt ($frame.Left + $edgeMargin)) {
|
|
910
|
+
# The window is too narrow to host the HUD without covering its tabs.
|
|
911
|
+
Write-HudDockDebug "dock hide: narrow (x=$x frame=$($frame.Left),$($frame.Top),$($frame.Right),$($frame.Bottom) formWidth=$($form.Width) reserve=$captionReserve)"
|
|
912
|
+
Set-HudHiddenForDock $true
|
|
913
|
+
return
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
$placement = "{0},{1}" -f $x, $y
|
|
917
|
+
if ($script:dockLastPlacement -ne $placement) {
|
|
918
|
+
$script:dockLastPlacement = $placement
|
|
919
|
+
$script:dockTargetFrameChangedAtUtc = [datetime]::UtcNow
|
|
920
|
+
Write-HudDockDebug "dock placement -> $placement (frame $($frame.Left),$($frame.Top))-($($frame.Right),$($frame.Bottom))"
|
|
921
|
+
$form.Location = [System.Drawing.Point]::new([int]$x, [int]$y)
|
|
922
|
+
}
|
|
923
|
+
Set-HudHiddenForDock $false
|
|
924
|
+
Sync-HudDockZOrder $target
|
|
925
|
+
}
|
|
926
|
+
|
|
927
927
|
function Get-DockNearestVisibleWindowAbove([IntPtr]$Handle) {
|
|
928
928
|
$candidate = [AiBatteryNative]::GetWindow($Handle, [AiBatteryNative]::GW_HWNDPREV)
|
|
929
929
|
for ($scanned = 0; $scanned -lt 64 -and $candidate -ne [IntPtr]::Zero; $scanned += 1) {
|
|
@@ -934,10 +934,10 @@ function Get-DockNearestVisibleWindowAbove([IntPtr]$Handle) {
|
|
|
934
934
|
}
|
|
935
935
|
|
|
936
936
|
function Sync-HudDockZOrder([IntPtr]$Target) {
|
|
937
|
-
# Keep the dock immediately above its terminal but below every window that
|
|
938
|
-
# already covers the terminal. The bottom layout overlaps the terminal frame
|
|
939
|
-
# so its opaque surface masks the DWM edge without becoming globally topmost.
|
|
940
|
-
if (-not $form -or $form.IsDisposed) { return }
|
|
937
|
+
# Keep the dock immediately above its terminal but below every window that
|
|
938
|
+
# already covers the terminal. The bottom layout overlaps the terminal frame
|
|
939
|
+
# so its opaque surface masks the DWM edge without becoming globally topmost.
|
|
940
|
+
if (-not $form -or $form.IsDisposed) { return }
|
|
941
941
|
if ($script:hudHiddenForFullscreen -or $script:hudHiddenForDock) { return }
|
|
942
942
|
$formHandle = $form.Handle
|
|
943
943
|
$hitHandle = if ($hitForm -and -not $hitForm.IsDisposed) { $hitForm.Handle } else { [IntPtr]::Zero }
|
|
@@ -964,136 +964,136 @@ function Sync-HudDockZOrder([IntPtr]$Target) {
|
|
|
964
964
|
}
|
|
965
965
|
}
|
|
966
966
|
}
|
|
967
|
-
|
|
968
|
-
$script:dockResizeDragActive = $false
|
|
969
|
-
$script:dockResizeDragEdge = ""
|
|
970
|
-
$script:dockResizeDragStart = [System.Drawing.Point]::Empty
|
|
971
|
-
$script:dockResizeDragRect = $null
|
|
972
|
-
|
|
973
|
-
function Get-HudDockResizeEdge([System.Drawing.Point]$ScreenPoint) {
|
|
974
|
-
if (-not (Test-DockBottomPlacement) -or -not $form -or $form.IsDisposed) { return "" }
|
|
975
|
-
$bottomGrip = [math]::Max(4, (Scale-HudValue 6))
|
|
976
|
-
if ($ScreenPoint.Y -lt ($form.Bottom - $bottomGrip)) { return "" }
|
|
977
|
-
$cornerGrip = [math]::Max(12, (Scale-HudValue 18))
|
|
978
|
-
if ($ScreenPoint.X -le ($form.Left + $cornerGrip)) { return "bottom-left" }
|
|
979
|
-
if ($ScreenPoint.X -ge ($form.Right - $cornerGrip)) { return "bottom-right" }
|
|
980
|
-
return "bottom"
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
function Set-HudDockResizeCursor($Control, [string]$Edge) {
|
|
984
|
-
if (-not $Control) { return }
|
|
985
|
-
if ($Edge -eq "bottom-left") {
|
|
986
|
-
$Control.Cursor = [System.Windows.Forms.Cursors]::SizeNESW
|
|
987
|
-
} elseif ($Edge -eq "bottom-right") {
|
|
988
|
-
$Control.Cursor = [System.Windows.Forms.Cursors]::SizeNWSE
|
|
989
|
-
} elseif ($Edge -eq "bottom") {
|
|
990
|
-
$Control.Cursor = [System.Windows.Forms.Cursors]::SizeNS
|
|
991
|
-
} else {
|
|
992
|
-
$Control.Cursor = [System.Windows.Forms.Cursors]::Default
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
function Initialize-HudDockResizeGrip {
|
|
997
|
-
if (-not $script:dockTuiStatusline) { return }
|
|
998
|
-
$mouseDown = {
|
|
999
|
-
param($sender, $event)
|
|
1000
|
-
if ($event.Button -ne [System.Windows.Forms.MouseButtons]::Left) { return }
|
|
1001
|
-
$point = [System.Windows.Forms.Cursor]::Position
|
|
1002
|
-
$edge = Get-HudDockResizeEdge $point
|
|
1003
|
-
if (-not $edge) { return }
|
|
1004
|
-
$rect = New-Object AiBatteryRect
|
|
1005
|
-
if (-not [AiBatteryNative]::GetWindowRect($script:dockTargetHandle, [ref]$rect)) { return }
|
|
1006
|
-
$script:dockResizeDragActive = $true
|
|
1007
|
-
$script:dockResizeDragEdge = $edge
|
|
1008
|
-
$script:dockResizeDragStart = $point
|
|
1009
|
-
$script:dockResizeDragRect = [PSCustomObject]@{
|
|
1010
|
-
Left = [int]$rect.Left
|
|
1011
|
-
Top = [int]$rect.Top
|
|
1012
|
-
Right = [int]$rect.Right
|
|
1013
|
-
Bottom = [int]$rect.Bottom
|
|
1014
|
-
}
|
|
1015
|
-
$sender.Capture = $true
|
|
1016
|
-
}
|
|
1017
|
-
$mouseMove = {
|
|
1018
|
-
param($sender, $event)
|
|
1019
|
-
$point = [System.Windows.Forms.Cursor]::Position
|
|
1020
|
-
if (-not $script:dockResizeDragActive -or -not $script:dockResizeDragRect) {
|
|
1021
|
-
Set-HudDockResizeCursor $sender (Get-HudDockResizeEdge $point)
|
|
1022
|
-
return
|
|
1023
|
-
}
|
|
1024
|
-
$start = $script:dockResizeDragRect
|
|
1025
|
-
$dx = $point.X - $script:dockResizeDragStart.X
|
|
1026
|
-
$dy = $point.Y - $script:dockResizeDragStart.Y
|
|
1027
|
-
$left = [int]$start.Left
|
|
1028
|
-
$top = [int]$start.Top
|
|
1029
|
-
$right = [int]$start.Right
|
|
1030
|
-
$bottom = [int]($start.Bottom + $dy)
|
|
1031
|
-
if ($script:dockResizeDragEdge -eq "bottom-left") {
|
|
1032
|
-
$left = [int]($start.Left + $dx)
|
|
1033
|
-
} elseif ($script:dockResizeDragEdge -eq "bottom-right") {
|
|
1034
|
-
$right = [int]($start.Right + $dx)
|
|
1035
|
-
}
|
|
1036
|
-
$minimumWidth = [math]::Max(240, (Scale-HudValue 320))
|
|
1037
|
-
$minimumHeight = [math]::Max(120, (Scale-HudValue 180))
|
|
1038
|
-
if (($right - $left) -lt $minimumWidth) {
|
|
1039
|
-
if ($script:dockResizeDragEdge -eq "bottom-left") {
|
|
1040
|
-
$left = $right - $minimumWidth
|
|
1041
|
-
} else {
|
|
1042
|
-
$right = $left + $minimumWidth
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
if (($bottom - $top) -lt $minimumHeight) { $bottom = $top + $minimumHeight }
|
|
1046
|
-
$work = Get-DockMonitorWorkArea $script:dockTargetHandle
|
|
1047
|
-
if ($work -and $bottom -gt $work.Bottom) { $bottom = $work.Bottom }
|
|
1048
|
-
[AiBatteryNative]::SetWindowPos(
|
|
1049
|
-
$script:dockTargetHandle,
|
|
1050
|
-
[AiBatteryNative]::HWND_TOP,
|
|
1051
|
-
$left,
|
|
1052
|
-
$top,
|
|
1053
|
-
($right - $left),
|
|
1054
|
-
($bottom - $top),
|
|
1055
|
-
([AiBatteryNative]::SWP_NOZORDER -bor [AiBatteryNative]::SWP_NOACTIVATE)
|
|
1056
|
-
) | Out-Null
|
|
1057
|
-
$script:dockLastPlacement = $null
|
|
1058
|
-
Update-HudDockPlacement
|
|
1059
|
-
}
|
|
1060
|
-
$mouseUp = {
|
|
1061
|
-
param($sender, $event)
|
|
1062
|
-
if (-not $script:dockResizeDragActive) { return }
|
|
1063
|
-
$script:dockResizeDragActive = $false
|
|
1064
|
-
$script:dockResizeDragEdge = ""
|
|
1065
|
-
$script:dockResizeDragRect = $null
|
|
1066
|
-
$sender.Capture = $false
|
|
1067
|
-
Set-HudDockResizeCursor $sender ""
|
|
1068
|
-
Update-HudDockPlacement
|
|
1069
|
-
}
|
|
1070
|
-
foreach ($control in @($form, $panel, $script:dockTuiPaintPanel)) {
|
|
1071
|
-
if (-not $control) { continue }
|
|
1072
|
-
$control.add_MouseDown($mouseDown)
|
|
1073
|
-
$control.add_MouseMove($mouseMove)
|
|
1074
|
-
$control.add_MouseUp($mouseUp)
|
|
1075
|
-
$control.add_MouseLeave({
|
|
1076
|
-
param($sender, $event)
|
|
1077
|
-
if (-not $script:dockResizeDragActive) { Set-HudDockResizeCursor $sender "" }
|
|
1078
|
-
})
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
function Update-HudDockRequest {
|
|
1083
|
-
$path = Get-HudDockRequestPath
|
|
1084
|
-
if (-not (Test-Path -LiteralPath $path)) { return }
|
|
1085
|
-
try {
|
|
1086
|
-
$write = (Get-Item -LiteralPath $path).LastWriteTimeUtc
|
|
1087
|
-
if ($write -le $script:dockRequestLastWriteUtc) { return }
|
|
1088
|
-
$script:dockRequestLastWriteUtc = $write
|
|
1089
|
-
$request = Get-Content -LiteralPath $path -Raw | ConvertFrom-Json
|
|
1090
|
-
Remove-Item -LiteralPath $path -Force -ErrorAction SilentlyContinue
|
|
1091
|
-
if ($request.stop) {
|
|
1092
|
-
if (([datetime]::UtcNow - $write).TotalSeconds -le 30) {
|
|
1093
|
-
$form.Close()
|
|
1094
|
-
}
|
|
1095
|
-
return
|
|
1096
|
-
}
|
|
967
|
+
|
|
968
|
+
$script:dockResizeDragActive = $false
|
|
969
|
+
$script:dockResizeDragEdge = ""
|
|
970
|
+
$script:dockResizeDragStart = [System.Drawing.Point]::Empty
|
|
971
|
+
$script:dockResizeDragRect = $null
|
|
972
|
+
|
|
973
|
+
function Get-HudDockResizeEdge([System.Drawing.Point]$ScreenPoint) {
|
|
974
|
+
if (-not (Test-DockBottomPlacement) -or -not $form -or $form.IsDisposed) { return "" }
|
|
975
|
+
$bottomGrip = [math]::Max(4, (Scale-HudValue 6))
|
|
976
|
+
if ($ScreenPoint.Y -lt ($form.Bottom - $bottomGrip)) { return "" }
|
|
977
|
+
$cornerGrip = [math]::Max(12, (Scale-HudValue 18))
|
|
978
|
+
if ($ScreenPoint.X -le ($form.Left + $cornerGrip)) { return "bottom-left" }
|
|
979
|
+
if ($ScreenPoint.X -ge ($form.Right - $cornerGrip)) { return "bottom-right" }
|
|
980
|
+
return "bottom"
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
function Set-HudDockResizeCursor($Control, [string]$Edge) {
|
|
984
|
+
if (-not $Control) { return }
|
|
985
|
+
if ($Edge -eq "bottom-left") {
|
|
986
|
+
$Control.Cursor = [System.Windows.Forms.Cursors]::SizeNESW
|
|
987
|
+
} elseif ($Edge -eq "bottom-right") {
|
|
988
|
+
$Control.Cursor = [System.Windows.Forms.Cursors]::SizeNWSE
|
|
989
|
+
} elseif ($Edge -eq "bottom") {
|
|
990
|
+
$Control.Cursor = [System.Windows.Forms.Cursors]::SizeNS
|
|
991
|
+
} else {
|
|
992
|
+
$Control.Cursor = [System.Windows.Forms.Cursors]::Default
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
function Initialize-HudDockResizeGrip {
|
|
997
|
+
if (-not $script:dockTuiStatusline) { return }
|
|
998
|
+
$mouseDown = {
|
|
999
|
+
param($sender, $event)
|
|
1000
|
+
if ($event.Button -ne [System.Windows.Forms.MouseButtons]::Left) { return }
|
|
1001
|
+
$point = [System.Windows.Forms.Cursor]::Position
|
|
1002
|
+
$edge = Get-HudDockResizeEdge $point
|
|
1003
|
+
if (-not $edge) { return }
|
|
1004
|
+
$rect = New-Object AiBatteryRect
|
|
1005
|
+
if (-not [AiBatteryNative]::GetWindowRect($script:dockTargetHandle, [ref]$rect)) { return }
|
|
1006
|
+
$script:dockResizeDragActive = $true
|
|
1007
|
+
$script:dockResizeDragEdge = $edge
|
|
1008
|
+
$script:dockResizeDragStart = $point
|
|
1009
|
+
$script:dockResizeDragRect = [PSCustomObject]@{
|
|
1010
|
+
Left = [int]$rect.Left
|
|
1011
|
+
Top = [int]$rect.Top
|
|
1012
|
+
Right = [int]$rect.Right
|
|
1013
|
+
Bottom = [int]$rect.Bottom
|
|
1014
|
+
}
|
|
1015
|
+
$sender.Capture = $true
|
|
1016
|
+
}
|
|
1017
|
+
$mouseMove = {
|
|
1018
|
+
param($sender, $event)
|
|
1019
|
+
$point = [System.Windows.Forms.Cursor]::Position
|
|
1020
|
+
if (-not $script:dockResizeDragActive -or -not $script:dockResizeDragRect) {
|
|
1021
|
+
Set-HudDockResizeCursor $sender (Get-HudDockResizeEdge $point)
|
|
1022
|
+
return
|
|
1023
|
+
}
|
|
1024
|
+
$start = $script:dockResizeDragRect
|
|
1025
|
+
$dx = $point.X - $script:dockResizeDragStart.X
|
|
1026
|
+
$dy = $point.Y - $script:dockResizeDragStart.Y
|
|
1027
|
+
$left = [int]$start.Left
|
|
1028
|
+
$top = [int]$start.Top
|
|
1029
|
+
$right = [int]$start.Right
|
|
1030
|
+
$bottom = [int]($start.Bottom + $dy)
|
|
1031
|
+
if ($script:dockResizeDragEdge -eq "bottom-left") {
|
|
1032
|
+
$left = [int]($start.Left + $dx)
|
|
1033
|
+
} elseif ($script:dockResizeDragEdge -eq "bottom-right") {
|
|
1034
|
+
$right = [int]($start.Right + $dx)
|
|
1035
|
+
}
|
|
1036
|
+
$minimumWidth = [math]::Max(240, (Scale-HudValue 320))
|
|
1037
|
+
$minimumHeight = [math]::Max(120, (Scale-HudValue 180))
|
|
1038
|
+
if (($right - $left) -lt $minimumWidth) {
|
|
1039
|
+
if ($script:dockResizeDragEdge -eq "bottom-left") {
|
|
1040
|
+
$left = $right - $minimumWidth
|
|
1041
|
+
} else {
|
|
1042
|
+
$right = $left + $minimumWidth
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (($bottom - $top) -lt $minimumHeight) { $bottom = $top + $minimumHeight }
|
|
1046
|
+
$work = Get-DockMonitorWorkArea $script:dockTargetHandle
|
|
1047
|
+
if ($work -and $bottom -gt $work.Bottom) { $bottom = $work.Bottom }
|
|
1048
|
+
[AiBatteryNative]::SetWindowPos(
|
|
1049
|
+
$script:dockTargetHandle,
|
|
1050
|
+
[AiBatteryNative]::HWND_TOP,
|
|
1051
|
+
$left,
|
|
1052
|
+
$top,
|
|
1053
|
+
($right - $left),
|
|
1054
|
+
($bottom - $top),
|
|
1055
|
+
([AiBatteryNative]::SWP_NOZORDER -bor [AiBatteryNative]::SWP_NOACTIVATE)
|
|
1056
|
+
) | Out-Null
|
|
1057
|
+
$script:dockLastPlacement = $null
|
|
1058
|
+
Update-HudDockPlacement
|
|
1059
|
+
}
|
|
1060
|
+
$mouseUp = {
|
|
1061
|
+
param($sender, $event)
|
|
1062
|
+
if (-not $script:dockResizeDragActive) { return }
|
|
1063
|
+
$script:dockResizeDragActive = $false
|
|
1064
|
+
$script:dockResizeDragEdge = ""
|
|
1065
|
+
$script:dockResizeDragRect = $null
|
|
1066
|
+
$sender.Capture = $false
|
|
1067
|
+
Set-HudDockResizeCursor $sender ""
|
|
1068
|
+
Update-HudDockPlacement
|
|
1069
|
+
}
|
|
1070
|
+
foreach ($control in @($form, $panel, $script:dockTuiPaintPanel)) {
|
|
1071
|
+
if (-not $control) { continue }
|
|
1072
|
+
$control.add_MouseDown($mouseDown)
|
|
1073
|
+
$control.add_MouseMove($mouseMove)
|
|
1074
|
+
$control.add_MouseUp($mouseUp)
|
|
1075
|
+
$control.add_MouseLeave({
|
|
1076
|
+
param($sender, $event)
|
|
1077
|
+
if (-not $script:dockResizeDragActive) { Set-HudDockResizeCursor $sender "" }
|
|
1078
|
+
})
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
function Update-HudDockRequest {
|
|
1083
|
+
$path = Get-HudDockRequestPath
|
|
1084
|
+
if (-not (Test-Path -LiteralPath $path)) { return }
|
|
1085
|
+
try {
|
|
1086
|
+
$write = (Get-Item -LiteralPath $path).LastWriteTimeUtc
|
|
1087
|
+
if ($write -le $script:dockRequestLastWriteUtc) { return }
|
|
1088
|
+
$script:dockRequestLastWriteUtc = $write
|
|
1089
|
+
$request = Get-Content -LiteralPath $path -Raw | ConvertFrom-Json
|
|
1090
|
+
Remove-Item -LiteralPath $path -Force -ErrorAction SilentlyContinue
|
|
1091
|
+
if ($request.stop) {
|
|
1092
|
+
if (([datetime]::UtcNow - $write).TotalSeconds -le 30) {
|
|
1093
|
+
$form.Close()
|
|
1094
|
+
}
|
|
1095
|
+
return
|
|
1096
|
+
}
|
|
1097
1097
|
if ($request.detach) {
|
|
1098
1098
|
$requestSession = if ($null -ne $request.session) { [Int64]$request.session } else { 0 }
|
|
1099
1099
|
$requestProvider = if ($request.provider) { [string]$request.provider } else { "" }
|
|
@@ -1109,11 +1109,11 @@ function Update-HudDockRequest {
|
|
|
1109
1109
|
}
|
|
1110
1110
|
}
|
|
1111
1111
|
return
|
|
1112
|
-
}
|
|
1113
|
-
$hwnd = [Int64]$request.hwnd
|
|
1114
|
-
if ($hwnd -ne 0 -and [AiBatteryNative]::IsWindow([IntPtr]::new($hwnd))) {
|
|
1115
|
-
if ($request.placement) {
|
|
1116
|
-
Set-DockPlacementMode ([string]$request.placement)
|
|
1112
|
+
}
|
|
1113
|
+
$hwnd = [Int64]$request.hwnd
|
|
1114
|
+
if ($hwnd -ne 0 -and [AiBatteryNative]::IsWindow([IntPtr]::new($hwnd))) {
|
|
1115
|
+
if ($request.placement) {
|
|
1116
|
+
Set-DockPlacementMode ([string]$request.placement)
|
|
1117
1117
|
}
|
|
1118
1118
|
$requestSession = if ($null -ne $request.session) { [Int64]$request.session } else { 0 }
|
|
1119
1119
|
$requestOwnerPid = if ($null -ne $request.ownerPid) { [int]$request.ownerPid } else { 0 }
|
|
@@ -1125,12 +1125,12 @@ function Update-HudDockRequest {
|
|
|
1125
1125
|
}
|
|
1126
1126
|
$script:dockTargetHandle = [IntPtr]::new($hwnd)
|
|
1127
1127
|
$script:dockSession = $requestSession
|
|
1128
|
-
$script:dockLastPlacement = $null
|
|
1129
|
-
$script:dockObservedFrameDragActive = $false
|
|
1130
|
-
$script:dockObservedRawRectKey = ""
|
|
1131
|
-
Update-HudDockPlacement
|
|
1132
|
-
}
|
|
1133
|
-
} catch {
|
|
1134
|
-
# A malformed request is discarded on the next write.
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1128
|
+
$script:dockLastPlacement = $null
|
|
1129
|
+
$script:dockObservedFrameDragActive = $false
|
|
1130
|
+
$script:dockObservedRawRectKey = ""
|
|
1131
|
+
Update-HudDockPlacement
|
|
1132
|
+
}
|
|
1133
|
+
} catch {
|
|
1134
|
+
# A malformed request is discarded on the next write.
|
|
1135
|
+
}
|
|
1136
|
+
}
|