Avalonia
Avalonia copied to clipboard
Properly implement Mica backdrop brush
Is your feature request related to a problem? Please describe.
The current Mica
backdrop brush is just created by calling ICompositorWithBlurredWallpaperBackdropBrush.TryCreateBlurredWallpaperBackdropBrush
which just returns the desktop wallpaper blurred, but doesn't apply the proper tint/opacity blends to produce the correct effect, which leads to an incorrect Mica effect
Describe the solution you'd like Create the proper brush with the tint and opacity blends. Properties probably should also be user settable/modifiable, but not immediately required
Default values (tint color, tint opacity, luminosity opacity): Light Theme: { 255, 243, 243, 243 }, 0.5, 1.0 Dark Theme: { 255, 32, 32, 32 }, 0.8, 1.0 High Contrast: falls back to solid tint color
The formula is available in WinUI: https://github.com/microsoft/microsoft-ui-xaml/blob/main/dev/Materials/Backdrop/SystemBackdropBrushFactory.cpp
Describe alternatives you've considered You can try to throw a semi-transparent color at the root of the window matching the tint color, but it doesn't blend right and the effect is lost e.g., https://github.com/amwx/FluentAvalonia/discussions/320
You can not use the built-in APIs and Pinvoke DwmSetWindowAttribute with DWMWA_USEHOSTBACKDROPBRUSH (< win 11 22621) or DWMWA_SYSTEMBACKDROP_TYPE (>= Win 11 22621) which will apply with the correct colors, however, I couldn't get that to work just now so that might be a regression as I'm pretty sure that used to work (WinUI comp was disabled too)
I was just trying the Mica effect here as well and found that its implementation in Avalonia is currently unusable due to the effect not being blended properly per above. Hope it can be fixed soon.
I think it was supposed to be used with ExperimentalAcrylicBorder applied on top of this blur. Won't give you the same result as WinUI though.
I was looking at this last week and ran into some problems. For Mica, we need to add 3 new WinUI effects (ColorSourceEffect, OpacityEffect, and BlendEffect). ColorSourceEffect maps to the D2D1_FLOOD effect which has 1 property, Color, that is a D2D1_VECTOR_4F, but WinRTPropertyValue
didn't have a way to set a Vector4 and I wasn't really sure how to fix that. Opacity effect should be easy, but BlendEffect looks complicated too (but I didn't get this far).
@amwx I had something working for a while in Fluent Search, just created a PR for it - https://github.com/AvaloniaUI/Avalonia/pull/12196
lmk what you think, I think eventually using Avalonia composition will be the most optimal.