Skip to content

fix(windows): pull the new Explorer window to the foreground - #3

Merged
BrianLeishman merged 1 commit into
masterfrom
fix/windows-explorer-foreground
Jul 8, 2026
Merged

BrianLeishman merged 1 commit into
masterfrom
fix/windows-explorer-foreground

Conversation

@BrianLeishman

Copy link
Copy Markdown
Member

Summary

  • v0.2.1 fixed the invisible window (SW_HIDE), but the folder window still opens behind everything with only a taskbar flash: Windows' foreground lock denies SetForegroundWindow to a background process like this server, and the blink is the consolation FlashWindow.
  • After launching Explorer, snapshot-diff the shell's folder windows (CabinetWClass/ExploreWClass via EnumWindows) to find the window this request created, then force it forward: SW_RESTORE if minimized → BringWindowToTop + SetForegroundWindow → the classic synthetic ALT-press unlock when Windows denies it → SwitchToThisWindow (Alt-Tab-equivalent) as last resort.
  • If Explorer recycled an existing window (no new HWND within 3s), focus is deliberately left alone — the folder is open, we just don't steal focus for a window we can't identify.
  • EnumWindows results go through a package-level buffer behind a mutex instead of passing a Go pointer through LPARAM, which go vet (correctly) flags as unsafe.Pointer misuse.

Test plan

  • GOOS=windows go build + GOOS=windows go vet
  • GOOS=linux CGO_ENABLED=0 go build
  • go build ./... && go vet ./... && go test ./... (darwin)
  • Windows spot-check on the v0.2.2 MSI: click a storage link with other windows focused — Explorer window should land on top, focused, no taskbar blink

🤖 Generated with Claude Code

Windows' foreground lock denies SetForegroundWindow to a background
process like this server, so the folder window opened behind everything
with only a taskbar flash. Snapshot Explorer's folder windows
(CabinetWClass/ExploreWClass) before launch, poll up to 3s for the new
one, then force it forward: SW_RESTORE if minimized, SetForegroundWindow,
the synthetic ALT-press unlock when that's denied, SwitchToThisWindow as
a last resort. If Explorer recycled an existing window (no new HWND),
focus is left alone.

EnumWindows results travel through a package-level buffer guarded by a
mutex instead of smuggling a Go pointer through LPARAM, which trips
vet's unsafe.Pointer checks.

Co-Authored-By: Claude Fable 5 (1M context) <noreply@anthropic.com>
@BrianLeishman
BrianLeishman merged commit 25eaec1 into master Jul 8, 2026
4 checks passed
@BrianLeishman
BrianLeishman deleted the fix/windows-explorer-foreground branch July 8, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant