mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
ToastWindows tweak (#569)
- Using default acrylic which is fine for notifications (it's not activated anyways because the window does not have focus..), and it removes a bunch of C# code. - Minor tweaks to the padding of the toastwindow so it's more similar to OS toasts
This commit is contained in:
@@ -8,19 +8,16 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||
Title="Command Palette Toast"
|
||||
Activated="OnActivated"
|
||||
Closed="OnClosed"
|
||||
mc:Ignorable="d">
|
||||
<!--<Window.SystemBackdrop>
|
||||
<MicaBackdrop />
|
||||
</Window.SystemBackdrop>-->
|
||||
<StackPanel x:Name="ToastGrid">
|
||||
<Window.SystemBackdrop>
|
||||
<DesktopAcrylicBackdrop />
|
||||
</Window.SystemBackdrop>
|
||||
<Grid x:Name="ToastGrid">
|
||||
<!-- This padding is used to calculate the dimensions of the ToastWindow -->
|
||||
<TextBlock
|
||||
x:Name="ToastText"
|
||||
Padding="8,8,28,20"
|
||||
FontSize="16"
|
||||
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
|
||||
Padding="16,16,36,24"
|
||||
Text="{x:Bind ViewModel.ToastMessage, Mode=OneWay}"
|
||||
TextAlignment="Left" />
|
||||
</StackPanel>
|
||||
TextAlignment="Center" />
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -30,9 +30,6 @@ public sealed partial class ToastWindow : Window,
|
||||
|
||||
private readonly DispatcherQueueTimer _debounceTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
|
||||
|
||||
private DesktopAcrylicController? _acrylicController;
|
||||
private SystemBackdropConfiguration? _configurationSource;
|
||||
|
||||
public ToastWindow()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
@@ -48,9 +45,6 @@ public sealed partial class ToastWindow : Window,
|
||||
PInvoke.EnableWindow(_hwnd, false);
|
||||
|
||||
WeakReferenceMessenger.Default.Register<QuitMessage>(this);
|
||||
|
||||
SetAcrylic();
|
||||
ToastText.ActualThemeChanged += (s, e) => UpdateAcrylic();
|
||||
}
|
||||
|
||||
private void PositionCentered()
|
||||
@@ -102,75 +96,4 @@ public sealed partial class ToastWindow : Window,
|
||||
// This might come in on a background thread
|
||||
DispatcherQueue.TryEnqueue(() => Close());
|
||||
}
|
||||
|
||||
////// Literally everything below here is for acrylic //////
|
||||
|
||||
internal void OnClosed(object sender, WindowEventArgs args) => DisposeAcrylic();
|
||||
|
||||
// We want to use DesktopAcrylicKind.Thin and custom colors as this is the default material
|
||||
// other Shell surfaces are using, this cannot be set in XAML however.
|
||||
private void SetAcrylic()
|
||||
{
|
||||
if (DesktopAcrylicController.IsSupported())
|
||||
{
|
||||
// Hooking up the policy object.
|
||||
_configurationSource = new SystemBackdropConfiguration
|
||||
{
|
||||
// Initial configuration state.
|
||||
IsInputActive = true,
|
||||
};
|
||||
UpdateAcrylic();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAcrylic()
|
||||
{
|
||||
_acrylicController = GetAcrylicConfig(Content);
|
||||
|
||||
// Enable the system backdrop.
|
||||
// Note: Be sure to have "using WinRT;" to support the Window.As<...>() call.
|
||||
_acrylicController.AddSystemBackdropTarget(this.As<ICompositionSupportsSystemBackdrop>());
|
||||
_acrylicController.SetSystemBackdropConfiguration(_configurationSource);
|
||||
}
|
||||
|
||||
private static DesktopAcrylicController GetAcrylicConfig(UIElement content)
|
||||
{
|
||||
var feContent = content as FrameworkElement;
|
||||
|
||||
return feContent?.ActualTheme == ElementTheme.Light
|
||||
? new DesktopAcrylicController()
|
||||
{
|
||||
Kind = DesktopAcrylicKind.Thin,
|
||||
TintColor = Color.FromArgb(255, 243, 243, 243),
|
||||
LuminosityOpacity = 0.90f,
|
||||
TintOpacity = 0.0f,
|
||||
FallbackColor = Color.FromArgb(255, 238, 238, 238),
|
||||
}
|
||||
: new DesktopAcrylicController()
|
||||
{
|
||||
Kind = DesktopAcrylicKind.Thin,
|
||||
TintColor = Color.FromArgb(255, 32, 32, 32),
|
||||
LuminosityOpacity = 0.96f,
|
||||
TintOpacity = 0.5f,
|
||||
FallbackColor = Color.FromArgb(255, 28, 28, 28),
|
||||
};
|
||||
}
|
||||
|
||||
private void DisposeAcrylic()
|
||||
{
|
||||
if (_acrylicController != null)
|
||||
{
|
||||
_acrylicController.Dispose();
|
||||
_acrylicController = null!;
|
||||
_configurationSource = null!;
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnActivated(object sender, WindowActivatedEventArgs args)
|
||||
{
|
||||
if (_configurationSource != null)
|
||||
{
|
||||
_configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user