Skip to content

Commit 2f536a3

Browse files
authored
Feature: Updated the fallback color for Acrylic (#12625)
1 parent ec5c6e6 commit 2f536a3

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

src/Files.App/Helpers/AppSystemBackdrop.cs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Text;
1010
using System.Threading.Tasks;
11+
using Windows.UI;
1112

1213
namespace Files.App.Helpers
1314
{
@@ -18,6 +19,7 @@ internal sealed class AppSystemBackdrop : SystemBackdrop
1819
private ISystemBackdropControllerWithTargets? controller;
1920
private ICompositionSupportsSystemBackdrop target;
2021
private XamlRoot root;
22+
private SystemBackdropTheme? prevTheme = null;
2123

2224
public AppSystemBackdrop(bool isSecondaryWindow = false)
2325
{
@@ -35,11 +37,23 @@ protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop con
3537
base.OnTargetConnected(connectedTarget, xamlRoot);
3638
this.target = connectedTarget;
3739
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);
4043
controller?.AddSystemBackdropTarget(connectedTarget);
4144
}
4245

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+
4357
protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop disconnectedTarget)
4458
{
4559
base.OnTargetDisconnected(disconnectedTarget);
@@ -60,15 +74,16 @@ private void OnSettingChanged(object? sender, Shared.EventArguments.SettingChang
6074
case nameof(IAppearanceSettingsService.AppThemeBackdropMaterial):
6175
controller?.RemoveAllSystemBackdropTargets();
6276
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);
6580
newController?.AddSystemBackdropTarget(target);
6681
controller = newController;
6782
break;
6883
}
6984
}
7085

71-
private ISystemBackdropControllerWithTargets? GetSystemBackdropController(BackdropMaterialType backdropType)
86+
private ISystemBackdropControllerWithTargets? GetSystemBackdropController(BackdropMaterialType backdropType, SystemBackdropTheme theme)
7287
{
7388
if (isSecondaryWindow && backdropType == BackdropMaterialType.MicaAlt)
7489
backdropType = BackdropMaterialType.Mica;
@@ -88,11 +103,36 @@ private void OnSettingChanged(object? sender, Shared.EventArguments.SettingChang
88103
};
89104

90105
case BackdropMaterialType.Acrylic:
91-
return new DesktopAcrylicController();
106+
var acrylicController = new DesktopAcrylicController();
107+
SetAcrylicBackdropProperties(acrylicController, theme);
108+
return acrylicController;
92109

93110
default:
94111
return null;
95112
}
96113
}
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+
}
97137
}
98138
}

0 commit comments

Comments
 (0)