Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix main window resize border thickness issue #3232

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading