-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added support for changing backdrop material (#12534)
- Loading branch information
1 parent
f1815df
commit 155f40b
Showing
11 changed files
with
211 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
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; | ||
private ISystemBackdropControllerWithTargets? controller; | ||
private ICompositionSupportsSystemBackdrop target; | ||
private XamlRoot root; | ||
|
||
public AppSystemBackdrop(bool isSecondaryWindow = false) | ||
{ | ||
this.isSecondaryWindow = isSecondaryWindow; | ||
userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>(); | ||
userSettingsService.OnSettingChangedEvent += OnSettingChanged; | ||
} | ||
|
||
[MemberNotNull(nameof(target), nameof(root))] | ||
protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop connectedTarget, XamlRoot xamlRoot) | ||
{ | ||
if (target is not null) | ||
throw new InvalidOperationException("AppSystemBackdrop cannot be used with more than one target"); | ||
|
||
base.OnTargetConnected(connectedTarget, xamlRoot); | ||
this.target = connectedTarget; | ||
this.root = xamlRoot; | ||
controller = GetSystemBackdropController(userSettingsService.AppearanceSettingsService.AppThemeBackdropMaterial); | ||
controller?.SetSystemBackdropConfiguration(GetDefaultSystemBackdropConfiguration(connectedTarget, xamlRoot)); | ||
controller?.AddSystemBackdropTarget(connectedTarget); | ||
} | ||
|
||
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) | ||
{ | ||
if (target is null) | ||
return; | ||
|
||
switch (e.SettingName) | ||
{ | ||
case nameof(IAppearanceSettingsService.AppThemeBackdropMaterial): | ||
controller?.RemoveAllSystemBackdropTargets(); | ||
controller?.Dispose(); | ||
var newController = GetSystemBackdropController((BackdropMaterialType)e.NewValue!); | ||
newController?.SetSystemBackdropConfiguration(GetDefaultSystemBackdropConfiguration(target, root)); | ||
newController?.AddSystemBackdropTarget(target); | ||
controller = newController; | ||
break; | ||
} | ||
} | ||
|
||
private ISystemBackdropControllerWithTargets? GetSystemBackdropController(BackdropMaterialType backdropType) | ||
{ | ||
if (isSecondaryWindow && backdropType == BackdropMaterialType.MicaAlt) | ||
backdropType = BackdropMaterialType.Mica; | ||
|
||
switch (backdropType) | ||
{ | ||
case BackdropMaterialType.MicaAlt: | ||
return new MicaController() | ||
{ | ||
Kind = MicaKind.BaseAlt | ||
}; | ||
|
||
case BackdropMaterialType.Mica: | ||
return new MicaController() | ||
{ | ||
Kind = MicaKind.Base | ||
}; | ||
|
||
case BackdropMaterialType.Acrylic: | ||
return new DesktopAcrylicController(); | ||
|
||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Files.Backend.Enums | ||
{ | ||
public enum BackdropMaterialType | ||
{ | ||
Solid, | ||
Mica, | ||
MicaAlt, | ||
Acrylic | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters