Base Structure for fluent window

This commit is contained in:
DB p 2025-02-23 09:48:33 +09:00
parent 3e9a0e2c71
commit 270f5b3ca0
6 changed files with 48 additions and 18 deletions

View file

@ -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
/// </summary>
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<Setter>().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<Setter>().FirstOrDefault(x => x.Property.Name == "Background") != null)
{
windowBorderStyle.Setters.Add(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
}
//mainWindow.WindowStyle = WindowStyle.None;
//if (windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background") != null)
//{
// windowBorderStyle.Setters.Add(windowBorderStyle.Setters.OfType<Setter>().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)
{

View file

@ -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'}" />
</Window.InputBindings>
<Border MouseDown="OnMouseDown">
<Border MouseDown="OnMouseDown" Style="{DynamicResource WindowBorderStyle}">
<StackPanel Orientation="Vertical">
<Grid>
<Border MinHeight="30" Style="{DynamicResource QueryBoxBgStyle}">

View file

@ -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

View file

@ -39,6 +39,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel
if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect)
DropShadowEffect = false;
ThemeManager.Instance.RefreshFrame();
}
}

View file

@ -10,8 +10,8 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml" />
</ResourceDictionary.MergedDictionaries>
<system:Boolean x:Key="ThemeBlurEnabled">True</system:Boolean>
<system:String x:Key="BlurMode">Auto</system:String>
<Style x:Key="WindowRadius" TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="0" />
</Style>

View file

@ -1,7 +1,7 @@
<!--
Name: Windows 11
IsDark: True
HasBlur: False
HasBlur: True
-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@ -12,6 +12,8 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml" />
</ResourceDictionary.MergedDictionaries>
<system:Boolean x:Key="ThemeBlurEnabled">True</system:Boolean>
<system:String x:Key="BlurMode">Auto</system:String>
<Style
x:Key="BulletStyle"
BasedOn="{StaticResource BaseBulletStyle}"