diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index fe64e0c3e17..e70de673e4c 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -28,6 +28,10 @@ public class Theme private string DirectoryPath => Path.Combine(Constant.ProgramDirectory, Folder); private string UserDirectoryPath => Path.Combine(DataLocation.DataDirectory(), Folder); + public bool BlurEnabled { get; set; } + + private double mainWindowWidth; + public Theme() { _themeDirectories.Add(DirectoryPath); @@ -88,8 +92,12 @@ public bool ChangeTheme(string theme) _oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath); } - if (Settings.UseDropShadowEffect) + BlurEnabled = IsBlurTheme(); + + if (Settings.UseDropShadowEffect && !BlurEnabled) AddDropShadowEffectToCurrentTheme(); + + SetBlurForWindow(); } catch (DirectoryNotFoundException e) { @@ -181,6 +189,21 @@ public ResourceDictionary GetResourceDictionary() Array.ForEach(new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p))); } + var windowStyle = dict["WindowStyle"] as Style; + + var width = windowStyle?.Setters.OfType().Where(x => x.Property.Name == "Width") + .Select(x => x.Value).FirstOrDefault(); + + if (width == null) + { + windowStyle = dict["BaseWindowStyle"] as Style; + + width = windowStyle?.Setters.OfType().Where(x => x.Property.Name == "Width") + .Select(x => x.Value).FirstOrDefault(); + } + + mainWindowWidth = (double)width; + return dict; } @@ -252,7 +275,7 @@ public void AddDropShadowEffectToCurrentTheme() UpdateResourceDictionary(dict); } - public void RemoveDropShadowEffectToCurrentTheme() + public void RemoveDropShadowEffectFromCurrentTheme() { var dict = CurrentThemeResourceDictionary(); var windowBorderStyle = dict["WindowBorderStyle"] as Style; @@ -320,35 +343,39 @@ private enum WindowCompositionAttribute /// public void SetBlurForWindow() { + if (BlurEnabled) + { + SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND); + } + else + { + SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED); + } + } - // Exception of FindResource can't be cathed if global exception handle is set + private bool IsBlurTheme() + { if (Environment.OSVersion.Version >= new Version(6, 2)) { var resource = Application.Current.TryFindResource("ThemeBlurEnabled"); - bool blur; + if (resource is bool) - { - blur = (bool)resource; - } - else - { - blur = false; - } + return (bool)resource; - if (blur) - { - SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND); - } - else - { - SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED); - } + return false; } + + return false; } private void SetWindowAccent(Window w, AccentState state) { var windowHelper = new WindowInteropHelper(w); + + // this determines the width of the main query window + w.Width = mainWindowWidth; + windowHelper.EnsureHandle(); + var accent = new AccentPolicy { AccentState = state }; var accentStructSize = Marshal.SizeOf(accent); diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 573403823ca..efb82b47813 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -39,6 +39,7 @@ Query Search Precision Should Use Pinyin Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for transliterating Chinese + Shadow effect is not allowed while current theme has blur effect enabled Plugin diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index aa0240dd428..7d0632d7039 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -60,7 +60,7 @@ - + diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 4355cda154b..735103938f0 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -61,8 +61,6 @@ private void OnLoaded(object sender, RoutedEventArgs _) // show notify icon when flowlauncher is hidden InitializeNotifyIcon(); - // todo is there a way to set blur only once? - ThemeManager.Instance.SetBlurForWindow(); WindowsInteropHelper.DisableControlBox(this); InitProgressbarAnimation(); InitializePosition(); diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 0d966f1d652..1a8a12100df 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -242,7 +242,7 @@ - + diff --git a/Flow.Launcher/Themes/Base.xaml b/Flow.Launcher/Themes/Base.xaml index eb2af490a30..df0304bc210 100644 --- a/Flow.Launcher/Themes/Base.xaml +++ b/Flow.Launcher/Themes/Base.xaml @@ -46,6 +46,8 @@