diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 01661678b..2ca0f2551 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -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().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() + .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) { diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index ab2419d99..43d00cf4b 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -433,6 +433,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel Constant.System => null, _ => ThemeManagerForColorSchemeSwitch.Current.ApplicationTheme }; + ThemeManager.Instance.SetBlurForWindow(); } public SettingsPaneThemeViewModel(Settings settings) diff --git a/Flow.Launcher/Themes/Ubuntu.xaml b/Flow.Launcher/Themes/Ubuntu.xaml index 3c9e0a125..4007370f9 100644 --- a/Flow.Launcher/Themes/Ubuntu.xaml +++ b/Flow.Launcher/Themes/Ubuntu.xaml @@ -32,7 +32,7 @@ x:Key="QueryBoxStyle" BasedOn="{StaticResource BaseQueryBoxStyle}" TargetType="{x:Type TextBox}"> - + @@ -43,7 +43,7 @@ x:Key="QuerySuggestionBoxStyle" BasedOn="{StaticResource BaseQuerySuggestionBoxStyle}" TargetType="{x:Type TextBox}"> - + @@ -56,15 +56,7 @@ TargetType="{x:Type Border}"> - - - - - - - - - + @@ -96,7 +88,7 @@ TargetType="{x:Type Rectangle}"> - + @@ -174,7 +166,7 @@ x:Key="ClockPanel" BasedOn="{StaticResource ClockPanel}" TargetType="{x:Type StackPanel}"> - +