mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
## Summary This PR adds: - Backdrop material customization - Alongside acrylic, the following options are now available: - Transparent background - Mica background - Background material opacity - Lets you control how transparent the background is ## Pictures? Pictures! <img width="1491" height="928" alt="image" src="https://github.com/user-attachments/assets/ff4e9e06-fcf1-4f05-bc0a-fb70dc4f39be" /> https://github.com/user-attachments/assets/84e83279-afab-481e-b904-f054318c5d2f <img width="977" height="628" alt="image" src="https://github.com/user-attachments/assets/241a228d-af3f-448a-94a6-0a282218bd8c" /> ## PR Checklist - [x] Closes: #44197 <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed
99 lines
3.7 KiB
C#
99 lines
3.7 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using Microsoft.CmdPal.UI.ViewModels.Services;
|
|
using Microsoft.UI.Dispatching;
|
|
using Microsoft.UI.Xaml.Media;
|
|
using Windows.UI;
|
|
|
|
namespace Microsoft.CmdPal.UI.ViewModels;
|
|
|
|
public partial class MainWindowViewModel : ObservableObject, IDisposable
|
|
{
|
|
private readonly IThemeService _themeService;
|
|
private readonly DispatcherQueue _uiDispatcherQueue = DispatcherQueue.GetForCurrentThread()!;
|
|
|
|
[ObservableProperty]
|
|
public partial ImageSource? BackgroundImageSource { get; private set; }
|
|
|
|
[ObservableProperty]
|
|
public partial Stretch BackgroundImageStretch { get; private set; } = Stretch.Fill;
|
|
|
|
[ObservableProperty]
|
|
[NotifyPropertyChangedFor(nameof(EffectiveImageOpacity))]
|
|
public partial double BackgroundImageOpacity { get; private set; }
|
|
|
|
[ObservableProperty]
|
|
public partial Color BackgroundImageTint { get; private set; }
|
|
|
|
[ObservableProperty]
|
|
public partial double BackgroundImageTintIntensity { get; private set; }
|
|
|
|
[ObservableProperty]
|
|
public partial int BackgroundImageBlurAmount { get; private set; }
|
|
|
|
[ObservableProperty]
|
|
public partial double BackgroundImageBrightness { get; private set; }
|
|
|
|
[ObservableProperty]
|
|
public partial bool ShowBackgroundImage { get; private set; }
|
|
|
|
[ObservableProperty]
|
|
[NotifyPropertyChangedFor(nameof(EffectiveBackdropStyle))]
|
|
[NotifyPropertyChangedFor(nameof(EffectiveImageOpacity))]
|
|
public partial BackdropStyle BackdropStyle { get; private set; }
|
|
|
|
[ObservableProperty]
|
|
[NotifyPropertyChangedFor(nameof(EffectiveBackdropStyle))]
|
|
[NotifyPropertyChangedFor(nameof(EffectiveImageOpacity))]
|
|
public partial float BackdropOpacity { get; private set; } = 1.0f;
|
|
|
|
// Returns null when no transparency needed (BlurImageControl uses this to decide source type)
|
|
public BackdropStyle? EffectiveBackdropStyle =>
|
|
BackdropStyle == BackdropStyle.Clear ||
|
|
BackdropStyle == BackdropStyle.Mica ||
|
|
BackdropOpacity < 1.0f
|
|
? BackdropStyle
|
|
: null;
|
|
|
|
// When transparency is enabled, use square root curve so image stays visible longer as backdrop fades
|
|
public double EffectiveImageOpacity =>
|
|
EffectiveBackdropStyle is not null
|
|
? BackgroundImageOpacity * Math.Sqrt(BackdropOpacity)
|
|
: BackgroundImageOpacity;
|
|
|
|
public MainWindowViewModel(IThemeService themeService)
|
|
{
|
|
_themeService = themeService;
|
|
_themeService.ThemeChanged += ThemeService_ThemeChanged;
|
|
}
|
|
|
|
private void ThemeService_ThemeChanged(object? sender, ThemeChangedEventArgs e)
|
|
{
|
|
_uiDispatcherQueue.TryEnqueue(() =>
|
|
{
|
|
BackgroundImageSource = _themeService.Current.BackgroundImageSource;
|
|
BackgroundImageStretch = _themeService.Current.BackgroundImageStretch;
|
|
BackgroundImageOpacity = _themeService.Current.BackgroundImageOpacity;
|
|
|
|
BackgroundImageBrightness = _themeService.Current.BackgroundBrightness;
|
|
BackgroundImageTint = _themeService.Current.Tint;
|
|
BackgroundImageTintIntensity = _themeService.Current.TintIntensity;
|
|
BackgroundImageBlurAmount = _themeService.Current.BlurAmount;
|
|
|
|
BackdropStyle = _themeService.Current.BackdropParameters.Style;
|
|
BackdropOpacity = _themeService.Current.BackdropOpacity;
|
|
|
|
ShowBackgroundImage = BackgroundImageSource != null;
|
|
});
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_themeService.ThemeChanged -= ThemeService_ThemeChanged;
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|