-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Feature: Added support for changing backdrop material #12534
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
271a219
Add support for changing system backdrop
heftymouse fb3d2e7
remove random extra line
heftymouse 40406a6
unregister event handler
heftymouse 8fcd4d5
remove solid and mica from ui
heftymouse b7294f8
fix default value
heftymouse 9a7284b
make (some) changes
heftymouse d24679a
check if target already connected
heftymouse 0e1bfbb
Merge branch 'main' into main
yaira2 0e8bbb1
Update src/Files.Backend/Services/Settings/IAppearanceSettingsService.cs
yaira2 df1ae0b
change user facing name for setting
heftymouse 572c270
Merge branch 'main' of https://github.com/heftymouse/Files
heftymouse 0fc2f83
Merge branch 'main' into main
yaira2 7737333
change internal name for system backdrop
heftymouse da94144
Merge branch 'main' of https://github.com/heftymouse/Files
heftymouse a342c29
Merge branch 'main' into main
yaira2 a23ba41
more name changes
heftymouse 769ab9c
Merge branch 'main' of https://github.com/heftymouse/Files
heftymouse db482b8
Unrelated change
yaira2 6e26154
Update AppearanceViewModel.cs
yaira2 9987e8a
Revert "Update AppearanceViewModel.cs"
yaira2 156726d
Update AppearanceViewModel.cs
yaira2 afe170e
Update GeneralPage.xaml
yaira2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.