From f24a6f0e3c3506103ed52ddfcd98b7a53e2770c0 Mon Sep 17 00:00:00 2001 From: Boris Makogonyuk Date: Tue, 10 Nov 2015 00:51:22 +0100 Subject: [PATCH 1/6] MainWindow: AllowsTransparency set to True WindowIntelopHelper: Added accent handling SettingsWindow: Added combobox with accent selector to Theme tab (not functional yet) Languages: Added entries for accent colors (all are in english for now) [TEMP] Blur and Accent themes experiments [TEMP] blur set in mainwindow on load. --- Wox/Helper/WindowIntelopHelper.cs | 54 ++++++++++++++++++++++++ Wox/Languages/en.xaml | 2 + Wox/Languages/ru.xaml | 1 + Wox/Languages/zh-cn.xaml | 3 +- Wox/Languages/zh-tw.xaml | 1 + Wox/MainWindow.xaml | 4 +- Wox/MainWindow.xaml.cs | 2 + Wox/SettingWindow.xaml | 13 ++++++ Wox/Themes/SimpleBlur.xaml | 41 ++++++++++++++++++ Wox/Themes/Test.xaml | 69 +++++++++++++++++++++++++++++++ Wox/Wox.csproj | 9 ++++ 11 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 Wox/Themes/SimpleBlur.xaml create mode 100644 Wox/Themes/Test.xaml diff --git a/Wox/Helper/WindowIntelopHelper.cs b/Wox/Helper/WindowIntelopHelper.cs index 4a0223a19e..a9dd5ab217 100644 --- a/Wox/Helper/WindowIntelopHelper.cs +++ b/Wox/Helper/WindowIntelopHelper.cs @@ -88,5 +88,59 @@ namespace Wox.Helper public int Right; public int Bottom; } + + internal enum AccentState + { + ACCENT_DISABLED = 0, + ACCENT_ENABLE_GRADIENT = 1, + ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, + ACCENT_ENABLE_BLURBEHIND = 3, + ACCENT_INVALID_STATE = 4 + } + + [StructLayout(LayoutKind.Sequential)] + internal struct AccentPolicy + { + public AccentState AccentState; + public int AccentFlags; + public int GradientColor; + public int AnimationId; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct WindowCompositionAttributeData + { + public WindowCompositionAttribute Attribute; + public IntPtr Data; + public int SizeOfData; + } + + internal enum WindowCompositionAttribute + { + WCA_ACCENT_POLICY = 19 + } + [DllImport("user32.dll")] + internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); + public static void EnableBlur(Window wind) + { + var windowHelper = new WindowInteropHelper(wind); + + var accent = new AccentPolicy(); + accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND; + accent.GradientColor = 16711680; + var accentStructSize = Marshal.SizeOf(accent); + + var accentPtr = Marshal.AllocHGlobal(accentStructSize); + Marshal.StructureToPtr(accent, accentPtr, false); + + var data = new WindowCompositionAttributeData(); + data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY; + data.SizeOfData = accentStructSize; + data.Data = accentPtr; + + SetWindowCompositionAttribute(windowHelper.Handle, ref data); + + Marshal.FreeHGlobal(accentPtr); + } } } \ No newline at end of file diff --git a/Wox/Languages/en.xaml b/Wox/Languages/en.xaml index 71b8cccf6a..8f53a74ff0 100644 --- a/Wox/Languages/en.xaml +++ b/Wox/Languages/en.xaml @@ -43,6 +43,8 @@ Result Item Font Window Mode Opacity + Windows Accents + Hotkey diff --git a/Wox/Languages/ru.xaml b/Wox/Languages/ru.xaml index 13a7be86cc..0c25bfb5a2 100644 --- a/Wox/Languages/ru.xaml +++ b/Wox/Languages/ru.xaml @@ -43,6 +43,7 @@ Шрифт результатов Оконный режим Прозрачность + Windows Accents Горячие клавиши diff --git a/Wox/Languages/zh-cn.xaml b/Wox/Languages/zh-cn.xaml index 0823b5f3e0..8db385c98d 100644 --- a/Wox/Languages/zh-cn.xaml +++ b/Wox/Languages/zh-cn.xaml @@ -43,7 +43,8 @@ 结果项字体 窗口模式 透明度 - + Windows Accents + 热键 Wox激活热键 diff --git a/Wox/Languages/zh-tw.xaml b/Wox/Languages/zh-tw.xaml index 5d8907fe7a..780bc115a5 100644 --- a/Wox/Languages/zh-tw.xaml +++ b/Wox/Languages/zh-tw.xaml @@ -43,6 +43,7 @@ 結果項字體 窗口模式 透明度 + Windows Accents 熱鍵 diff --git a/Wox/MainWindow.xaml b/Wox/MainWindow.xaml index 4b5a315fed..e3f249642e 100644 --- a/Wox/MainWindow.xaml +++ b/Wox/MainWindow.xaml @@ -13,7 +13,9 @@ AllowDrop="True" ShowInTaskbar="False" Style="{DynamicResource WindowStyle}" - Icon="Images\app.png"> + Icon="Images\app.png" + AllowsTransparency="True" + > diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 5a289131ed..ef46b74f51 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -207,6 +207,7 @@ namespace Wox InitialTray(); Closing += MainWindow_Closing; + } @@ -255,6 +256,7 @@ namespace Wox InitProgressbarAnimation(); WindowIntelopHelper.DisableControlBox(this); + WindowIntelopHelper.EnableBlur(this); CheckUpdate(); } diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 3d94b8fd5b..402aa1506b 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -199,7 +199,20 @@ + + + + + + + + + + + + + diff --git a/Wox/Themes/SimpleBlur.xaml b/Wox/Themes/SimpleBlur.xaml new file mode 100644 index 0000000000..acb26e0ba8 --- /dev/null +++ b/Wox/Themes/SimpleBlur.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + #4F6180 + + + + + + diff --git a/Wox/Themes/Test.xaml b/Wox/Themes/Test.xaml new file mode 100644 index 0000000000..108852a6f5 --- /dev/null +++ b/Wox/Themes/Test.xaml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + #FFBBBBBB + + + + + + diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 7d46e6109a..140595f5a5 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -258,6 +258,15 @@ Designer PreserveNewest + + MSBuild:Compile + Designer + PreserveNewest + + + Designer + MSBuild:Compile + Designer MSBuild:Compile From d8b806966a8ced00c0b50d234fcfc8ca2dce9f09 Mon Sep 17 00:00:00 2001 From: Boris Makogonyuk Date: Tue, 10 Nov 2015 03:37:34 +0100 Subject: [PATCH 2/6] Reversing MainWindow Blur call and settings window modification Added WindowsAccentMode to Base theme --- Wox/MainWindow.xaml.cs | 2 -- Wox/SettingWindow.xaml | 13 ------------- Wox/Themes/Base.xaml | 1 + Wox/Themes/SimpleBlur.xaml | 3 ++- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index ef46b74f51..5a289131ed 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -207,7 +207,6 @@ namespace Wox InitialTray(); Closing += MainWindow_Closing; - } @@ -256,7 +255,6 @@ namespace Wox InitProgressbarAnimation(); WindowIntelopHelper.DisableControlBox(this); - WindowIntelopHelper.EnableBlur(this); CheckUpdate(); } diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 402aa1506b..3d94b8fd5b 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -199,20 +199,7 @@ - - - - - - - - - - - - - diff --git a/Wox/Themes/Base.xaml b/Wox/Themes/Base.xaml index 39866e052c..d0d2b4a8eb 100644 --- a/Wox/Themes/Base.xaml +++ b/Wox/Themes/Base.xaml @@ -27,6 +27,7 @@ + 0 From 724cb0787dd8c4c5190e4ee67c6e1c3388646dc0 Mon Sep 17 00:00:00 2001 From: Boris Makogonyuk Date: Tue, 10 Nov 2015 06:35:09 +0100 Subject: [PATCH 3/6] Applying theme before actually setting the theme accent. UserSettingStorage now stores current theme accent mode. Themes: Added a bunch of them. Testing what works. --- Wox/Themes/Accent.xaml | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Wox/Themes/Accent.xaml diff --git a/Wox/Themes/Accent.xaml b/Wox/Themes/Accent.xaml new file mode 100644 index 0000000000..8585d5cb2c --- /dev/null +++ b/Wox/Themes/Accent.xaml @@ -0,0 +1,44 @@ + + + + + + + 2 + + + + + + + + + + + + + + + #4F6180 + + + + + + From 287e15fddc8319bba4b957191f590639f5e8a9ce Mon Sep 17 00:00:00 2001 From: Boris Makogonyuk Date: Tue, 10 Nov 2015 06:36:08 +0100 Subject: [PATCH 4/6] *forgot to stage files on last commit --- Wox.Core/Theme/Theme.cs | 8 ++++---- Wox.Core/UserSettings/UserSettingStorage.cs | 5 +++++ Wox/Helper/WindowIntelopHelper.cs | 8 ++++---- Wox/SettingWindow.xaml.cs | 1 + Wox/Themes/Base.xaml | 3 +++ Wox/Themes/Dark.xaml | 2 ++ Wox/Themes/SimpleBlur.xaml | 3 +++ Wox/Themes/Test.xaml | 7 +++++-- Wox/Wox.csproj | 6 ++++++ 9 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Wox.Core/Theme/Theme.cs b/Wox.Core/Theme/Theme.cs index 9d937b51b1..e9eee2e0fa 100644 --- a/Wox.Core/Theme/Theme.cs +++ b/Wox.Core/Theme/Theme.cs @@ -53,10 +53,11 @@ namespace Wox.Core.Theme } } - UserSettingStorage.Instance.Theme = themeName; - UserSettingStorage.Instance.Save(); - ResourceMerger.ApplyThemeResource(this); + + UserSettingStorage.Instance.Theme = themeName; + UserSettingStorage.Instance.ThemeAccentMode = (int)Application.Current.Resources["WindowsAccentMode"]; + UserSettingStorage.Instance.Save(); } public ResourceDictionary GetResourceDictionary() @@ -89,7 +90,6 @@ namespace Wox.Core.Theme Setter[] setters = new Setter[] { fontFamily, fontStyle, fontWeight, fontStretch }; Array.ForEach(new Style[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p))); } - return dict; } diff --git a/Wox.Core/UserSettings/UserSettingStorage.cs b/Wox.Core/UserSettings/UserSettingStorage.cs index 32b3a20cc7..1b9f69396c 100644 --- a/Wox.Core/UserSettings/UserSettingStorage.cs +++ b/Wox.Core/UserSettings/UserSettingStorage.cs @@ -55,6 +55,9 @@ namespace Wox.Core.UserSettings [JsonProperty] public string ResultItemFontStretch { get; set; } + [JsonProperty] + public int ThemeAccentMode { get; set; } + [JsonProperty] public double WindowLeft { get; set; } @@ -117,6 +120,8 @@ namespace Wox.Core.UserSettings get { return "config"; } } + + public void IncreaseActivateTimes() { ActivateTimes++; diff --git a/Wox/Helper/WindowIntelopHelper.cs b/Wox/Helper/WindowIntelopHelper.cs index a9dd5ab217..fd40479eca 100644 --- a/Wox/Helper/WindowIntelopHelper.cs +++ b/Wox/Helper/WindowIntelopHelper.cs @@ -121,13 +121,13 @@ namespace Wox.Helper } [DllImport("user32.dll")] internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); - public static void EnableBlur(Window wind) + public static void SetWindowAccent(Window wind, int themeAccentMode) { + if (themeAccentMode < 0 || themeAccentMode > 3) + themeAccentMode = 0; var windowHelper = new WindowInteropHelper(wind); - var accent = new AccentPolicy(); - accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND; - accent.GradientColor = 16711680; + accent.AccentState = (AccentState) themeAccentMode; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 4546d8f797..0d8bf200ac 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -460,6 +460,7 @@ namespace Wox Dispatcher.DelayInvoke("delayChangeTheme", () => { ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); + WindowIntelopHelper.SetWindowAccent(MainWindow, UserSettingStorage.Instance.ThemeAccentMode); }, TimeSpan.FromMilliseconds(100)); } diff --git a/Wox/Themes/Base.xaml b/Wox/Themes/Base.xaml index d0d2b4a8eb..18d1edcb4e 100644 --- a/Wox/Themes/Base.xaml +++ b/Wox/Themes/Base.xaml @@ -27,7 +27,10 @@ + 0 + + + + diff --git a/Wox/Themes/SimpleBlur.xaml b/Wox/Themes/SimpleBlur.xaml index fb8882dd33..ff136a15d2 100644 --- a/Wox/Themes/SimpleBlur.xaml +++ b/Wox/Themes/SimpleBlur.xaml @@ -5,6 +5,9 @@ + + 3 + diff --git a/Wox/Themes/Test.xaml b/Wox/Themes/Test.xaml index 108852a6f5..70bc4aedd5 100644 --- a/Wox/Themes/Test.xaml +++ b/Wox/Themes/Test.xaml @@ -5,8 +5,11 @@ + + 3 + - #FFBBBBBB + Transparent + + - #4F6180 + #356ef3 diff --git a/Wox/Themes/SimpleBlur-White.xaml b/Wox/Themes/SimpleBlur-White.xaml new file mode 100644 index 0000000000..f502115e85 --- /dev/null +++ b/Wox/Themes/SimpleBlur-White.xaml @@ -0,0 +1,55 @@ + + + + + + + 3 + + + + + + + + + + + + + + + #356ef3 + + + + + + From ece09a93cdf7a0ddc80eb99be26d7497a1871f6a Mon Sep 17 00:00:00 2001 From: Boris Makogonyuk Date: Tue, 10 Nov 2015 12:18:03 +0100 Subject: [PATCH 6/6] 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