Skip to content

fix(windows): prevent Center() from stealing focus when StartHidden:true#5249

Draft
leaanthony wants to merge 1 commit intomasterfrom
v2-bugfix/4882-starthidden-focus-steal
Draft

fix(windows): prevent Center() from stealing focus when StartHidden:true#5249
leaanthony wants to merge 1 commit intomasterfrom
v2-bugfix/4882-starthidden-focus-steal

Conversation

@leaanthony
Copy link
Copy Markdown
Member

Description

Fixes #4882

When a Wails v2 app is started with StartHidden: true on Windows, the Center() method calls SetWindowPos with HWND_TOP but without the SWP_NOACTIVATE flag. This causes the window to be activated (stealing focus from the foreground application) even though it should remain hidden.

Changes

  • Added SWP_NOACTIVATE flag to the SetWindowPos call in Form.Center() (v2/internal/frontend/desktop/windows/winc/form.go:171)
  • This matches the pattern used in window.go:248 where SWP_NOACTIVATE is already used for positioning operations

Testing

  • Added test in v2/test/4882/center_noactivate_test.go verifying the flag combination
…s true

When StartHidden:true is set, the Center() method's SetWindowPos call
would activate the window and steal focus from the foreground application.
Adding SWP_NOACTIVATE to the flags prevents this behavior.

Fixes #4882
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 26, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c063e758-15ae-4e04-9baf-f0f3dfba7808

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch v2-bugfix/4882-starthidden-focus-steal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant