Skip to content

fix(x11): Stable pointer ids under a WM + DisplayInformation init race - #23844

Merged
ramezgerges merged 3 commits into
unoplatform:masterfrom
ramezgerges:fix/x11-pointer-id-master-device
Jul 29, 2026
Merged

ramezgerges merged 3 commits into
unoplatform:masterfrom
ramezgerges:fix/x11-pointer-id-master-device

Conversation

@ramezgerges

Copy link
Copy Markdown
Contributor

GitHub Issue: #23159 (fixes the "can't click anything in the left-hand tree" regression; the WebView rendering problems tracked in that issue are separate and remain open)

PR Type:

🐞 Bugfix

What changed? 🚀

1. NavigationView items didn't expand/navigate on click on Linux under a window manager (fix(x11): Use master device id for mouse pointer id)

The X11 host derived PointerId from the XI2 sourceid. Under a WM (reproduced with mutter; does not reproduce on bare Xvfb), crossing events generated by the WM — map-under-pointer XI_Enter, grab activation/deactivation XI_Leave/XI_Enter — arrive with sourceid = the master pointer, while button/motion events carry sourceid = the slave device. One physical cursor therefore produced two different pointer ids.

NavigationViewItem tracks a single pointer id (m_trackedPointerId, ported WinUI logic) and early-returns on id mismatch in every handler — including PointerExited, the only place the tracked id is reset. Once an item saw a master-sourced crossing, it ignored every subsequent real pointer event, permanently. Controls without per-pointer-id tracking (ButtonBase: chevron, CheckBox, ToggleSwitch) kept working, as did keyboard invoke, which is why this presented as "NavigationView expansion is broken" (Uno.Gallery left nav, SamplesApp NavigationView_Pane_Automated).

Fix: derive the mouse pointer id from deviceid (the master device — the X11 "one cursor" concept, matching the master-delivered event copies the handler already keeps). Touch ids are unchanged (detail).

Instrumented capture of a poisoned click (Uno.Gallery 6.7.0-dev.815 artifact under Xvfb + mutter), before the fix:

XI_Enter  dev=2 src=2                       ← WM crossing at map, phantom pointer 2
'Theming' IgnorePointerId: tracking pointer 2
XI_ButtonPress dev=2 src=4                  ← real click is pointer 4
'Theming' PRESS id=4 → IGNORING pointer 4   (tracked=2)
'Theming' RELEASE id=4 → IGNORING pointer 4 → invoke never fires

After the fix, the same scenario invokes and expands correctly (validated at runtime by swapping the rebuilt assemblies into the same Gallery artifact under the same Xvfb + mutter setup).

2. Startup crash X11DisplayInformationExtension is set twice (fix(x11): Keep DisplayInformation init off the thread pool)

SetWindowIcon ran inside Task.Run and resolved the scaled icon path via BitmapImage.GetScaledPath, which reads DisplayInformation. On cold starts the task could win the race against the rest of the X11XamlRootHost constructor:

  1. GetForCurrentView() created the window's DisplayInformation; its X11DisplayInformationExtension registered itself on the host, then UpdateDetails() reported the XRandR refresh rate via UpdateRenderTimerFps, which dereferenced the not-yet-assigned _framePacer → NullReferenceException.
  2. The NRE unwound through the DisplayInformation constructor, so GetOrCreateForWindowId never cached the instance — but the host kept the half-initialized extension. Task.Run swallowed the exception, so nothing was logged.
  3. The subsequent legitimate DisplayInformation creation from X11WindowWrapper..ctor then hit InvalidOperationException: X11DisplayInformationExtension is set twice → unhandled → app aborts at startup.

Fix: resolve the icon path on the UI thread (only the PNG decode and the _NET_WM_ICON X11 calls — which take XLock — are offloaded, and their failures are now logged instead of swallowed), and create the frame pacer before UpdateWindowPropertiesFromPackage() so reporting the refresh rate during DPI initialization can't NRE.

Validation: making the call synchronous surfaced the previously-swallowed NRE deterministically at the exact call site; with the frame-pacer reorder the app starts cleanly, the extension is created once on the UI thread, and window-icon behavior is unchanged.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable) — not practical to automate: both bugs require a real window manager delivering grab/crossing events (reproduced with Xvfb + mutter --x11); bare Xvfb (as used by CI) does not reproduce. Manual repro steps documented above.
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features)
  • 🖼️ 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 22, 2026 14:22
WM-generated crossing events (map-under-pointer, grab activation)
carry sourceid = master while regular events carry sourceid = slave,
so keying PointerId on sourceid splits one cursor into two pointer
ids. Controls tracking a single pointer id (e.g. NavigationViewItem)
then ignore all real pointer events for the poisoned element, which
broke NavigationView expand/collapse on Linux under a window manager.

Co-Authored-By: Claude Fable 5 <[email protected]>
SetWindowIcon ran in Task.Run and resolved the scaled icon path via
BitmapImage.GetScaledPath, which reads DisplayInformation. On cold
starts this created the window's DisplayInformation concurrently with
window init; its extension registered on the host, then UpdateDetails
hit a NullReferenceException in UpdateRenderTimerFps (frame pacer not
created yet), the exception was swallowed by Task.Run, and the next
DisplayInformation creation crashed the app with
"X11DisplayInformationExtension is set twice".

Resolve the icon path on the UI thread and offload only the decode and
X11 property calls, logging their failures. Create the frame pacer
before UpdateWindowPropertiesFromPackage since reading the DPI reports
the refresh rate through UpdateRenderTimerFps.

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

This PR fixes two X11/Skia Linux regressions in Uno.UI.Runtime.Skia.X11: (1) inconsistent pointer IDs under some window managers that broke NavigationViewItem pointer tracking, and (2) a startup race where DisplayInformation could be initialized from a thread-pool task during window icon setup, leading to crashes and “extension set twice” failures.

Changes:

  • Create mouse PointerId from the XI2 deviceid (while keeping touch IDs based on detail) to avoid WM-induced master/slave ID mismatches.
  • Reorder X11 host initialization so the frame pacer exists before DisplayInformation can report refresh rate via UpdateRenderTimerFps.
  • Keep icon path resolution on the UI thread and offload only decoding/X11 property setting, with error logging for failures during the offloaded work.

Reviewed changes

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

File Description
src/Uno.UI.Runtime.Skia.X11/Hosting/X11XamlRootHost.cs Reorders frame pacer creation and adjusts window icon initialization to avoid DisplayInformation thread-pool races.
src/Uno.UI.Runtime.Skia.X11/Devices/Input/X11PointerInputSource.XInput.cs Uses a stable XI2 identifier for mouse pointer IDs to prevent per-cursor pointer ID splitting under WMs.

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

Clarify why deviceid is the master pointer id given the
deviceid == sourceid filtering, and honor the pointerType parameter
in CreatePointerEventArgsFromEnterLeaveEvent instead of hard-coding
Mouse.

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

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 223688 has failed on Uno.UI - CI.

@ramezgerges
ramezgerges merged commit 488ab47 into unoplatform:master Jul 29, 2026
47 checks passed
@ramezgerges
ramezgerges deleted the fix/x11-pointer-id-master-device branch July 29, 2026 14:01
@mergify

mergify Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

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.

4 participants