Skip to content

fix(titlebar): Make the WinUI TitleBar control work on Skia desktop - #25190

Merged
MartinZikmund merged 10 commits into
masterfrom
dev/mazi/titlebar-skia
Oct 11, 2026
Merged

MartinZikmund merged 10 commits into
masterfrom
dev/mazi/titlebar-skia

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #21714, related #19392, #24878

PR Type:

🐞 Bugfix

What changed? 🚀

The ported WinUI TitleBar control did not work on Skia desktop. On Win32, custom title bar buttons also could not be clicked.

Root causes

  1. TitleBar crashed on XamlRoot.ContentIslandEnvironment. TitleBar.GetAppWindowId() reads XamlRoot.ContentIslandEnvironment.AppWindowId, which was [NotImplemented] on Skia and threw. Effects:
    • OnApplyTemplate aborted before any GoToState, so every lazy template part stayed an ElementStub and only the background rendered.
    • When Content was set, OnContentLayoutUpdated threw inside Win32WindowWrapper.ShowCore, so the window never appeared.
  2. The control's other window dependencies were also unimplemented on Skia:
    • InputActivationListener.GetForWindowId (used on Loaded)
    • AppWindowTitleBar.LeftInset/RightInset (used by UpdatePadding)
  3. Win32 hit-testing was order dependent. Win32WindowWrapper.NonClientAreaHitTest returned the first region in Dictionary order. SetTitleBar registers the whole title bar as a Caption region before TitleBar adds its Passthrough holes, so Caption won and clicks on title bar buttons started a window drag. WinUI's design depends on Passthrough taking precedence: CWindowChrome::SetDragRegion registers the full element as Caption, and TitleBar::UpdateDragRegion adds Passthrough rects on top of it.

Fixes

  • XamlRoot.ContentIslandEnvironment now returns a ContentIslandEnvironment whose AppWindowId is the host window's AppWindow.Id, or null when there is no host window. This mirrors XamlRoot::get_ContentIslandEnvironmentImpl, which returns the content root's environment.
    • Trade-off: Uno has no per-content-root ContentIsland, so the environment is derived from the host window. DisplayId, DisplayScale and the events remain [NotImplemented].
  • InputActivationListener: GetForWindowId, State and InputActivationChanged are implemented and fed from window activation. The listener is cleared on ALC window close, alongside the other per-WindowId registries.
  • AppWindowTitleBar.LeftInset/RightInset are now real. WindowChrome reports the caption-button container width in physical pixels; LeftInset stays 0 because Uno draws the caption buttons on the right.
    • The caption buttons are XAML on Skia, so the insets are only known after chrome layout. TitleBar subscribes to an internal inset-changed event, which implements WinUI's own TODO 50724421: Bind to appTitleBar Left and Right inset changed event.
  • Win32 non-client hit-testing now uses a fixed precedence: Passthrough, then caption buttons, Icon, borders, and Caption last.

WinUI parity note

WinUI's TitleBar::UpdatePadding passes the physical-pixel RightInset directly to GridLengthHelper::FromPixels. The right padding column is therefore RightInset DIPs wide, which is wider than the caption buttons at scales above 100%.

A WinUI 2.5.1 app at 250% reports RightInset = 345, and its RightHeader ends 393 DIP from the right edge. Uno now reports the same RightInset = 345 and lays out the same way, so this port keeps WinUI's behaviour instead of "fixing" it.

Validation

  • New runtime tests (Skia Win32):
    • Given_TitleBar: template parts realized; back and pane toggle raise their events; interactive content is registered as Passthrough; RightHeader avoids the caption buttons.
    • Given_InputNonClientPointerSource: a real WM_NCHITTEST sent to the HWND returns HTCLIENT inside a Passthrough hole and HTCAPTION outside it.
    • Given_InputActivationListener, and Given_XamlRoot.When_Loaded_ContentIslandEnvironment_Matches_AppWindow.
    • All 7 pass with the fix. With the fixes stashed, all 6 that existed at that point fail: NotImplementedException, or HTCAPTION returned where HTCLIENT was expected. The inset test was added afterwards.
  • Regression run of the Microsoft_UI_Windowing, Microsoft_UI_Input, Given_Window, Given_XamlRoot and Given_TitleBar classes: 32 passed. 3 Given_Window theme tests fail, and they fail identically on unmodified master on the same machine (the OS is in dark mode).
  • Real app: a Skia Win32 app at 250% scale using Window.ExtendsContentIntoTitleBar and SetTitleBar(titleBar), with a TitleBar containing IconSource, Title, Subtitle, back and pane toggle buttons, an AutoSuggestBox as Content and a button plus PersonPicture RightHeader. Everything was driven with real mouse input through UIA tooling:
    • All parts render, and the window shows without exceptions.
    • The pane toggle collapses and expands the NavigationView pane, so PaneToggleRequested fires.
    • Back navigates back, so BackRequested fires.
    • The RightHeader button navigates.
    • The AutoSuggestBox takes typing and shows suggestions.
    • Dragging an empty title bar area moves the window by the drag delta.
    • Dragging on the search box does not move the window.
    • The RightHeader no longer overlaps the min/max/close buttons.

Not covered

  • X11: ExtendsContentIntoTitleBar removes decorations, but there is no native INativeInputNonClientPointerSource, so title bars are not draggable there. The TitleBar control itself no longer throws on X11 (the fixes are platform-agnostic), but this was not runtime-verified on Linux.
  • macOS: not verified.
  • RTL caption-button placement (LeftInset) is not modelled.

PR Checklist ✅

  • 🧪 Added Runtime tests
  • 📚 Docs have been added/updated
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests

🤖 Generated with Claude Code

https://claude.ai/code/session_013yZfe9CjkLZqGRwjwfXyQ7

MartinZikmund and others added 4 commits October 10, 2026 21:04
Region rects were hit-tested in Dictionary order, so a Caption rect
registered before an overlapping Passthrough rect (as SetTitleBar +
TitleBar do) won and title bar buttons started a window drag. Hit-test
in a fixed order with Passthrough first, as WinUI does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013yZfe9CjkLZqGRwjwfXyQ7
TitleBar resolves its window through XamlRoot.ContentIslandEnvironment,
which threw NotImplementedException on Skia, aborting OnApplyTemplate
(only the background rendered) and crashing window show when Content was
set. Implement the APIs it depends on:

- XamlRoot.ContentIslandEnvironment / ContentIslandEnvironment.AppWindowId,
  derived from the host window
- InputActivationListener (GetForWindowId, State, InputActivationChanged),
  fed from window activation
- AppWindowTitleBar.LeftInset/RightInset, reported by WindowChrome from
  its caption buttons; TitleBar refreshes its padding when they change
  (WinUI's TODO 50724421), as they are only known after chrome layout

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013yZfe9CjkLZqGRwjwfXyQ7
@github-actions

Copy link
Copy Markdown
Contributor

WinAppSDK sync generator drift detected on 6ae3341

The Uno.WinAppSDKSyncGenerator produced changes that are not committed on this PR.

To apply automatically (PRs from branches in this repo only): comment /apply-sync-gen on this PR and a bot will push chore: Sync generator run to the head branch.

To apply manually (required for PRs from forks):

  1. Download the sync-generator-patch artifact from this run.
  2. In your local checkout of the PR branch:
    git apply sync-generator.patch
    git add -A
    git commit -m "chore: Sync generator run"
    git push
    

Or re-run the generator locally on Windows via build\run-api-sync-tool.cmd.

MartinZikmund and others added 2 commits October 10, 2026 22:10
Creating and closing a secondary Window fail-fasts the WinAppSDK runtime
test app; match the existing Given_AppWindow secondary-window tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013yZfe9CjkLZqGRwjwfXyQ7
@MartinZikmund MartinZikmund added the 7.0 PRs only. For issues, use the Release field. label Oct 11, 2026
@MartinZikmund
MartinZikmund marked this pull request as ready for review October 11, 2026 07:43
Copilot AI balanced review requested due to automatic review settings October 11, 2026 07:43

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 26s —— View job


Review of #25190: TitleBar on Skia desktop

Verdict: ship. I found nothing blocking. I read the diff by inspection only. I did not build the code or run the tests.

Issues by severity: 0 blocking, 0 major, 2 minor/nit. I posted no inline comments.

What I checked

  • Root-cause-first: The PR addresses the causes, not the symptoms. It implements ContentIslandEnvironment, InputActivationListener and the insets instead of guarding against the NotImplementedException. The hit-test change fixes the order dependence at its source. It uses a fixed precedence list in place of Dictionary enumeration order.
  • Generated folders: The Generated/ edits are only the sync-generator output that drops the [NotImplemented] stubs, and the PR adds hand-written implementations outside Generated/. This matches the repo workflow for implementing new WinUI features.
  • Events and style: InsetsChanged is an EventHandler, and the new code uses braces and tabs. The commits follow Conventional Commits.
  • Tests: The runtime tests cover each fix, including a real WM_NCHITTEST check, and the PR reports the fails-before/passes-after result. I did not see any skipped or ignored tests.

Minor / nits (optional)

  1. InputActivationListener.SetStateForWindowId uses GetOrAdd. If an activation callback arrives after DestroyForWindowId on window close, it would re-create an entry that is never removed. This is an unlikely race and the entry is tiny. A TryGetValue-only path for the activation-feed side would avoid the leak. GetForWindowId would keep GetOrAdd, but then the state set before the first GetForWindowId call would be lost, so the current behavior is arguably right.
  2. XamlRoot.ContentIslandEnvironment caches _contentIslandEnvironment without synchronization. This is fine on the UI thread, but a short comment saying it is UI-thread-only would help.

Cross-cutting notes

  • The documented trade-offs are reasonable: no per-root ContentIsland, no RTL LeftInset, and X11 and macOS unverified. The parity note about RightInset being passed as DIPs matches WinUI.
  • The checklist leaves "Screenshots Compare Test Run" unchecked. The latest CI run (238835) failed on Uno.UI - CI, and the screenshot diffs, about 2458 on Windows and 118 on Linux, look broad. Please confirm they come from master or infrastructure drift and not from this PR. A change this narrow should not alter that many samples.
  • The "Docs have been added/updated" box is also unchecked. That is probably fine for a bugfix.

MartinZikmund and others added 4 commits October 11, 2026 18:54
UpdatePadding moves the TitleBar's interactive parts without resizing it,
and resizing is what refreshes the Passthrough and Icon regions. After an
inset or FlowDirection change the regions stayed where the parts used to
be, so clicks on the back button or headers could start a window drag.
Refresh them after the next layout pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GetScreenRect transformed only the element's origin, which under
RightToLeft is its right edge, so the SetTitleBar Caption rect (and the
caption button rects) landed past the element, even outside the window.
Use TransformBounds instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 11, 2026 16:57

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 27s —— View job


Review of #25190: TitleBar on Skia desktop

Verdict: ship. I read the diff by inspection only. I did not build the code or run the tests.

Issues by severity: 0 blocking, 0 major, 2 minor/nit. Both are posted as inline comments.

Cross-cutting notes

  • Root-cause-first: The fixes address the causes rather than guarding against the exception. ContentIslandEnvironment, InputActivationListener and the insets are implemented, and Win32 hit-testing uses a fixed precedence order instead of Dictionary order.
  • Style and events: InsetsChanged is an EventHandler. The commits follow Conventional Commits. The Generated/ edits are only the sync-generator output that drops the [NotImplemented] stubs, and the implementations live outside Generated/.
  • Sync-generator drift: A CI comment reports drift from the sync generator. Please comment /apply-sync-gen on this PR, or apply the patch manually. If drift remains it will keep the CI check red.
  • Screenshot diffs: Builds 238816, 238835 and 238903 report about 2458 changed screenshots on Windows and 118 on Linux, and the Uno.UI - CI stage failed. A change this narrow should not alter that many samples, so this looks like baseline or infrastructure drift. Please confirm that against a recent master build before merging. The "Screenshots Compare Test Run" box is still unchecked.
  • XamlRoot.ContentIslandEnvironment: The cached _contentIslandEnvironment is not synchronized. That is fine on the UI thread, but a short comment saying so would help.
  • Docs: The docs box is unchecked, which is probably fine for a bugfix.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 238919 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • DisplayInformation.png-dark
    • DynamicFont.png-dark
    • DynamicFont.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DropDownButtonPage.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Examples.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
  • skia-windows-screenshots: 2458 changed over 2486

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png
    • AnimatedVisualsTestbedPage.png-dark
    • ApplicationViewSizing.png-dark
    • AppWindowFeatures.png
    • AppXamlDefinedResources.png
    • Attributed_text_Supserscript.png
    • AutoBorderStretchwithleftmargin.png
    • AutomationProperties_Landmark.png
    • AutoSizedPathCentered.png-dark
    • AutoSizedPathCentered.png
    • AutoSuggestBox_Reason.png-dark
    • AutoSuggestBox_Reason.png
    • Basics Pivot Test.png-dark
    • Basics Pivot Test.png
    • Battery.png-dark
    • Battery.png
    • BezierSegment.png-dark
    • BezierSegment.png
    • BitmapIcon_Sizing.png-dark
    • BitmapIcon_Sizing.png

@unodevops

Copy link
Copy Markdown
Contributor

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

@unoplatform unoplatform deleted a comment from unodevops Oct 11, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 11, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Oct 11, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Oct 11, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Oct 11, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 11, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 11, 2026
@unoplatform unoplatform deleted a comment from unodevops Oct 11, 2026
@MartinZikmund
MartinZikmund merged commit faf529b into master Oct 11, 2026
49 of 51 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/titlebar-skia branch October 11, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.0 PRs only. For issues, use the Release field.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WinUI TitleBar

4 participants