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 | 43 ++++++++++--------- Flow.Launcher/MainWindow.xaml.cs | 3 +- Flow.Launcher/SettingWindow.xaml | 2 +- .../ViewModel/SettingWindowViewModel.cs | 12 +++++- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index fe64e0c3e..e7a19d6a4 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -28,6 +28,8 @@ namespace Flow.Launcher.Core.Resource 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 @@ namespace Flow.Launcher.Core.Resource _oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath); } - if (Settings.UseDropShadowEffect) + BlurEnabled = IsBlurTheme(); + + if (Settings.UseDropShadowEffect && !BlurEnabled) AddDropShadowEffectToCurrentTheme(); } catch (DirectoryNotFoundException e) @@ -252,7 +256,7 @@ namespace Flow.Launcher.Core.Resource UpdateResourceDictionary(dict); } - public void RemoveDropShadowEffectToCurrentTheme() + public void RemoveDropShadowEffectFromCurrentTheme() { var dict = CurrentThemeResourceDictionary(); var windowBorderStyle = dict["WindowBorderStyle"] as Style; @@ -320,30 +324,29 @@ namespace Flow.Launcher.Core.Resource /// 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; - } - if (blur) - { - SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND); - } - else - { - SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED); - } + if (resource is bool) + return (bool)resource; + + 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 4355cda15..177953912 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -61,7 +61,8 @@ namespace Flow.Launcher // 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 0d966f1d6..1a8a12100 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 b974efd03..b476599b5 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -271,6 +271,10 @@ namespace Flow.Launcher.ViewModel { Settings.Theme = value; ThemeManager.Instance.ChangeTheme(value); + + if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect) + DropShadowEffect = false; + } } @@ -282,13 +286,19 @@ namespace Flow.Launcher.ViewModel 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 e7a19d6a4..00e62ad77 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -30,6 +30,10 @@ namespace Flow.Launcher.Core.Resource 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 573403823..f04677669 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 177953912..f712f9a6e 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -64,6 +64,8 @@ namespace Flow.Launcher // 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 b476599b5..c3c35f256 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -275,6 +275,11 @@ namespace Flow.Launcher.ViewModel 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 @@ namespace Flow.Launcher.ViewModel { 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 00e62ad77..488e73eb6 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -30,10 +30,6 @@ namespace Flow.Launcher.Core.Resource 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 @@ namespace Flow.Launcher.Core.Resource if (Settings.UseDropShadowEffect && !BlurEnabled) AddDropShadowEffectToCurrentTheme(); + + SetBlurForWindow(); } catch (DirectoryNotFoundException e) { @@ -356,6 +354,8 @@ namespace Flow.Launcher.Core.Resource 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 f04677669..efb82b478 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 f712f9a6e..735103938 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -61,11 +61,6 @@ namespace Flow.Launcher // 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 c3c35f256..53789d2d9 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -274,12 +274,6 @@ namespace Flow.Launcher.ViewModel 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 488e73eb6..e70de673e 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -30,6 +30,8 @@ namespace Flow.Launcher.Core.Resource public bool BlurEnabled { get; set; } + private double mainWindowWidth; + public Theme() { _themeDirectories.Add(DirectoryPath); @@ -187,6 +189,21 @@ namespace Flow.Launcher.Core.Resource 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 @@ namespace Flow.Launcher.Core.Resource 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 aa0240dd4..7d0632d70 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 eb2af490a..df0304bc2 100644 --- a/Flow.Launcher/Themes/Base.xaml +++ b/Flow.Launcher/Themes/Base.xaml @@ -46,6 +46,8 @@