diff --git a/QuickLook.Common/Helpers/WindowHelper.cs b/QuickLook.Common/Helpers/WindowHelper.cs index 2c13af1..f9475f7 100644 --- a/QuickLook.Common/Helpers/WindowHelper.cs +++ b/QuickLook.Common/Helpers/WindowHelper.cs @@ -168,7 +168,7 @@ public static class WindowHelper Marshal.FreeHGlobal(accentPtr); } - public static void EnableAcrylicBlur(Window window, Color tintColor, bool isDarkTheme) + public static void EnableAcrylicBlur(Window window, Color tintColor, bool isDarkTheme, double tintOpacity = 0.8) { window.Background = Brushes.Transparent; @@ -193,7 +193,7 @@ public static class WindowHelper var accent = new AccentPolicy(); var accentStructSize = Marshal.SizeOf(accent); accent.AccentState = AccentState.AccentEnableAcrylicblurbehind; - accent.GradientColor = ToAbgr(tintColor, 0.8); + accent.GradientColor = ToAbgr(tintColor, tintOpacity); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); diff --git a/QuickLook/ViewerWindow.xaml.cs b/QuickLook/ViewerWindow.xaml.cs index bd96dec..44b4d01 100644 --- a/QuickLook/ViewerWindow.xaml.cs +++ b/QuickLook/ViewerWindow.xaml.cs @@ -41,6 +41,10 @@ namespace QuickLook; public partial class ViewerWindow : Window { + private const double Acrylic10TintOpacity = 0.7; + private static readonly Color Acrylic10DarkTintColor = Color.FromRgb(0x17, 0x17, 0x17); + private static readonly Color Acrylic10LightTintColor = Color.FromRgb(0xF2, 0xF2, 0xF2); + private Size _customWindowSize = Size.Empty; private bool _ignoreNextWindowSizeChange; private string _path = string.Empty; @@ -204,7 +208,7 @@ public partial class ViewerWindow : Window { Background = (Brush)new BrushConverter().ConvertFromString(customColor); } - catch + catch (Exception ex) when (ex is FormatException || ex is NotSupportedException) { // Ignore invalid color } @@ -279,11 +283,11 @@ public partial class ViewerWindow : Window case SystembackdropType.Acrylic10: if (App.IsWin10 || App.IsWin11) { - var acrylicTint = GetAcrylicTintColor(); + var acrylicTint = GetAcrylic10TintColor(); WindowChrome.GetWindowChrome(this)?.GlassFrameThickness = new Thickness(0d); WindowHelper.DisableDwmBlur(this); // Restore rounded corners on Windows 11 - WindowHelper.EnableAcrylicBlur(this, acrylicTint, CurrentTheme == Themes.Dark); + WindowHelper.EnableAcrylicBlur(this, acrylicTint, CurrentTheme == Themes.Dark, Acrylic10TintOpacity); Background = Brushes.Transparent; } else @@ -356,7 +360,7 @@ public partial class ViewerWindow : Window { return ((SolidColorBrush)new BrushConverter().ConvertFromString(customColor)).Color; } - catch + catch (Exception ex) when (ex is FormatException || ex is NotSupportedException) { // Ignore invalid color } @@ -365,6 +369,25 @@ public partial class ViewerWindow : Window return ((SolidColorBrush)FindResource("MainWindowBackground")).Color; } + private Color GetAcrylic10TintColor() + { + var customColor = SettingHelper.Get("WindowBackgroundColor", string.Empty, "QuickLook"); + + if (!string.IsNullOrEmpty(customColor)) + { + try + { + return ((SolidColorBrush)new BrushConverter().ConvertFromString(customColor)).Color; + } + catch (Exception ex) when (ex is FormatException || ex is NotSupportedException) + { + // Ignore invalid color + } + } + + return CurrentTheme == Themes.Dark ? Acrylic10DarkTintColor : Acrylic10LightTintColor; + } + private static SystembackdropType GetBackdropOption() { var option = SettingHelper.Get("WindowBackdrop", nameof(SystembackdropType.Auto), "QuickLook")?.Trim();