From 6a6d6b22ee665a35d869e5fd29726e2eeceff5cc Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 27 Jun 2021 21:42:37 +1000 Subject: [PATCH 1/4] auto disable shadow when blur is enabled --- Flow.Launcher.Core/Resource/Theme.cs | 41 ++++++++++--------- Flow.Launcher/MainWindow.xaml.cs | 3 +- Flow.Launcher/SettingWindow.xaml | 2 +- .../ViewModel/SettingWindowViewModel.cs | 12 +++++- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index fe64e0c3e17..e7a19d6a466 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -28,6 +28,8 @@ public class Theme private string DirectoryPath => Path.Combine(Constant.ProgramDirectory, Folder); private string UserDirectoryPath => Path.Combine(DataLocation.DataDirectory(), Folder); + public bool BlurEnabled { get; set; } + public Theme() { _themeDirectories.Add(DirectoryPath); @@ -88,7 +90,9 @@ public bool ChangeTheme(string theme) _oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath); } - if (Settings.UseDropShadowEffect) + BlurEnabled = IsBlurTheme(); + + if (Settings.UseDropShadowEffect && !BlurEnabled) AddDropShadowEffectToCurrentTheme(); } catch (DirectoryNotFoundException e) @@ -252,7 +256,7 @@ public void AddDropShadowEffectToCurrentTheme() UpdateResourceDictionary(dict); } - public void RemoveDropShadowEffectToCurrentTheme() + public void RemoveDropShadowEffectFromCurrentTheme() { var dict = CurrentThemeResourceDictionary(); var windowBorderStyle = dict["WindowBorderStyle"] as Style; @@ -320,30 +324,29 @@ 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) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 4355cda154b..177953912e2 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -61,7 +61,8 @@ private void OnLoaded(object sender, RoutedEventArgs _) // show notify icon when flowlauncher is hidden InitializeNotifyIcon(); - // todo is there a way to set blur only once? + // currently blur can only be called when loading main window. + // is there a way to set blur only once? ThemeManager.Instance.SetBlurForWindow(); WindowsInteropHelper.DisableControlBox(this); InitProgressbarAnimation(); 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/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index b974efd0337..b476599b538 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -271,6 +271,10 @@ public string SelectedTheme { Settings.Theme = value; ThemeManager.Instance.ChangeTheme(value); + + if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect) + DropShadowEffect = false; + } } @@ -282,13 +286,19 @@ public bool DropShadowEffect get { return Settings.UseDropShadowEffect; } set { + if (ThemeManager.Instance.BlurEnabled && value) + { + MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + return; + } + if (value) { ThemeManager.Instance.AddDropShadowEffectToCurrentTheme(); } else { - ThemeManager.Instance.RemoveDropShadowEffectToCurrentTheme(); + ThemeManager.Instance.RemoveDropShadowEffectFromCurrentTheme(); } Settings.UseDropShadowEffect = value; From 52fbebf2d6881a0521c95d0a61bd95874981a3b4 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 27 Jun 2021 22:13:58 +1000 Subject: [PATCH 2/4] prompt user restart required when blur theme is selected first time --- Flow.Launcher.Core/Resource/Theme.cs | 4 ++++ Flow.Launcher/Languages/en.xaml | 2 ++ Flow.Launcher/MainWindow.xaml.cs | 2 ++ Flow.Launcher/ViewModel/SettingWindowViewModel.cs | 7 ++++++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index e7a19d6a466..00e62ad77a5 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -30,6 +30,10 @@ public class Theme public bool BlurEnabled { get; set; } + // due to blur only enabled when main window is loaded for the first time, this is used to track the blur status + // when the window is first loaded and prompt user that a restart is required for blur to take effect. + public bool BlurEnabledOnloaded { get; set; } + public Theme() { _themeDirectories.Add(DirectoryPath); diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 573403823ca..f0467766982 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -39,6 +39,8 @@ 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 + Current theme has blur effect enabled for the first time, a restart is required in order to take effect Plugin diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 177953912e2..f712f9a6e97 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -64,6 +64,8 @@ private void OnLoaded(object sender, RoutedEventArgs _) // currently blur can only be called when loading main window. // is there a way to set blur only once? ThemeManager.Instance.SetBlurForWindow(); + ThemeManager.Instance.BlurEnabledOnloaded = ThemeManager.Instance.BlurEnabled; + WindowsInteropHelper.DisableControlBox(this); InitProgressbarAnimation(); InitializePosition(); diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index b476599b538..c3c35f25638 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -275,6 +275,11 @@ public string SelectedTheme if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect) DropShadowEffect = false; + if (!ThemeManager.Instance.BlurEnabledOnloaded && ThemeManager.Instance.BlurEnabled) + { + MessageBox.Show(InternationalizationManager.Instance.GetTranslation("blurEffectRequireRestart")); + ThemeManager.Instance.BlurEnabledOnloaded = true; + } } } @@ -288,7 +293,7 @@ public bool DropShadowEffect { if (ThemeManager.Instance.BlurEnabled && value) { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem")); + MessageBox.Show(InternationalizationManager.Instance.GetTranslation("shadowEffectNotAllowed")); return; } From aa34a0202d620e61daf22548425c693320867900 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 29 Jun 2021 07:00:01 +1000 Subject: [PATCH 3/4] set blur when theme change is called --- Flow.Launcher.Core/Resource/Theme.cs | 8 ++++---- Flow.Launcher/Languages/en.xaml | 1 - Flow.Launcher/MainWindow.xaml.cs | 5 ----- Flow.Launcher/ViewModel/SettingWindowViewModel.cs | 6 ------ 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 00e62ad77a5..488e73eb62d 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -30,10 +30,6 @@ public class Theme public bool BlurEnabled { get; set; } - // due to blur only enabled when main window is loaded for the first time, this is used to track the blur status - // when the window is first loaded and prompt user that a restart is required for blur to take effect. - public bool BlurEnabledOnloaded { get; set; } - public Theme() { _themeDirectories.Add(DirectoryPath); @@ -98,6 +94,8 @@ public bool ChangeTheme(string theme) if (Settings.UseDropShadowEffect && !BlurEnabled) AddDropShadowEffectToCurrentTheme(); + + SetBlurForWindow(); } catch (DirectoryNotFoundException e) { @@ -356,6 +354,8 @@ private bool IsBlurTheme() private void SetWindowAccent(Window w, AccentState state) { var windowHelper = new WindowInteropHelper(w); + w.Width = 750; + 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 f0467766982..efb82b47813 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -40,7 +40,6 @@ 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 - Current theme has blur effect enabled for the first time, a restart is required in order to take effect Plugin diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index f712f9a6e97..735103938f0 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -61,11 +61,6 @@ private void OnLoaded(object sender, RoutedEventArgs _) // show notify icon when flowlauncher is hidden InitializeNotifyIcon(); - // currently blur can only be called when loading main window. - // is there a way to set blur only once? - ThemeManager.Instance.SetBlurForWindow(); - ThemeManager.Instance.BlurEnabledOnloaded = ThemeManager.Instance.BlurEnabled; - WindowsInteropHelper.DisableControlBox(this); InitProgressbarAnimation(); InitializePosition(); diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index c3c35f25638..53789d2d90d 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -274,12 +274,6 @@ public string SelectedTheme if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect) DropShadowEffect = false; - - if (!ThemeManager.Instance.BlurEnabledOnloaded && ThemeManager.Instance.BlurEnabled) - { - MessageBox.Show(InternationalizationManager.Instance.GetTranslation("blurEffectRequireRestart")); - ThemeManager.Instance.BlurEnabledOnloaded = true; - } } } From b5272ddb4707e86c54c94b8f6b754c145dfed56f Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 29 Jun 2021 09:21:53 +1000 Subject: [PATCH 4/4] allow main query window's width to be dynamic --- Flow.Launcher.Core/Resource/Theme.cs | 22 +++++++++++++++++++++- Flow.Launcher/MainWindow.xaml | 2 +- Flow.Launcher/Themes/Base.xaml | 2 ++ Flow.Launcher/Themes/BlurBlack Darker.xaml | 1 - Flow.Launcher/Themes/BlurBlack.xaml | 1 - Flow.Launcher/Themes/BlurWhite.xaml | 1 - 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 488e73eb62d..e70de673e4c 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -30,6 +30,8 @@ public class Theme public bool BlurEnabled { get; set; } + private double mainWindowWidth; + public Theme() { _themeDirectories.Add(DirectoryPath); @@ -187,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; } @@ -354,8 +371,11 @@ private bool IsBlurTheme() private void SetWindowAccent(Window w, AccentState state) { var windowHelper = new WindowInteropHelper(w); - w.Width = 750; + + // 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/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/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 @@