Skip to content

fix(skia-win32): re-apply SetWindowPos after SW_SHOWNORMAL on first show - #23196

Merged
Xiaoy312 merged 1 commit into
masterfrom
dev/xygu/20260504/win32-native-element-coords
May 5, 2026
Merged

Xiaoy312 merged 1 commit into
masterfrom
dev/xygu/20260504/win32-native-element-coords

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes unoplatform/kahua-private#467

PR Type:

🐞 Bugfix

What is the current behavior? 🤔

Since #23126, native elements hosted in a Win32 Skia window are placed at the wrong position on first show. The element appears at its original screen coordinates (e.g. 268,291 / 1440×759) rather than at the correct parent-relative position (e.g. 0,141 / 991×500). Resizing the element by even 1 pixel corrects it.

What is the new behavior? 🚀

Native elements appear at the correct position immediately on first show, without requiring a resize.

Root cause

SW_SHOWNORMAL restores the window using its saved WINDOWPLACEMENT.rcNormalPosition, which still holds the old screen coordinates from before SetParent was called. Once the window is a child, those screen coordinates are reinterpreted as parent-relative offsets, placing the element at the wrong location.

The pre-#23126 code accidentally masked this: ShowWindow was called in ArrangeNativeElement, and a second arrange immediately followed with another SetWindowPos that corrected the position. After #23126 deferred show to the render handler, there was no subsequent SetWindowPos to fix it — hence the resize workaround worked (it triggered another SetWindowPos after the window was already visible).

Fix: re-apply SetWindowPos with the correct rect immediately after SW_SHOWNORMAL.

PR Checklist ✅

SW_SHOWNORMAL restores the window's saved WINDOWPLACEMENT.rcNormalPosition,
which still holds the old screen coordinates from before SetParent. Once the
window is a child, those coordinates are reinterpreted as parent-relative
offsets, placing the native element at the wrong position.

Re-applying SetWindowPos immediately after ShowWindow overrides the restored
placement so the element appears at the correct location.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Copilot AI review requested due to automatic review settings May 4, 2026 23:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Win32 Skia regression in native element hosting where a re-parented child HWND could appear at stale screen coordinates on its first show. It does so within Win32NativeElementHostingExtension, which is the Win32-specific bridge between Uno layout/clip updates and hosted native windows.

Changes:

  • Keeps the existing deferred first-show flow, but now re-applies SetWindowPos immediately after SW_SHOWNORMAL.
  • Documents why SW_SHOWNORMAL restores stale WINDOWPLACEMENT.rcNormalPosition values after SetParent.
  • Preserves the existing logging path if the corrective SetWindowPos call fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Xiaoy312
Xiaoy312 requested a review from ramezgerges May 4, 2026 23:24
@unodevops

Copy link
Copy Markdown
Contributor

@Xiaoy312
Xiaoy312 merged commit 3d0094f into master May 5, 2026
49 checks passed
@Xiaoy312
Xiaoy312 deleted the dev/xygu/20260504/win32-native-element-coords branch May 5, 2026 15:55
pull Bot pushed a commit to Stars1233/uno that referenced this pull request May 6, 2026
…u/20260504/win32-native-element-coords"

This reverts commit 3d0094f, reversing
changes made to b4db8c0.
pull Bot pushed a commit to Stars1233/uno that referenced this pull request May 8, 2026
…/dev/xygu/20260504/win32-native-element-coords""

This reverts commit bfc23e2.
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.

4 participants