8
8
using System . Linq ;
9
9
using System . Text ;
10
10
using System . Threading . Tasks ;
11
+ using Windows . UI ;
11
12
12
13
namespace Files . App . Helpers
13
14
{
@@ -18,6 +19,7 @@ internal sealed class AppSystemBackdrop : SystemBackdrop
18
19
private ISystemBackdropControllerWithTargets ? controller ;
19
20
private ICompositionSupportsSystemBackdrop target ;
20
21
private XamlRoot root ;
22
+ private SystemBackdropTheme ? prevTheme = null ;
21
23
22
24
public AppSystemBackdrop ( bool isSecondaryWindow = false )
23
25
{
@@ -35,11 +37,23 @@ protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop con
35
37
base . OnTargetConnected ( connectedTarget , xamlRoot ) ;
36
38
this . target = connectedTarget ;
37
39
this . root = xamlRoot ;
38
- controller = GetSystemBackdropController ( userSettingsService . AppearanceSettingsService . AppThemeBackdropMaterial ) ;
39
- controller ? . SetSystemBackdropConfiguration ( GetDefaultSystemBackdropConfiguration ( connectedTarget , xamlRoot ) ) ;
40
+ var configuration = GetDefaultSystemBackdropConfiguration ( connectedTarget , xamlRoot ) ;
41
+ controller = GetSystemBackdropController ( userSettingsService . AppearanceSettingsService . AppThemeBackdropMaterial , configuration . Theme ) ;
42
+ controller ? . SetSystemBackdropConfiguration ( configuration ) ;
40
43
controller ? . AddSystemBackdropTarget ( connectedTarget ) ;
41
44
}
42
45
46
+ protected override void OnDefaultSystemBackdropConfigurationChanged ( ICompositionSupportsSystemBackdrop target , XamlRoot xamlRoot )
47
+ {
48
+ base . OnDefaultSystemBackdropConfigurationChanged ( target , xamlRoot ) ;
49
+ var configuration = GetDefaultSystemBackdropConfiguration ( target , xamlRoot ) ;
50
+ if ( controller is not DesktopAcrylicController acrylicController || configuration . Theme == prevTheme )
51
+ return ;
52
+
53
+ prevTheme = configuration . Theme ;
54
+ SetAcrylicBackdropProperties ( acrylicController , configuration . Theme ) ;
55
+ }
56
+
43
57
protected override void OnTargetDisconnected ( ICompositionSupportsSystemBackdrop disconnectedTarget )
44
58
{
45
59
base . OnTargetDisconnected ( disconnectedTarget ) ;
@@ -60,15 +74,16 @@ private void OnSettingChanged(object? sender, Shared.EventArguments.SettingChang
60
74
case nameof ( IAppearanceSettingsService . AppThemeBackdropMaterial ) :
61
75
controller ? . RemoveAllSystemBackdropTargets ( ) ;
62
76
controller ? . Dispose ( ) ;
63
- var newController = GetSystemBackdropController ( ( BackdropMaterialType ) e . NewValue ! ) ;
64
- newController ? . SetSystemBackdropConfiguration ( GetDefaultSystemBackdropConfiguration ( target , root ) ) ;
77
+ var configuration = GetDefaultSystemBackdropConfiguration ( target , root ) ;
78
+ var newController = GetSystemBackdropController ( ( BackdropMaterialType ) e . NewValue ! , configuration . Theme ) ;
79
+ newController ? . SetSystemBackdropConfiguration ( configuration ) ;
65
80
newController ? . AddSystemBackdropTarget ( target ) ;
66
81
controller = newController ;
67
82
break ;
68
83
}
69
84
}
70
85
71
- private ISystemBackdropControllerWithTargets ? GetSystemBackdropController ( BackdropMaterialType backdropType )
86
+ private ISystemBackdropControllerWithTargets ? GetSystemBackdropController ( BackdropMaterialType backdropType , SystemBackdropTheme theme )
72
87
{
73
88
if ( isSecondaryWindow && backdropType == BackdropMaterialType . MicaAlt )
74
89
backdropType = BackdropMaterialType . Mica ;
@@ -88,11 +103,36 @@ private void OnSettingChanged(object? sender, Shared.EventArguments.SettingChang
88
103
} ;
89
104
90
105
case BackdropMaterialType . Acrylic :
91
- return new DesktopAcrylicController ( ) ;
106
+ var acrylicController = new DesktopAcrylicController ( ) ;
107
+ SetAcrylicBackdropProperties ( acrylicController , theme ) ;
108
+ return acrylicController ;
92
109
93
110
default :
94
111
return null ;
95
112
}
96
113
}
114
+
115
+ private void SetAcrylicBackdropProperties ( DesktopAcrylicController controller , SystemBackdropTheme theme )
116
+ {
117
+ // This sets all properties to work around a bug where other properties stop updating when fallback color is changed
118
+ // This uses the Thin Acrylic recipe from the WinUI Figma toolkit
119
+
120
+ switch ( theme )
121
+ {
122
+ case SystemBackdropTheme . Light :
123
+ controller . TintColor = Color . FromArgb ( 0xff , 0xd3 , 0xd3 , 0xd3 ) ;
124
+ controller . TintOpacity = 0f ;
125
+ controller . LuminosityOpacity = 0.44f ;
126
+ controller . FallbackColor = Color . FromArgb ( 0x99 , 0xd3 , 0xd3 , 0xd3 ) ;
127
+ break ;
128
+
129
+ case SystemBackdropTheme . Dark :
130
+ controller . TintColor = Color . FromArgb ( 0xff , 0x54 , 0x54 , 0x54 ) ;
131
+ controller . TintOpacity = 0f ;
132
+ controller . LuminosityOpacity = 0.64f ;
133
+ controller . FallbackColor = Color . FromArgb ( 0xff , 0x20 , 0x20 , 0x20 ) ;
134
+ break ;
135
+ }
136
+ }
97
137
}
98
138
}
0 commit comments