Skip to content

More changes for non-toplevel visual tree roots.#20732

Merged
MrJul merged 15 commits intomasterfrom
refactor/introduce-visual-tree-host
Feb 25, 2026
Merged

More changes for non-toplevel visual tree roots.#20732
MrJul merged 15 commits intomasterfrom
refactor/introduce-visual-tree-host

Conversation

@kekekeks
Copy link
Member

This PR:

  1. makes parts of VisualLayerManager and relevant layers to be internal, since we are planning to migrate those outside of TopLevel's subtree later
  2. introduces a stub visual as the actual visual tree root, to make sure that nobody is assuming the root to be a TopLevel. To get a TopLevel one needs to call TopLevel.GetTopLevel(visual).

This is a part of our work for unlocking CSDs for Wayland and making Window class accessible on mobile/wasm/embedded platforms.

Copy link
Contributor

Copilot AI left a comment

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 introduces significant architectural changes to the Avalonia visual tree structure by adding TopLevelHost as the actual visual root instead of TopLevel. This is preparatory work for enabling Client-Side Decorations (CSDs) for Wayland and making the Window class accessible on mobile/wasm/embedded platforms.

Changes:

  • Introduces TopLevelHost as a stub visual root wrapping TopLevel, establishing that TopLevel is no longer the visual tree root
  • Makes layer-related classes and interfaces internal (VisualLayerManager, AdornerLayer, OverlayLayer, LightDismissOverlayLayer, IPopupHost, IPopupHostProvider, IHostedVisualTreeRoot)
  • Adds FocusRoot property to IInputRoot to separate focus management from visual tree root concepts

Reviewed changes

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

Show a summary per file
File Description
src/Avalonia.Controls/TopLevelHost.cs New internal stub class that serves as the visual tree root, containing TopLevel as a child
src/Avalonia.Controls/TopLevel.cs Creates TopLevelHost and updates PresentationSource initialization with separate visual and focus roots
src/Avalonia.Controls/PresentationSource/PresentationSource.cs Accepts separate rootVisual and defaultFocusVisual parameters to support the new architecture
src/Avalonia.Controls/PresentationSource/PresentationSource.Input.cs Adds FocusRoot property to support focus management
src/Avalonia.Base/Input/IInputRoot.cs Adds FocusRoot property with documentation explaining it as a temporary hack for default focus
src/Avalonia.Base/Input/KeyboardDevice.cs Uses FocusRoot instead of RootElement for keyboard event routing
src/Avalonia.Base/Input/FocusManager.cs Updates focus root resolution to use PresentationSource.InputRoot.FocusRoot
src/Avalonia.Controls/ToolTipService.cs Updates tooltip event root comparison to work with new visual tree structure
src/Avalonia.Controls/Primitives/* Makes layer classes and properties internal (VisualLayerManager, AdornerLayer, OverlayLayer, etc.)
src/Avalonia.X11/X11Window.cs Updates storage provider initialization to use FocusRoot instead of RootElement
tests/* Updates tests to expect TopLevelHost in visual tree, fixes test expectations, adds FocusRoot to test implementations
api/Avalonia.nupkg.xml Adds API compatibility suppressions for breaking changes (internal visibility changes)

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

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0062446-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0062452-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0062462-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0062472-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0062529-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0062535-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul enabled auto-merge February 25, 2026 17:12
Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

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

LGTM!

@MrJul MrJul added this pull request to the merge queue Feb 25, 2026
Merged via the queue into master with commit 2c44533 Feb 25, 2026
11 checks passed
@MrJul MrJul deleted the refactor/introduce-visual-tree-host branch February 25, 2026 19:17
Numpsy added a commit to Numpsy/Avalonia.FuncUI that referenced this pull request Mar 8, 2026
Main changes are from
AvaloniaUI/Avalonia#20732
AvaloniaUI/Avalonia#20767

Where a number of previously public things were made internal.
@freddiesmartbox
Copy link

freddiesmartbox commented Mar 11, 2026

Looks like this may have created a cycle in the new dev tools; haven't create an issue as I'm not sure where best to report this sort of thing for the new tooling (does it come under https://github.com/AvaloniaUI/Accelerate/issues ?). Screenshot is from the sandbox on master

image

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants