Skip to content

Commit

Permalink
Fix main window resize boarder thickness issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack251970 committed Feb 7, 2025
1 parent 38eb07a commit 1a39af3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion Flow.Launcher.Core/Resource/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.UserSettings;
using System.Windows.Shell;

namespace Flow.Launcher.Core.Resource
{
Expand Down Expand Up @@ -306,12 +307,15 @@ public void AddDropShadowEffectToCurrentTheme()
var marginSetter = windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == Border.MarginProperty) as Setter;
if (marginSetter == null)
{
var margin = new Thickness(ShadowExtraMargin, 12, ShadowExtraMargin, ShadowExtraMargin);
marginSetter = new Setter()
{
Property = Border.MarginProperty,
Value = new Thickness(ShadowExtraMargin, 12, ShadowExtraMargin, ShadowExtraMargin),
Value = margin,
};
windowBorderStyle.Setters.Add(marginSetter);

SetResizeBoarderThickness(margin);
}
else
{
Expand All @@ -322,6 +326,8 @@ public void AddDropShadowEffectToCurrentTheme()
baseMargin.Right + ShadowExtraMargin,
baseMargin.Bottom + ShadowExtraMargin);
marginSetter.Value = newMargin;

SetResizeBoarderThickness(newMargin);
}

windowBorderStyle.Setters.Add(effectSetter);
Expand Down Expand Up @@ -352,9 +358,36 @@ public void RemoveDropShadowEffectFromCurrentTheme()
marginSetter.Value = newMargin;
}

SetResizeBoarderThickness(null);

UpdateResourceDictionary(dict);
}

// because adding drop shadow effect will change the margin of the window,
// we need to update the window chrome thickness to correct set the resize border
private static void SetResizeBoarderThickness(Thickness? effectMargin)
{
var window = Application.Current.MainWindow;
if (WindowChrome.GetWindowChrome(window) is WindowChrome windowChrome)
{
Thickness thickness;
if (effectMargin == null)
{
thickness = SystemParameters.WindowResizeBorderThickness;
}
else
{
thickness = new Thickness(
effectMargin.Value.Left + SystemParameters.WindowResizeBorderThickness.Left,
effectMargin.Value.Top + SystemParameters.WindowResizeBorderThickness.Top,
effectMargin.Value.Right + SystemParameters.WindowResizeBorderThickness.Right,
effectMargin.Value.Bottom + SystemParameters.WindowResizeBorderThickness.Bottom);
}

windowChrome.ResizeBorderThickness = thickness;
}
}

public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, bool? HasBlur = null);
}
}
2 changes: 1 addition & 1 deletion Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
mc:Ignorable="d">
<!-- WindowChrome -->
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="9" ResizeBorderThickness="32 4 32 32" />
<WindowChrome CaptionHeight="9" />
</WindowChrome.WindowChrome>
<Window.Resources>
<converters:QuerySuggestionBoxConverter x:Key="QuerySuggestionBoxConverter" />
Expand Down

0 comments on commit 1a39af3

Please # to comment.