Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Updated the fallback color for Acrylic #12625

Merged
merged 3 commits into from
Jun 18, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions src/Files.App/Helpers/AppSystemBackdrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI;

namespace Files.App.Helpers
{
Expand All @@ -18,6 +19,7 @@ internal sealed class AppSystemBackdrop : SystemBackdrop
private ISystemBackdropControllerWithTargets? controller;
private ICompositionSupportsSystemBackdrop target;
private XamlRoot root;
private SystemBackdropTheme? prevTheme = null;

public AppSystemBackdrop(bool isSecondaryWindow = false)
{
Expand All @@ -35,11 +37,23 @@ protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop con
base.OnTargetConnected(connectedTarget, xamlRoot);
this.target = connectedTarget;
this.root = xamlRoot;
controller = GetSystemBackdropController(userSettingsService.AppearanceSettingsService.AppThemeBackdropMaterial);
controller?.SetSystemBackdropConfiguration(GetDefaultSystemBackdropConfiguration(connectedTarget, xamlRoot));
var configuration = GetDefaultSystemBackdropConfiguration(connectedTarget, xamlRoot);
controller = GetSystemBackdropController(userSettingsService.AppearanceSettingsService.AppThemeBackdropMaterial, configuration.Theme);
controller?.SetSystemBackdropConfiguration(configuration);
controller?.AddSystemBackdropTarget(connectedTarget);
}

protected override void OnDefaultSystemBackdropConfigurationChanged(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot)
{
base.OnDefaultSystemBackdropConfigurationChanged(target, xamlRoot);
var configuration = GetDefaultSystemBackdropConfiguration(target, xamlRoot);
if (controller is not DesktopAcrylicController acrylicController || configuration.Theme == prevTheme)
return;

prevTheme = configuration.Theme;
SetAcrylicBackdropProperties(acrylicController, configuration.Theme);
}

protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop disconnectedTarget)
{
base.OnTargetDisconnected(disconnectedTarget);
Expand All @@ -60,15 +74,16 @@ private void OnSettingChanged(object? sender, Shared.EventArguments.SettingChang
case nameof(IAppearanceSettingsService.AppThemeBackdropMaterial):
controller?.RemoveAllSystemBackdropTargets();
controller?.Dispose();
var newController = GetSystemBackdropController((BackdropMaterialType)e.NewValue!);
newController?.SetSystemBackdropConfiguration(GetDefaultSystemBackdropConfiguration(target, root));
var configuration = GetDefaultSystemBackdropConfiguration(target, root);
var newController = GetSystemBackdropController((BackdropMaterialType)e.NewValue!, configuration.Theme);
newController?.SetSystemBackdropConfiguration(configuration);
newController?.AddSystemBackdropTarget(target);
controller = newController;
break;
}
}

private ISystemBackdropControllerWithTargets? GetSystemBackdropController(BackdropMaterialType backdropType)
private ISystemBackdropControllerWithTargets? GetSystemBackdropController(BackdropMaterialType backdropType, SystemBackdropTheme theme)
{
if (isSecondaryWindow && backdropType == BackdropMaterialType.MicaAlt)
backdropType = BackdropMaterialType.Mica;
Expand All @@ -88,11 +103,36 @@ private void OnSettingChanged(object? sender, Shared.EventArguments.SettingChang
};

case BackdropMaterialType.Acrylic:
return new DesktopAcrylicController();
var acrylicController = new DesktopAcrylicController();
SetAcrylicBackdropProperties(acrylicController, theme);
return acrylicController;

default:
return null;
}
}

private void SetAcrylicBackdropProperties(DesktopAcrylicController controller, SystemBackdropTheme theme)
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
{
// need to set all properties to work around a bug where other properties stop updating when fallback color is changed
// this uses the Thin Acrylic recipe from the WinUI Figma toolkit
heftymouse marked this conversation as resolved.
Show resolved Hide resolved

switch(theme)
{
case SystemBackdropTheme.Light:
controller.TintColor = Color.FromArgb(0xff, 0xd3, 0xd3, 0xd3);
controller.TintOpacity = 0f;
controller.LuminosityOpacity = 0.44f;
controller.FallbackColor = Color.FromArgb(0x99, 0xd3, 0xd3, 0xd3);
break;

case SystemBackdropTheme.Dark:
controller.TintColor = Color.FromArgb(0xff, 0x54, 0x54, 0x54);
controller.TintOpacity = 0f;
controller.LuminosityOpacity = 0.64f;
controller.FallbackColor = Color.FromArgb(0xff, 0x20, 0x20, 0x20);
break;
}
}
}
}