From 270f5b3ca07f4fe51079295a48f4948f46674dd2 Mon Sep 17 00:00:00 2001 From: DB p Date: Sun, 23 Feb 2025 09:48:33 +0900 Subject: [PATCH] Base Structure for fluent window --- Flow.Launcher.Core/Resource/Theme.cs | 52 ++++++++++++++----- Flow.Launcher/MainWindow.xaml | 4 +- Flow.Launcher/MainWindow.xaml.cs | 3 +- .../ViewModels/SettingsPaneThemeViewModel.cs | 1 + Flow.Launcher/Themes/BlurBlack.xaml | 2 +- Flow.Launcher/Themes/Win11Light.xaml | 4 +- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index ed975aa9d..3ebcd65c7 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -15,6 +15,7 @@ using System.Windows.Shell; using static Flow.Launcher.Core.Resource.Theme.ParameterTypes; using System.Runtime.InteropServices; using System.Windows.Interop; +using System.Diagnostics; namespace Flow.Launcher.Core.Resource { @@ -119,8 +120,9 @@ namespace Flow.Launcher.Core.Resource // Remove OS minimizing/maximizing animation Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, 3); + //Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR, 0x00FF0000); - Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 3); + //Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 3); SetBlurForWindow(); } @@ -131,24 +133,26 @@ namespace Flow.Launcher.Core.Resource /// public void SetBlurForWindow() { + //SetWindowAccent(); var dict = GetThemeResourceDictionary(Settings.Theme); var windowBorderStyle = dict["WindowBorderStyle"] as Style; + Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 3); if (BlurEnabled) { + //mainWindow.WindowStyle = WindowStyle.SingleBorderWindow; + BlurColor(BlurMode()); windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property.Name == "Background")); windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.Transparent))); - //mainWindow.WindowStyle = WindowStyle.SingleBorderWindow; Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 3); - BlurColor(BlurMode()); } else { - mainWindow.WindowStyle = WindowStyle.None; - if (windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property.Name == "Background") != null) - { - windowBorderStyle.Setters.Add(windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property.Name == "Background")); - } + //mainWindow.WindowStyle = WindowStyle.None; + //if (windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property.Name == "Background") != null) + //{ + // windowBorderStyle.Setters.Add(windowBorderStyle.Setters.OfType().FirstOrDefault(x => x.Property.Name == "Background")); + //} Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 1); } UpdateResourceDictionary(dict); @@ -156,28 +160,34 @@ namespace Flow.Launcher.Core.Resource public void BlurColor(string Color) { + if (Color == "Light") { + //mainWindow.Background = new SolidColorBrush(defaultBGcolor.Value); Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0); } else if (Color == "Dark") { + //mainWindow.Background = new SolidColorBrush(darkBGcolor.Value); Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1); } else /* Case of "Auto" Blur Type Theme */ { //if (_isDarkTheme()) //{ + // mainWindow.Background = new SolidColorBrush(darkBGcolor.Value); // Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1); //} //else //{ + // mainWindow.Background = new SolidColorBrush(defaultBGcolor.Value); // Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0); //} - Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1); - } + //mainWindow.Background = new SolidColorBrush(Colors.Red); + Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1); } } + public bool IsBlurTheme() { if (Environment.OSVersion.Version >= new Version(6, 2)) @@ -207,6 +217,24 @@ namespace Flow.Launcher.Core.Resource return null; } + //public SolidColorBrush BGColor(string colorBgKey) + //{ + // var defaultBG = Application.Current.TryFindResource("DefaultBG"); + // var darkBG = Application.Current.TryFindResource("DarkBG"); + + // if (colorBgKey == "") + // { + // var resource = Application.Current.TryFindResource("BlurMode"); + + // if (resource is string) + // return (SolidColorBrush)resource; + + // return new SolidColorBrush(Colors.DarkGray); + // } + + // return null; + //} + #endregion private void MakeSureThemeDirectoriesExist() @@ -252,8 +280,8 @@ namespace Flow.Launcher.Core.Resource if (Settings.UseDropShadowEffect && !BlurEnabled) AddDropShadowEffectToCurrentTheme(); - Win32Helper.SetBlurForWindow(Application.Current.MainWindow, BlurEnabled); - //Win32Helper.SetMicaForWindow(Application.Current.MainWindow, BlurEnabled); + //Win32Helper.SetBlurForWindow(Application.Current.MainWindow, BlurEnabled); + SetBlurForWindow(); } catch (DirectoryNotFoundException) { diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 22594217f..d99787a8d 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -16,7 +16,7 @@ d:DataContext="{d:DesignInstance Type=vm:MainViewModel}" AllowDrop="True" AllowsTransparency="False" - Background="#DB213C95" + Background="#E12E2E2E" Closing="OnClosing" Deactivated="OnDeactivated" Icon="Images/app.png" @@ -213,7 +213,7 @@ Modifiers="{Binding CycleHistoryDownHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}" /> - + diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index abb959ad8..8270150c2 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -61,7 +61,6 @@ namespace Flow.Launcher InitSoundEffects(); DataObject.AddPastingHandler(QueryTextBox, OnPaste); - this.Loaded += (_, _) => { var handle = new WindowInteropHelper(this).Handle; @@ -107,6 +106,7 @@ namespace Flow.Launcher return IntPtr.Zero; } + private void OnResizeEnd() { int shadowMargin = 0; @@ -181,7 +181,6 @@ namespace Flow.Launcher private void OnLoaded(object sender, RoutedEventArgs _) { - // Remove OS minimizing/maximizing animation ThemeManager.Instance.RefreshFrame(); // MouseEventHandler diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 8d8ccb780..ab2419d99 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -39,6 +39,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect) DropShadowEffect = false; + ThemeManager.Instance.RefreshFrame(); } } diff --git a/Flow.Launcher/Themes/BlurBlack.xaml b/Flow.Launcher/Themes/BlurBlack.xaml index 5d0fc2c3c..63fb83609 100644 --- a/Flow.Launcher/Themes/BlurBlack.xaml +++ b/Flow.Launcher/Themes/BlurBlack.xaml @@ -10,8 +10,8 @@ - True + Auto diff --git a/Flow.Launcher/Themes/Win11Light.xaml b/Flow.Launcher/Themes/Win11Light.xaml index 4fe3c0495..52758171a 100644 --- a/Flow.Launcher/Themes/Win11Light.xaml +++ b/Flow.Launcher/Themes/Win11Light.xaml @@ -1,7 +1,7 @@ + True + Auto