From ece09a93cdf7a0ddc80eb99be26d7497a1871f6a Mon Sep 17 00:00:00 2001 From: Boris Makogonyuk Date: Tue, 10 Nov 2015 12:18:03 +0100 Subject: [PATCH] Changed WindowsAccentMode (int32) Theme setting to ThemeBlurEnabled (boolean): - Exposed a new function "SetBlurForWindow" in WindowIntelopHelper that handles the blur. - Deleted Accent and Test themes - Changed SimpleBlur and Base themes according to changes --- Wox.Core/Theme/Theme.cs | 2 +- Wox.Core/UserSettings/UserSettingStorage.cs | 2 +- Wox/Helper/WindowIntelopHelper.cs | 28 ++++++-- Wox/MainWindow.xaml.cs | 1 + Wox/SettingWindow.xaml.cs | 2 +- Wox/Themes/Accent.xaml | 44 ------------- Wox/Themes/Base.xaml | 4 +- Wox/Themes/SimpleBlur-Black.xaml | 7 +- Wox/Themes/SimpleBlur-White.xaml | 7 +- Wox/Themes/Test.xaml | 72 --------------------- Wox/Wox.csproj | 9 +-- 11 files changed, 36 insertions(+), 142 deletions(-) delete mode 100644 Wox/Themes/Accent.xaml delete mode 100644 Wox/Themes/Test.xaml diff --git a/Wox.Core/Theme/Theme.cs b/Wox.Core/Theme/Theme.cs index e9eee2e0fa..87c3406357 100644 --- a/Wox.Core/Theme/Theme.cs +++ b/Wox.Core/Theme/Theme.cs @@ -56,7 +56,7 @@ namespace Wox.Core.Theme ResourceMerger.ApplyThemeResource(this); UserSettingStorage.Instance.Theme = themeName; - UserSettingStorage.Instance.ThemeAccentMode = (int)Application.Current.Resources["WindowsAccentMode"]; + UserSettingStorage.Instance.ThemeBlurEnabled = (bool)Application.Current.Resources["ThemeBlurEnabled"]; UserSettingStorage.Instance.Save(); } diff --git a/Wox.Core/UserSettings/UserSettingStorage.cs b/Wox.Core/UserSettings/UserSettingStorage.cs index 1b9f69396c..7aa48a82df 100644 --- a/Wox.Core/UserSettings/UserSettingStorage.cs +++ b/Wox.Core/UserSettings/UserSettingStorage.cs @@ -56,7 +56,7 @@ namespace Wox.Core.UserSettings public string ResultItemFontStretch { get; set; } [JsonProperty] - public int ThemeAccentMode { get; set; } + public bool ThemeBlurEnabled { get; set; } [JsonProperty] public double WindowLeft { get; set; } diff --git a/Wox/Helper/WindowIntelopHelper.cs b/Wox/Helper/WindowIntelopHelper.cs index fd40479eca..6bd64615ee 100644 --- a/Wox/Helper/WindowIntelopHelper.cs +++ b/Wox/Helper/WindowIntelopHelper.cs @@ -89,7 +89,11 @@ namespace Wox.Helper public int Bottom; } - internal enum AccentState + #region Blur Handling + /* + Found on https://github.com/riverar/sample-win10-aeroglass + */ + public enum AccentState { ACCENT_DISABLED = 0, ACCENT_ENABLE_GRADIENT = 1, @@ -120,14 +124,23 @@ namespace Wox.Helper WCA_ACCENT_POLICY = 19 } [DllImport("user32.dll")] - internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); - public static void SetWindowAccent(Window wind, int themeAccentMode) + private static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); + + /// + /// Sets the blur for a window via SetWindowCompositionAttribute + /// + /// window to blur + /// true/false - on or off correspondingly + public static void SetBlurForWindow(Window wind, bool status) + { + SetWindowAccent(wind, status ? AccentState.ACCENT_ENABLE_BLURBEHIND : AccentState.ACCENT_DISABLED); + } + + private static void SetWindowAccent(Window wind, AccentState themeAccentMode) { - if (themeAccentMode < 0 || themeAccentMode > 3) - themeAccentMode = 0; var windowHelper = new WindowInteropHelper(wind); var accent = new AccentPolicy(); - accent.AccentState = (AccentState) themeAccentMode; + accent.AccentState = themeAccentMode; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); @@ -142,5 +155,8 @@ namespace Wox.Helper Marshal.FreeHGlobal(accentPtr); } + #endregion + + } } \ No newline at end of file diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 5a289131ed..8be83c06a7 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -255,6 +255,7 @@ namespace Wox InitProgressbarAnimation(); WindowIntelopHelper.DisableControlBox(this); + WindowIntelopHelper.SetBlurForWindow(this, UserSettingStorage.Instance.ThemeBlurEnabled); CheckUpdate(); } diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 0d8bf200ac..c484adbeb0 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -460,7 +460,7 @@ namespace Wox Dispatcher.DelayInvoke("delayChangeTheme", () => { ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); - WindowIntelopHelper.SetWindowAccent(MainWindow, UserSettingStorage.Instance.ThemeAccentMode); + WindowIntelopHelper.SetBlurForWindow(MainWindow, UserSettingStorage.Instance.ThemeBlurEnabled); }, TimeSpan.FromMilliseconds(100)); } diff --git a/Wox/Themes/Accent.xaml b/Wox/Themes/Accent.xaml deleted file mode 100644 index 8585d5cb2c..0000000000 --- a/Wox/Themes/Accent.xaml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - 2 - - - - - - - - - - - - - - - #4F6180 - - - - - - diff --git a/Wox/Themes/Base.xaml b/Wox/Themes/Base.xaml index 18d1edcb4e..5fa7c96c81 100644 --- a/Wox/Themes/Base.xaml +++ b/Wox/Themes/Base.xaml @@ -27,8 +27,8 @@ - - 0 + + false diff --git a/Wox/Themes/SimpleBlur-Black.xaml b/Wox/Themes/SimpleBlur-Black.xaml index fad01abd7a..88e911b931 100644 --- a/Wox/Themes/SimpleBlur-Black.xaml +++ b/Wox/Themes/SimpleBlur-Black.xaml @@ -4,10 +4,9 @@ - - - 3 - + + True + - - - - - - - - - - - - - Transparent - - - - - - diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index aa8737fb38..52b55486ac 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -258,21 +258,16 @@ Designer PreserveNewest - + MSBuild:Compile Designer PreserveNewest - + MSBuild:Compile Designer PreserveNewest - - Designer - MSBuild:Compile - Always - Designer MSBuild:Compile