Skip to content

fix(x11): Fix WebView2 native element embedding on WSLg (Weston/XWayland) - #23736

Merged
ramezgerges merged 5 commits into
unoplatform:masterfrom
ramezgerges:fix/x11-native-element-wslg-reparent
Jul 16, 2026
Merged

ramezgerges merged 5 commits into
unoplatform:masterfrom
ramezgerges:fix/x11-native-element-wslg-reparent

Conversation

@ramezgerges

@ramezgerges ramezgerges commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #23735, closes unoplatform/quadient-private#2

PR Type:

🐞 Bugfix

What changed? 🚀

On the X11 Skia target under WSLg (Weston/XWayland), a WebView2 was never displayed: the WebKitGTK window ended up held under Weston's XWM frame window instead of being embedded in the app's window.

Two layered fixes:

  • X11XamlRootHost.AttachSubWindow: the code passed an XWindowAttributes buffer to XChangeWindowAttributes, which expects the differently-laid-out XSetWindowAttributes. The override_redirect value actually applied came from whatever bytes sat at offset 88 (map_installed) — 1 for plain default-colormap windows, 0 for GTK windows — so the intended override-redirect was never reliably set. Now a properly-constructed XSetWindowAttributes is passed (this also drops a Marshal.AllocHGlobal and an XGetWindowAttributes round-trip). A best-effort post-reparent check now logs a warning naming the window that kept the native element, instead of failing silently.
  • X11NativeWebView: sets override-redirect on the GTK window right after realization, before it is first mapped, so the WM never starts managing it. This matters because once Weston's XWM manages a toplevel, reparenting it away is not reliably possible (it re-reparents the client under its own window even after XWithdrawWindow); mainstream WMs (mutter/KWin) release the window, which is why this only broke under Weston/WSLg. Additionally, RunOnGtkThread now propagates exceptions from the GTK thread through the TaskCompletionSource instead of leaving the calling thread blocked forever.

The MediaPlayer add-in needs no equivalent change: its X window stays unmapped until AttachNativeElement reparents it (with the now-correct override-redirect) before mapping, so the WM never gets a chance to manage it.

Validation (runtime, WSLg Ubuntu 24.04):

  • Before: xwininfo -root -tree shows the Uno WebView window under the "Weston WM" window (10x10 at origin) → invisible.
  • After: the window is a child of the app window at the arranged size/position; WebView2_Static renders web content, and keyboard input into an HTML <input> inside an embedded override-redirect WebKitGTK window was verified (typed text round-tripped via JavaScript).
  • No behavior change expected on desktop WMs where embedding already worked; not runtime-verified on mutter/KWin in this PR (X11 WM interaction isn't coverable by CI runtime tests — CI runs under Xvfb with no WM).

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable) — not applicable: the bug is X11 window-manager interaction, which cannot be exercised in CI (Xvfb has no WM); validated manually on WSLg with existing WebView samples
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — no user-facing behavior/API change
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

🤖 Generated with Claude Code

ramezgerges and others added 2 commits July 13, 2026 12:52
AttachSubWindow marshalled an XWindowAttributes buffer into
XChangeWindowAttributes, which expects the differently-laid-out
XSetWindowAttributes. The override_redirect value actually applied came
from whatever bytes were at offset 88 (map_installed), so the intended
override-redirect was never reliably set. Without it, Weston's XWM
(WSLg) reparents the WebView2 GTK toplevel into its own frame window
and never lets it go, leaving the webview invisible.

- Pass a properly-constructed XSetWindowAttributes.
- Set override-redirect on the GTK window right after realization,
  before it is first mapped, so the WM never starts managing it
  (once Weston's XWM manages a window, reparenting it away is not
  reliably possible).
- Warn when the reparent doesn't stick instead of failing silently.

Validated at runtime on WSLg (Ubuntu 24.04): WebView2 samples now
render embedded in the app window; previously the webview window was
held under the "Weston WM" window and never displayed.

Co-Authored-By: Claude Fable 5 <[email protected]>
RunOnGtkThread now propagates exceptions from the GTK idle callback
through the TaskCompletionSource instead of leaving the calling thread
blocked forever, and the post-reparent diagnostic checks XQueryTree's
status (avoiding a spurious warning and XFree on garbage when the
window dies mid-attach) and names the window that kept the native
element.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 13, 2026 17:10
@github-actions github-actions Bot added the platform/x11 🐧 Categorizes an issue or PR as relevant to X11 label Jul 13, 2026

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

Fixes X11 Skia WebView2 native window embedding under WSLg/Weston by ensuring the embedded/native subwindows are treated as override-redirect early enough to prevent WM reparenting, and by improving diagnostics/robustness around GTK-thread execution.

Changes:

  • Correctly applies override_redirect via XSetWindowAttributes in X11XamlRootHost.AttachSubWindow and adds a post-reparent diagnostic warning when the WM keeps ownership.
  • Sets OverrideRedirect on the realized GTK window before its first map to prevent Weston's XWM from ever managing the WebKitGTK toplevel.
  • Ensures exceptions thrown on the GTK idle callback complete the waiting TaskCompletionSource instead of leaving callers blocked indefinitely.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Uno.UI.Runtime.Skia.X11/Hosting/X11XamlRootHost.cs Fixes X11 attribute-setting interop and adds a best-effort verification/warning after reparenting native subwindows.
src/AddIns/Uno.UI.WebView.Skia.X11/X11NativeWebView.cs Prevents WM management by setting override-redirect before mapping and propagates GTK-thread exceptions back to callers.

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

Use SetWindowValuemask.OverrideRedirect for XChangeWindowAttributes and
GetAwaiter().GetResult() to rethrow original GTK-thread exceptions.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 13, 2026 17:25

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 222073 has failed on Uno.UI - CI.

Copilot AI review requested due to automatic review settings July 16, 2026 15:58

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings July 16, 2026 16:30

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@unodevops

Copy link
Copy Markdown
Contributor

@ramezgerges

Copy link
Copy Markdown
Contributor Author

CI note: the WebAssembly Skia Runtime Tests 0/1/2 failures are unrelated to this change — the X11 assemblies are not part of the WASM head. The failing tests (When_OuterScrollViewer_BringIntoView_Scrolls_To_Caret, When_Repeater_ChangedView, When_ScrollWheel, When_Add_Remove, When_Accessibility_Is_Enabled_After_Text_Exists_Then_SemanticTyping_Appends_At_Current_Caret) are timing/scroll/caret-sensitive and also fail on master without this change: master build 222601 fails the identical When_OuterScrollViewer_BringIntoView_Scrolls_To_Caret in the same test group. Re-running the failed jobs should clear them.

@ramezgerges
ramezgerges enabled auto-merge July 16, 2026 17:57
@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 222688 has failed on Uno.UI - CI.

@ramezgerges
ramezgerges merged commit 21bf1ad into unoplatform:master Jul 16, 2026
46 checks passed
MartinZikmund added a commit to ramezgerges/uno that referenced this pull request Sep 21, 2026
…#23736, unoplatform#23844

Restores unoplatform#23736 (WSLg's XWM re-detaches subwindows without
override-redirect set via XSetWindowAttributes, plus a
best-effort post-reparent ownership check) and unoplatform#23844 (frame
pacer created before the DPI read that spins up
DisplayInformation; icon decoding offloaded per-icon instead of
racing DisplayInformation creation off the UI thread). unoplatform#23895's
Compositor.IsSoftwareRenderer line was already covered by the
branch's own GraphicsContextKind-based assignment - the
duplicate line from the merge was dropped.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XsQppKuZgijApgJxaTZt81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/x11 🐧 Categorizes an issue or PR as relevant to X11

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebView2 is not displayed on the X11 Skia target under WSLg (Weston/XWayland)

5 participants