From c9152b8b1c21c99d7ce6b8209c904cab3f7958a3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 3 Mar 2026 15:53:53 +0800 Subject: [PATCH 1/5] Improve font and caret brush setter handling in styles Refactored style management to explicitly remove existing CaretBrush setters before adding new ones, preventing duplicates. Unified font property removal to consistently target Control's font properties, enhancing robustness and consistency for text control styling. --- Flow.Launcher.Core/Resource/Theme.cs | 32 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index c3bb6190f01..7d8db686dbc 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -194,7 +194,7 @@ private static void SetFontProperties(Style style, FontFamily fontFamily, FontSt // Remove existing font-related setters if (isTextBox) { - // First, find the setters to remove and store them in a list + // Find the setters to remove and store them in a list var settersToRemove = style.Setters .OfType() .Where(setter => @@ -204,7 +204,7 @@ private static void SetFontProperties(Style style, FontFamily fontFamily, FontSt setter.Property == Control.FontStretchProperty) .ToList(); - // Remove each found setter one by one + // Remove each found setter one by one foreach (var setter in settersToRemove) { style.Setters.Remove(setter); @@ -216,24 +216,30 @@ private static void SetFontProperties(Style style, FontFamily fontFamily, FontSt style.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight)); style.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch)); - // Set caret brush (retain existing logic) - var caretBrushPropertyValue = style.Setters.OfType().Any(x => x.Property.Name == "CaretBrush"); + // Set caret brush (retain existing logic) + var caretBrushProperty = style.Setters.OfType().Where(x => x.Property.Name == "CaretBrush")? + .FirstOrDefault(); var foregroundPropertyValue = style.Setters.OfType().Where(x => x.Property.Name == "Foreground") .Select(x => x.Value).FirstOrDefault(); - if (!caretBrushPropertyValue && foregroundPropertyValue != null) + if (caretBrushProperty != null && foregroundPropertyValue != null) + { + style.Setters.Remove(caretBrushProperty); style.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue)); + } } else { + // Find the setters to remove and store them in a list var settersToRemove = style.Setters .OfType() .Where(setter => - setter.Property == TextBlock.FontFamilyProperty || - setter.Property == TextBlock.FontStyleProperty || - setter.Property == TextBlock.FontWeightProperty || - setter.Property == TextBlock.FontStretchProperty) + setter.Property == Control.FontFamilyProperty || + setter.Property == Control.FontStyleProperty || + setter.Property == Control.FontWeightProperty || + setter.Property == Control.FontStretchProperty) .ToList(); + // Remove each found setter one by one foreach (var setter in settersToRemove) { style.Setters.Remove(setter); @@ -274,11 +280,15 @@ private ResourceDictionary GetResourceDictionary(string theme) queryBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight)); queryBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch)); - var caretBrushPropertyValue = queryBoxStyle.Setters.OfType().Any(x => x.Property.Name == "CaretBrush"); + var caretBrushProperty = queryBoxStyle.Setters.OfType().Where(x => x.Property.Name == "CaretBrush")? + .FirstOrDefault(); var foregroundPropertyValue = queryBoxStyle.Setters.OfType().Where(x => x.Property.Name == "Foreground") .Select(x => x.Value).FirstOrDefault(); - if (!caretBrushPropertyValue && foregroundPropertyValue != null) //otherwise BaseQueryBoxStyle will handle styling + if (caretBrushProperty != null && foregroundPropertyValue != null) + { + queryBoxStyle.Setters.Remove(caretBrushProperty); queryBoxStyle.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue)); + } // Query suggestion box's font style is aligned with query box querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, fontFamily)); From aff6b20aa067769d050b9ec8e849d4035ba7c527 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 3 Mar 2026 16:02:54 +0800 Subject: [PATCH 2/5] Refactor theme font/style application and window width Move font and style setting logic to ApplyFontSettings for better modularity. Improve window width handling by removing existing setters before applying user settings, preventing duplicates and ensuring cleaner resource dictionaries. --- Flow.Launcher.Core/Resource/Theme.cs | 71 ++++------------------------ 1 file changed, 9 insertions(+), 62 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 7d8db686dbc..fe0d0e9705a 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -259,7 +259,6 @@ private ResourceDictionary GetThemeResourceDictionary(string theme) { Source = new Uri(uri, UriKind.Absolute) }; - return dict; } @@ -267,71 +266,19 @@ private ResourceDictionary GetResourceDictionary(string theme) { var dict = GetThemeResourceDictionary(theme); - if (dict["QueryBoxStyle"] is Style queryBoxStyle && - dict["QuerySuggestionBoxStyle"] is Style querySuggestionBoxStyle) - { - var fontFamily = new FontFamily(_settings.QueryBoxFont); - var fontStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.QueryBoxFontStyle); - var fontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.QueryBoxFontWeight); - var fontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.QueryBoxFontStretch); + /* Apply font settings */ + ApplyFontSettings(dict); - queryBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, fontFamily)); - queryBoxStyle.Setters.Add(new Setter(Control.FontStyleProperty, fontStyle)); - queryBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight)); - queryBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch)); - - var caretBrushProperty = queryBoxStyle.Setters.OfType().Where(x => x.Property.Name == "CaretBrush")? - .FirstOrDefault(); - var foregroundPropertyValue = queryBoxStyle.Setters.OfType().Where(x => x.Property.Name == "Foreground") - .Select(x => x.Value).FirstOrDefault(); - if (caretBrushProperty != null && foregroundPropertyValue != null) + /* Ignore Theme Window Width and use setting */ + if (dict.Contains("WindowStyle") && dict["WindowStyle"] is Style windowStyle) + { + var windowStyleProperty = windowStyle.Setters.OfType().FirstOrDefault(s => s.Property == FrameworkElement.WidthProperty); + if (windowStyleProperty != null) { - queryBoxStyle.Setters.Remove(caretBrushProperty); - queryBoxStyle.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue)); + windowStyle.Setters.Remove(windowStyleProperty); } - - // Query suggestion box's font style is aligned with query box - querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, fontFamily)); - querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontStyleProperty, fontStyle)); - querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, fontWeight)); - querySuggestionBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch)); + windowStyle.Setters.Add(new Setter(FrameworkElement.WidthProperty, _settings.WindowSize)); } - - if (dict["ItemTitleStyle"] is Style resultItemStyle && - dict["ItemTitleSelectedStyle"] is Style resultItemSelectedStyle && - dict["ItemHotkeyStyle"] is Style resultHotkeyItemStyle && - dict["ItemHotkeySelectedStyle"] is Style resultHotkeyItemSelectedStyle) - { - Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(_settings.ResultFont)); - Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.ResultFontStyle)); - Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.ResultFontWeight)); - Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.ResultFontStretch)); - - Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch }; - Array.ForEach( - new[] { resultItemStyle, resultItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o - => Array.ForEach(setters, p => o.Setters.Add(p))); - } - - if ( - dict["ItemSubTitleStyle"] is Style resultSubItemStyle && - dict["ItemSubTitleSelectedStyle"] is Style resultSubItemSelectedStyle) - { - Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(_settings.ResultSubFont)); - Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(_settings.ResultSubFontStyle)); - Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(_settings.ResultSubFontWeight)); - Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(_settings.ResultSubFontStretch)); - - Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch }; - Array.ForEach( - new[] { resultSubItemStyle, resultSubItemSelectedStyle }, o - => Array.ForEach(setters, p => o.Setters.Add(p))); - } - - /* Ignore Theme Window Width and use setting */ - var windowStyle = dict["WindowStyle"] as Style; - var width = _settings.WindowSize; - windowStyle.Setters.Add(new Setter(FrameworkElement.WidthProperty, width)); return dict; } From 913ef1a0bd9abc997a9438948aba2ef85ca739ad Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 3 Mar 2026 16:04:48 +0800 Subject: [PATCH 3/5] Improve style setter property checks for CaretBrush/Foreground Updated logic to compare dependency property objects directly instead of using string property names when identifying and manipulating CaretBrush and Foreground setters. This enhances robustness and reduces risk of errors from string comparisons. --- Flow.Launcher.Core/Resource/Theme.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index fe0d0e9705a..445d033c7f1 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -217,9 +217,9 @@ private static void SetFontProperties(Style style, FontFamily fontFamily, FontSt style.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch)); // Set caret brush (retain existing logic) - var caretBrushProperty = style.Setters.OfType().Where(x => x.Property.Name == "CaretBrush")? + var caretBrushProperty = style.Setters.OfType().Where(x => x.Property == TextBoxBase.CaretBrushProperty)? .FirstOrDefault(); - var foregroundPropertyValue = style.Setters.OfType().Where(x => x.Property.Name == "Foreground") + var foregroundPropertyValue = style.Setters.OfType().Where(x => x.Property == Control.ForegroundProperty) .Select(x => x.Value).FirstOrDefault(); if (caretBrushProperty != null && foregroundPropertyValue != null) { @@ -245,6 +245,7 @@ private static void SetFontProperties(Style style, FontFamily fontFamily, FontSt style.Setters.Remove(setter); } + // Add New font setter style.Setters.Add(new Setter(TextBlock.FontFamilyProperty, fontFamily)); style.Setters.Add(new Setter(TextBlock.FontStyleProperty, fontStyle)); style.Setters.Add(new Setter(TextBlock.FontWeightProperty, fontWeight)); From 1dcaf3d3597c0bb6c0d679a67d8cc98debe8dcd3 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 3 Mar 2026 16:21:04 +0800 Subject: [PATCH 4/5] Improve theme window width setter handling Previously, only the first width setter in WindowStyle was removed, which could leave conflicting width settings. Now, all width setters are removed before adding a new one based on user settings, ensuring the user's preferred window width is always applied. --- Flow.Launcher.Core/Resource/Theme.cs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 445d033c7f1..3d1e89a111e 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Metrics; using System.IO; using System.Linq; -using System.Xml; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -12,6 +12,7 @@ using System.Windows.Media.Effects; using System.Windows.Shell; using System.Windows.Threading; +using System.Xml; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; @@ -217,13 +218,15 @@ private static void SetFontProperties(Style style, FontFamily fontFamily, FontSt style.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch)); // Set caret brush (retain existing logic) - var caretBrushProperty = style.Setters.OfType().Where(x => x.Property == TextBoxBase.CaretBrushProperty)? - .FirstOrDefault(); + var caretBrushPropertySetters = style.Setters.OfType().Where(x => x.Property == TextBoxBase.CaretBrushProperty).ToList(); var foregroundPropertyValue = style.Setters.OfType().Where(x => x.Property == Control.ForegroundProperty) .Select(x => x.Value).FirstOrDefault(); - if (caretBrushProperty != null && foregroundPropertyValue != null) + if (caretBrushPropertySetters.Count > 0 && foregroundPropertyValue != null) { - style.Setters.Remove(caretBrushProperty); + foreach (var setter in caretBrushPropertySetters) + { + style.Setters.Remove(setter); + } style.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue)); } } @@ -273,11 +276,17 @@ private ResourceDictionary GetResourceDictionary(string theme) /* Ignore Theme Window Width and use setting */ if (dict.Contains("WindowStyle") && dict["WindowStyle"] is Style windowStyle) { - var windowStyleProperty = windowStyle.Setters.OfType().FirstOrDefault(s => s.Property == FrameworkElement.WidthProperty); - if (windowStyleProperty != null) + // Remove all width setters + var widthSetters = windowStyle.Setters + .OfType() + .Where(s => s.Property == FrameworkElement.WidthProperty) + .ToList(); + foreach (var setter in widthSetters) { - windowStyle.Setters.Remove(windowStyleProperty); + windowStyle.Setters.Remove(setter); } + + // Add width setter based on user settings windowStyle.Setters.Add(new Setter(FrameworkElement.WidthProperty, _settings.WindowSize)); } return dict; From f5b8a87de490c26fe2ebf9b4e6b4d093a747129a Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 3 Mar 2026 16:31:27 +0800 Subject: [PATCH 5/5] Fix CaretBrush setter logic in theme styles Fixed the logic for setting the CaretBrush property in styles to only add the setter if it does not already exist and a Foreground value is present. This removes unnecessary checks and setter removals, making the code more efficient and easier to maintain. --- Flow.Launcher.Core/Resource/Theme.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 3d1e89a111e..7e9c3bf11ad 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -218,15 +218,11 @@ private static void SetFontProperties(Style style, FontFamily fontFamily, FontSt style.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch)); // Set caret brush (retain existing logic) - var caretBrushPropertySetters = style.Setters.OfType().Where(x => x.Property == TextBoxBase.CaretBrushProperty).ToList(); + var caretBrushPropertyExist = style.Setters.OfType().Any(x => x.Property == TextBoxBase.CaretBrushProperty); var foregroundPropertyValue = style.Setters.OfType().Where(x => x.Property == Control.ForegroundProperty) .Select(x => x.Value).FirstOrDefault(); - if (caretBrushPropertySetters.Count > 0 && foregroundPropertyValue != null) + if (!caretBrushPropertyExist && foregroundPropertyValue != null) { - foreach (var setter in caretBrushPropertySetters) - { - style.Setters.Remove(setter); - } style.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue)); } }