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: Added support for changing backdrop material #12534

Merged
merged 22 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/FilePropertiesHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan
propertiesWindow.Width = 800;
propertiesWindow.Height = 550;
propertiesWindow.Content = frame;
propertiesWindow.SystemBackdrop = new MicaBackdrop();
propertiesWindow.SystemBackdrop = new AppSystemBackdrop(true);

var appWindow = propertiesWindow.AppWindow;
appWindow.Title = "Properties".GetLocalizedResource();
Expand Down
92 changes: 92 additions & 0 deletions src/Files.App/Helpers/SystemBackdropHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Microsoft.UI.Composition;
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Files.App.Helpers
{
internal sealed class AppSystemBackdrop : SystemBackdrop
{
private bool isSecondaryWindow;
private IUserSettingsService userSettingsService;
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
private ISystemBackdropControllerWithTargets? controller;
private ICompositionSupportsSystemBackdrop target;
private XamlRoot root;

public AppSystemBackdrop(bool isSecondaryWindow = false)
{
this.isSecondaryWindow = isSecondaryWindow;
}

[MemberNotNull(nameof(target), nameof(root))]
protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop connectedTarget, XamlRoot xamlRoot)
{
base.OnTargetConnected(connectedTarget, xamlRoot);
this.target = connectedTarget;
this.root = xamlRoot;
userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
controller = GetSystemBackdropController(userSettingsService.AppearanceSettingsService.AppThemeSystemBackdrop);
controller?.SetSystemBackdropConfiguration(GetDefaultSystemBackdropConfiguration(connectedTarget, xamlRoot));
controller?.AddSystemBackdropTarget(connectedTarget);
userSettingsService.OnSettingChangedEvent += OnSettingChanged;
heftymouse marked this conversation as resolved.
Show resolved Hide resolved
}

protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop disconnectedTarget)
{
base.OnTargetDisconnected(disconnectedTarget);
this.target = null!;
this.root = null!;
controller?.RemoveSystemBackdropTarget(disconnectedTarget);
controller?.Dispose();
userSettingsService.OnSettingChangedEvent -= OnSettingChanged;
}

private void OnSettingChanged(object? sender, Shared.EventArguments.SettingChangedEventArgs e)
{
switch (e.SettingName)
heftymouse marked this conversation as resolved.
Show resolved Hide resolved
{
case nameof(IAppearanceSettingsService.AppThemeSystemBackdrop):
controller?.RemoveAllSystemBackdropTargets();
controller?.Dispose();
var newController = GetSystemBackdropController((SystemBackdropType)e.NewValue!);
newController?.SetSystemBackdropConfiguration(GetDefaultSystemBackdropConfiguration(target, root));
newController?.AddSystemBackdropTarget(target);
controller = newController;
break;
}
}

private ISystemBackdropControllerWithTargets? GetSystemBackdropController(SystemBackdropType backdropType)
{
if (isSecondaryWindow && backdropType == SystemBackdropType.MicaAlt)
backdropType = SystemBackdropType.Mica;

switch (backdropType)
{
case SystemBackdropType.MicaAlt:
return new MicaController()
{
Kind = MicaKind.BaseAlt
};

case SystemBackdropType.Mica:
return new MicaController()
{
Kind = MicaKind.Base
};

case SystemBackdropType.Acrylic:
return new DesktopAcrylicController();

default:
return null;
}
}
}
}
9 changes: 1 addition & 8 deletions src/Files.App/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,4 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:winuiex="using:WinUIEx"
mc:Ignorable="d">

<!-- Mica Alt -->
<winuiex:WindowEx.Backdrop>
<winuiex:MicaSystemBackdrop Kind="BaseAlt" />
</winuiex:WindowEx.Backdrop>

</winuiex:WindowEx>
mc:Ignorable="d" />
6 changes: 6 additions & 0 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.ServicesImplementation.Settings;
using Files.App.UserControls.MultitaskingControl;
using Microsoft.UI;
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Animation;
using Microsoft.UI.Xaml.Navigation;
using System.IO;
Expand Down Expand Up @@ -158,6 +161,9 @@ private Frame EnsureWindowIsInitialized()
// just ensure that the window is active
if (!(App.Window.Content is Frame rootFrame))
{
// Set system backdrop
this.SystemBackdrop = new AppSystemBackdrop();

// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.CacheSize = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Files.Backend.Services.Settings;
using Files.Shared.EventArguments;
using Microsoft.AppCenter.Analytics;
using Microsoft.UI.Composition.SystemBackdrops;
using System;

namespace Files.App.ServicesImplementation.Settings
Expand Down Expand Up @@ -70,6 +71,13 @@ public String AppThemeFontFamily
set => Set(value);
}

/// <inheritdoc/>
public SystemBackdropType AppThemeSystemBackdrop
{
get => Get(MicaController.IsSupported() ? SystemBackdropType.MicaAlt : SystemBackdropType.Solid);
heftymouse marked this conversation as resolved.
Show resolved Hide resolved
set => Set(value);
}

protected override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
{
switch (e.SettingName)
Expand All @@ -79,6 +87,7 @@ protected override void RaiseOnSettingChangedEvent(object sender, SettingChanged
case nameof(AppThemeAddressBarBackgroundColor):
case nameof(AppThemeSidebarBackgroundColor):
case nameof(AppThemeFileAreaBackgroundColor):
case nameof(AppThemeSystemBackdrop):
Analytics.TrackEvent($"Set {e.SettingName} to {e.NewValue}");
break;
}
Expand Down
15 changes: 15 additions & 0 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3341,4 +3341,19 @@
<value>(multiple values)</value>
<comment>Text indicating that multiple selected files have different metadata values.</comment>
</data>
<data name="Acrylic" xml:space="preserve">
<value>Acrylic</value>
</data>
<data name="Mica" xml:space="preserve">
<value>Mica</value>
</data>
<data name="MicaAlt" xml:space="preserve">
<value>Mica Alt</value>
</data>
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
<data name="SettingsAppearanceSystemBackdrop" xml:space="preserve">
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
<value>System Backdrop</value>
heftymouse marked this conversation as resolved.
Show resolved Hide resolved
</data>
<data name="Solid" xml:space="preserve">
<value>Solid</value>
</data>
</root>
30 changes: 30 additions & 0 deletions src/Files.App/ViewModels/Settings/AppearanceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Licensed under the MIT License. See the LICENSE.

using CommunityToolkit.WinUI.Helpers;
using Files.App.ServicesImplementation.Settings;
using Files.Backend.Services;
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Xaml;

namespace Files.App.ViewModels.Settings
Expand All @@ -13,6 +15,7 @@ public class AppearanceViewModel : ObservableObject
private readonly IResourcesService ResourcesService;

public List<string> Themes { get; private set; }
public Dictionary<SystemBackdropType, string> SystemBackdropTypes { get; private set; } = new();

public ObservableCollection<AppThemeResourceItem> AppThemeResources { get; }

Expand All @@ -28,6 +31,19 @@ public AppearanceViewModel(IUserSettingsService userSettingsService, IResourcesS
"DarkTheme".GetLocalizedResource()
};

// TODO: Re-add Solid and regular Mica when theming is revamped
//SystemBackdropTypes.Add(SystemBackdropType.Solid, "Solid".GetLocalizedResource());

if (DesktopAcrylicController.IsSupported())
SystemBackdropTypes.Add(SystemBackdropType.Acrylic, "Acrylic".GetLocalizedResource());

if (MicaController.IsSupported())
{
//SystemBackdropTypes.Add(SystemBackdropType.Mica, "Mica".GetLocalizedResource());
SystemBackdropTypes.Add(SystemBackdropType.MicaAlt, "MicaAlt".GetLocalizedResource());
}
selectedSystemBackdrop = SystemBackdropTypes[UserSettingsService.AppearanceSettingsService.AppThemeSystemBackdrop];

AppThemeResources = AppThemeResourceFactory.AppThemeResources;

UpdateSelectedResource();
Expand Down Expand Up @@ -129,5 +145,19 @@ public string AppThemeBackgroundColor
}
}
}

private string selectedSystemBackdrop;
public string SelectedSystemBackdrop
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
{
get => selectedSystemBackdrop;
set
{
if(SetProperty(ref selectedSystemBackdrop, value))
{
UserSettingsService.AppearanceSettingsService.AppThemeSystemBackdrop = SystemBackdropTypes.First(e => e.Value == value).Key;
}
}
}

}
}
12 changes: 12 additions & 0 deletions src/Files.App/Views/Settings/AppearancePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@
SelectedIndex="{x:Bind ViewModel.SelectedThemeIndex, Mode=TwoWay}" />
</local:SettingsBlockControl>

<!-- System Backdrop -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=SettingsAppearanceSystemBackdrop}" HorizontalAlignment="Stretch">
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
<local:SettingsBlockControl.Icon>
<FontIcon Glyph="&#xEF1F;" />
</local:SettingsBlockControl.Icon>
<ComboBox
x:Name="SystemBackdropChooser"
AutomationProperties.Name="{helpers:ResourceString Name=SettingsAppearanceSystemBackdrop}"
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
ItemsSource="{x:Bind ViewModel.SystemBackdropTypes.Values}"
SelectedItem="{x:Bind ViewModel.SelectedSystemBackdrop, Mode=TwoWay}" />
</local:SettingsBlockControl>

<!-- App Background -->
<local:SettingsBlockControl
Title="{helpers:ResourceString Name=Background}"
Expand Down
10 changes: 10 additions & 0 deletions src/Files.Backend/Enums/SystemBackdropType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Files.Backend.Enums
{
public enum SystemBackdropType
{
Solid,
Mica,
MicaAlt,
Acrylic
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.Backend.Enums;
using System;
using System.ComponentModel;

Expand Down Expand Up @@ -51,5 +52,10 @@ public interface IAppearanceSettingsService : IBaseSettingsService, INotifyPrope
/// Gets or sets a value for the app theme font family.
/// </summary>
String AppThemeFontFamily { get; set; }

/// <summary>
/// Gets or sets a value for the app theme system backdrop.
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
SystemBackdropType AppThemeSystemBackdrop { get; set; }
}
}