mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #4319 from Flow-Launcher/FreezeResources1
Freeze SolidColorBrush to improve performance
This commit is contained in:
commit
0ddcc5c1c6
2 changed files with 39 additions and 24 deletions
|
|
@ -673,13 +673,13 @@ namespace Flow.Launcher.Core.Resource
|
||||||
// If the BackdropType is Mica or MicaAlt, set the windowborderstyle's background to transparent
|
// If the BackdropType is Mica or MicaAlt, set the windowborderstyle's background to transparent
|
||||||
if (backdropType == BackdropTypes.Mica || backdropType == BackdropTypes.MicaAlt)
|
if (backdropType == BackdropTypes.Mica || backdropType == BackdropTypes.MicaAlt)
|
||||||
{
|
{
|
||||||
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
|
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property == Control.BackgroundProperty));
|
||||||
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Color.FromArgb(1, 0, 0, 0))));
|
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, ThemeHelper.GetFrozenSolidColorBrush(Color.FromArgb(1, 0, 0, 0))));
|
||||||
}
|
}
|
||||||
else if (backdropType == BackdropTypes.Acrylic)
|
else if (backdropType == BackdropTypes.Acrylic)
|
||||||
{
|
{
|
||||||
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background"));
|
windowBorderStyle.Setters.Remove(windowBorderStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property == Control.BackgroundProperty));
|
||||||
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(Colors.Transparent)));
|
windowBorderStyle.Setters.Add(new Setter(Border.BackgroundProperty, Brushes.Transparent));
|
||||||
}
|
}
|
||||||
|
|
||||||
// For themes with blur enabled, the window border is rendered by the system, so it's treated as a simple rectangle regardless of thickness.
|
// For themes with blur enabled, the window border is rendered by the system, so it's treated as a simple rectangle regardless of thickness.
|
||||||
|
|
@ -798,12 +798,12 @@ namespace Flow.Launcher.Core.Resource
|
||||||
Application.Current.Resources["WindowBorderStyle"] is Style originalStyle)
|
Application.Current.Resources["WindowBorderStyle"] is Style originalStyle)
|
||||||
{
|
{
|
||||||
// Copy the original style, including the base style if it exists
|
// Copy the original style, including the base style if it exists
|
||||||
CopyStyle(originalStyle, previewStyle);
|
ThemeHelper.CopyStyle(originalStyle, previewStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply background color (remove transparency in color)
|
// Apply background color (remove transparency in color)
|
||||||
Color backgroundColor = Color.FromRgb(bgColor.Value.R, bgColor.Value.G, bgColor.Value.B);
|
var backgroundColor = Color.FromRgb(bgColor.Value.R, bgColor.Value.G, bgColor.Value.B);
|
||||||
previewStyle.Setters.Add(new Setter(Border.BackgroundProperty, new SolidColorBrush(backgroundColor)));
|
previewStyle.Setters.Add(new Setter(Border.BackgroundProperty, ThemeHelper.GetFrozenSolidColorBrush(backgroundColor)));
|
||||||
|
|
||||||
// The blur theme keeps the corner round fixed (applying DWM code to modify it causes rendering issues).
|
// The blur theme keeps the corner round fixed (applying DWM code to modify it causes rendering issues).
|
||||||
// The non-blur theme retains the previously set WindowBorderStyle.
|
// The non-blur theme retains the previously set WindowBorderStyle.
|
||||||
|
|
@ -817,21 +817,6 @@ namespace Flow.Launcher.Core.Resource
|
||||||
Application.Current.Resources["PreviewWindowBorderStyle"] = previewStyle;
|
Application.Current.Resources["PreviewWindowBorderStyle"] = previewStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyStyle(Style originalStyle, Style targetStyle)
|
|
||||||
{
|
|
||||||
// If the style is based on another style, copy the base style first
|
|
||||||
if (originalStyle.BasedOn != null)
|
|
||||||
{
|
|
||||||
CopyStyle(originalStyle.BasedOn, targetStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy the setters from the original style
|
|
||||||
foreach (var setter in originalStyle.Setters.OfType<Setter>())
|
|
||||||
{
|
|
||||||
targetStyle.Setters.Add(new Setter(setter.Property, setter.Value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ColorizeWindow(string theme, BackdropTypes backdropType)
|
private void ColorizeWindow(string theme, BackdropTypes backdropType)
|
||||||
{
|
{
|
||||||
var dict = GetThemeResourceDictionary(theme);
|
var dict = GetThemeResourceDictionary(theme);
|
||||||
|
|
@ -917,11 +902,11 @@ namespace Flow.Launcher.Core.Resource
|
||||||
// Only set the background to transparent if the theme supports blur
|
// Only set the background to transparent if the theme supports blur
|
||||||
if (backdropType == BackdropTypes.Mica || backdropType == BackdropTypes.MicaAlt)
|
if (backdropType == BackdropTypes.Mica || backdropType == BackdropTypes.MicaAlt)
|
||||||
{
|
{
|
||||||
mainWindow.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
|
mainWindow.Background = ThemeHelper.GetFrozenSolidColorBrush(Color.FromArgb(1, 0, 0, 0));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mainWindow.Background = new SolidColorBrush(selectedBG);
|
mainWindow.Background = ThemeHelper.GetFrozenSolidColorBrush(selectedBG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
30
Flow.Launcher.Core/Resource/ThemeHelper.cs
Normal file
30
Flow.Launcher.Core/Resource/ThemeHelper.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
using System.Linq;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace Flow.Launcher.Core.Resource;
|
||||||
|
|
||||||
|
public static class ThemeHelper
|
||||||
|
{
|
||||||
|
public static void CopyStyle(Style originalStyle, Style targetStyle)
|
||||||
|
{
|
||||||
|
// If the style is based on another style, copy the base style first
|
||||||
|
if (originalStyle.BasedOn != null)
|
||||||
|
{
|
||||||
|
CopyStyle(originalStyle.BasedOn, targetStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the setters from the original style
|
||||||
|
foreach (var setter in originalStyle.Setters.OfType<Setter>())
|
||||||
|
{
|
||||||
|
targetStyle.Setters.Add(new Setter(setter.Property, setter.Value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SolidColorBrush GetFrozenSolidColorBrush(Color color)
|
||||||
|
{
|
||||||
|
var brush = new SolidColorBrush(color);
|
||||||
|
brush.Freeze();
|
||||||
|
return brush;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue