Repository navigation
fix(windows): pull the new Explorer window to the foreground - #3
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SetForegroundWindowto a background process like this server, and the blink is the consolationFlashWindow.CabinetWClass/ExploreWClassviaEnumWindows) to find the window this request created, then force it forward:SW_RESTOREif minimized →BringWindowToTop+SetForegroundWindow→ the classic synthetic ALT-press unlock when Windows denies it →SwitchToThisWindow(Alt-Tab-equivalent) as last resort.EnumWindowsresults go through a package-level buffer behind a mutex instead of passing a Go pointer through LPARAM, whichgo vet(correctly) flags as unsafe.Pointer misuse.Test plan
GOOS=windows go build+GOOS=windows go vetGOOS=linux CGO_ENABLED=0 go buildgo build ./... && go vet ./... && go test ./...(darwin)🤖 Generated with Claude Code