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] 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 445d033c7..3d1e89a11 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; 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 @@ namespace Flow.Launcher.Core.Resource 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 @@ namespace Flow.Launcher.Core.Resource /* 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;