55using Avalonia . Controls . Primitives ;
66using Avalonia . Media ;
77using Avalonia . Platform ;
8+ using UniGetUI . Avalonia . Assets . Styles ;
89
910namespace UniGetUI . Avalonia . Infrastructure ;
1011
@@ -24,6 +25,7 @@ internal static class MicaWindowHelper
2425 private const int DWMSBT_TRANSIENTWINDOW = 3 ; // Acrylic — for transient surfaces (menus/flyouts); Mica won't paint on these
2526
2627 private static bool _acrylicPopupsHooked ;
28+ private static bool _micaConfirmedUnavailable ;
2729
2830 public static void Apply ( Window window )
2931 {
@@ -71,6 +73,9 @@ public static void EnableAcrylicPopups()
7173
7274 private static void ApplyAcrylicToPopup ( TopLevel root )
7375 {
76+ if ( ! IsMicaEnabled ( ) )
77+ return ;
78+
7479 // Request acrylic (not Transparent): the Transparent level makes a layered window, and DWM
7580 // system backdrops never paint on those — so the popup ended up fully see-through with only
7681 // the presenter tint, unreadable when shown over the desktop (e.g. the tray menu). AcrylicBlur
@@ -89,15 +94,37 @@ private static void ApplyAcrylicToPopup(TopLevel root)
8994 }
9095
9196 /// <summary>
92- /// True when the native Mica look should be used: Windows 11+ AND the user has
93- /// "Transparency effects" enabled. When transparency is off we keep the solid look ,
94- /// since the Mica backdrop otherwise lingers (DWM keeps painting it) .
97+ /// True when the native Mica look should be used: Windows 11+, "Transparency effects" on,
98+ /// GPU-accelerated (software rendering can't be transparent, so Mica shows as black — #5111) ,
99+ /// and no window has since found the backdrop didn't engage. Otherwise keep the solid look .
95100 /// </summary>
96101 public static bool IsMicaEnabled ( )
97102 => OperatingSystem . IsWindows ( )
98103 && Environment . OSVersion . Version . Build >= 22000
104+ && ! _micaConfirmedUnavailable
105+ && ! WindowsAvaloniaRenderingPolicy . ShouldUseSoftwareRendering
99106 && IsOsTransparencyEnabled ( ) ;
100107
108+ /// <summary>
109+ /// Latch Mica off for the session and drop the translucent surface overrides so every surface
110+ /// falls back to the solid look, once a window confirms the backdrop never engaged (#5111).
111+ /// </summary>
112+ public static void NotifyMicaUnavailable ( )
113+ {
114+ if ( _micaConfirmedUnavailable )
115+ return ;
116+ _micaConfirmedUnavailable = true ;
117+
118+ if ( Application . Current is { } app )
119+ {
120+ for ( int i = app . Resources . MergedDictionaries . Count - 1 ; i >= 0 ; i -- )
121+ {
122+ if ( app . Resources . MergedDictionaries [ i ] is WindowsMicaStyles )
123+ app . Resources . MergedDictionaries . RemoveAt ( i ) ;
124+ }
125+ }
126+ }
127+
101128 private static bool IsOsTransparencyEnabled ( )
102129 {
103130 if ( ! OperatingSystem . IsWindows ( ) )
0 commit comments