Add theme compatibility code

This commit is contained in:
DB p 2025-02-25 02:42:27 +09:00
parent db5036a3c9
commit 10bbccb787
4 changed files with 137 additions and 15 deletions

View file

@ -16,6 +16,7 @@ using static Flow.Launcher.Core.Resource.Theme.ParameterTypes;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Diagnostics;
using Microsoft.Win32;
namespace Flow.Launcher.Core.Resource
{
@ -128,6 +129,7 @@ namespace Flow.Launcher.Core.Resource
//Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR, 0x00FF0000);
//Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 3);
ThemeModeColor(BlurMode());
SetBlurForWindow();
}
@ -151,7 +153,10 @@ namespace Flow.Launcher.Core.Resource
if (BlurEnabled)
{
//mainWindow.WindowStyle = WindowStyle.SingleBorderWindow;
BlurColor(BlurMode());
//BlurColor(BlurMode());
ThemeModeColor(BlurMode());
Debug.WriteLine("~~~~~~~~~~~~~~~~~~~~");
Debug.WriteLine(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)));
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, 3);
@ -168,6 +173,128 @@ namespace Flow.Launcher.Core.Resource
UpdateResourceDictionary(dict);
}
// WindowBorderStyle에서 Background 색상 가져오는 함수
private Color GetWindowBorderStyleBackground()
{
var Resources = GetThemeResourceDictionary(Settings.Theme);
var windowBorderStyle = (Style)Resources["WindowBorderStyle"];
var backgroundSetter = windowBorderStyle.Setters
.OfType<Setter>()
.FirstOrDefault(s => s.Property == Border.BackgroundProperty);
if (backgroundSetter != null)
{
// Background의 Value가 DynamicColor일 경우 처리
var backgroundValue = backgroundSetter.Value;
if (backgroundValue is SolidColorBrush solidColorBrush)
{
return solidColorBrush.Color; // SolidColorBrush의 Color 반환
}
else if (backgroundValue is DynamicResourceExtension dynamicResource)
{
// DynamicResource Extension을 처리할 때, Key는 리소스에 대한 이름입니다.
var resourceKey = backgroundSetter.Value.ToString();
// 리소스에서 해당 키를 찾아 색상 반환
if (Resources.Contains(resourceKey))
{
var colorResource = Resources[resourceKey];
if (colorResource is SolidColorBrush colorBrush)
{
return colorBrush.Color;
}
else if (colorResource is Color color)
{
return color;
}
}
}
}
return Colors.Transparent; // 기본값: 투명
}
public void ThemeModeColor(string Mode)
{
var dict = GetThemeResourceDictionary(Settings.Theme);
Color lightBG;
Color darkBG;
// lightBG 값을 가져오기 (없으면 WindowBorderStyle의 Background 값 사용)
try
{
// dict["lightBG"] 값이 없거나 null이면 WindowBorderStyle의 Background 값 사용
lightBG = dict.Contains("lightBG") ? (Color)dict["lightBG"] : GetWindowBorderStyleBackground();
}
catch (Exception)
{
// lightBG가 없으면 WindowBorderStyle의 Background 값 사용
lightBG = GetWindowBorderStyleBackground();
}
// darkBG 값을 가져오기 (없으면 lightBG 값으로 설정)
try
{
darkBG = dict.Contains("darkBG") ? (Color)dict["darkBG"] : lightBG;
}
catch (Exception)
{
darkBG = lightBG; // darkBG가 없으면 lightBG 값을 사용
}
if (Mode == "Auto")
{
int themeValue = (int)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 1);
string colorScheme = Settings.ColorScheme;
bool isDarkMode = themeValue == 0; // 0이면 다크 모드
if (colorScheme == "System")
{
if (isDarkMode)
{
mainWindow.Background = new SolidColorBrush(darkBG);
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
return;
}
else
{
mainWindow.Background = new SolidColorBrush(lightBG);
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
return;
}
}
else
{
if (colorScheme == "Dark")
{
mainWindow.Background = new SolidColorBrush(darkBG);
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
return;
}
else if (colorScheme == "Light")
{
mainWindow.Background = new SolidColorBrush(lightBG);
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
return;
}
}
}
else if (Mode == "Dark")
{
mainWindow.Background = new SolidColorBrush(Colors.Green);
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 1);
return;
}
else if (Mode == "Light")
{
mainWindow.Background = new SolidColorBrush(Colors.Yellow);
Methods.SetWindowAttribute(new WindowInteropHelper(mainWindow).Handle, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, 0);
return;
}
}
public void BlurColor(string Color)
{

View file

@ -433,6 +433,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel
Constant.System => null,
_ => ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme
};
ThemeManager.Instance.SetBlurForWindow();
}
public SettingsPaneThemeViewModel(Settings settings)

View file

@ -32,7 +32,7 @@
x:Key="QueryBoxStyle"
BasedOn="{StaticResource BaseQueryBoxStyle}"
TargetType="{x:Type TextBox}">
<Setter Property="Padding" Value="0,4,50,0" />
<Setter Property="Padding" Value="0 4 50 0" />
<Setter Property="CaretBrush" Value="#fa7941" />
<Setter Property="Foreground" Value="#ffffff" />
<Setter Property="FontSize" Value="18" />
@ -43,7 +43,7 @@
x:Key="QuerySuggestionBoxStyle"
BasedOn="{StaticResource BaseQuerySuggestionBoxStyle}"
TargetType="{x:Type TextBox}">
<Setter Property="Padding" Value="0,4,50,0" />
<Setter Property="Padding" Value="0 4 50 0" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="38" />
<Setter Property="FontSize" Value="18" />
@ -56,15 +56,7 @@
TargetType="{x:Type Border}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="BorderBrush" Value="#e2e2e2" />
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0.0" Color="#383838" />
<GradientStop Offset="0.9" Color="#2e2e2e" />
<GradientStop Offset="1.0" Color="#2e2e2e" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="#2e2e2e" />
<Setter Property="CornerRadius" Value="8" />
<Setter Property="UseLayoutRounding" Value="True" />
</Style>
@ -96,7 +88,7 @@
TargetType="{x:Type Rectangle}">
<Setter Property="Fill" Value="#3b3b3b" />
<Setter Property="Height" Value="1" />
<Setter Property="Margin" Value="0,0,0,8" />
<Setter Property="Margin" Value="0 0 0 8" />
</Style>
<Style x:Key="HighlightStyle" />
<Style
@ -147,7 +139,7 @@
<Setter Property="Background" Value="Transparent" />
<Setter Property="Width" Value="32" />
<Setter Property="Height" Value="32" />
<Setter Property="Margin" Value="0,8,8,0" />
<Setter Property="Margin" Value="0 8 8 0" />
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
@ -174,7 +166,7 @@
x:Key="ClockPanel"
BasedOn="{StaticResource ClockPanel}"
TargetType="{x:Type StackPanel}">
<Setter Property="Margin" Value="0,0,54,2" />
<Setter Property="Margin" Value="0 0 54 2" />
</Style>
<Style
x:Key="ClockBox"

View file

@ -14,6 +14,8 @@
</ResourceDictionary.MergedDictionaries>
<system:Boolean x:Key="ThemeBlurEnabled">True</system:Boolean>
<system:String x:Key="BlurMode">Auto</system:String>
<Color x:Key="lightBG">#DFFAFAFA</Color>
<Color x:Key="darkBG">#DD202020</Color>
<Style
x:Key="BulletStyle"
BasedOn="{StaticResource BaseBulletStyle}"