Skip to content

Commit 1a97a42

Browse files
committed
Support change resize boarder thinkness
1 parent a4dac91 commit 1a97a42

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Theme
2424
{
2525
#region Properties & Fields
2626

27-
public bool BlurEnabled { get; set; }
27+
public bool BlurEnabled { get; private set; }
2828

2929
private const string ThemeMetadataNamePrefix = "Name:";
3030
private const string ThemeMetadataIsDarkPrefix = "IsDark:";
@@ -42,6 +42,8 @@ public class Theme
4242
private static string DirectoryPath => Path.Combine(Constant.ProgramDirectory, Folder);
4343
private static string UserDirectoryPath => Path.Combine(DataLocation.DataDirectory(), Folder);
4444

45+
private Thickness _themeResizeBorderThickness;
46+
4547
#endregion
4648

4749
#region Constructor
@@ -463,7 +465,7 @@ public void AddDropShadowEffectToCurrentTheme()
463465

464466
var effectSetter = new Setter
465467
{
466-
Property = Border.EffectProperty,
468+
Property = UIElement.EffectProperty,
467469
Value = new DropShadowEffect
468470
{
469471
Opacity = 0.3,
@@ -473,12 +475,12 @@ public void AddDropShadowEffectToCurrentTheme()
473475
}
474476
};
475477

476-
if (windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == Border.MarginProperty) is not Setter marginSetter)
478+
if (windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == FrameworkElement.MarginProperty) is not Setter marginSetter)
477479
{
478480
var margin = new Thickness(ShadowExtraMargin, 12, ShadowExtraMargin, ShadowExtraMargin);
479481
marginSetter = new Setter()
480482
{
481-
Property = Border.MarginProperty,
483+
Property = FrameworkElement.MarginProperty,
482484
Value = margin,
483485
};
484486
windowBorderStyle.Setters.Add(marginSetter);
@@ -508,12 +510,12 @@ public void RemoveDropShadowEffectFromCurrentTheme()
508510
var dict = GetCurrentResourceDictionary();
509511
var windowBorderStyle = dict["WindowBorderStyle"] as Style;
510512

511-
if (windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == Border.EffectProperty) is Setter effectSetter)
513+
if (windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == UIElement.EffectProperty) is Setter effectSetter)
512514
{
513515
windowBorderStyle.Setters.Remove(effectSetter);
514516
}
515517

516-
if (windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == Border.MarginProperty) is Setter marginSetter)
518+
if (windowBorderStyle.Setters.FirstOrDefault(setterBase => setterBase is Setter setter && setter.Property == FrameworkElement.MarginProperty) is Setter marginSetter)
517519
{
518520
var currentMargin = (Thickness)marginSetter.Value;
519521
var newMargin = new Thickness(
@@ -529,28 +531,41 @@ public void RemoveDropShadowEffectFromCurrentTheme()
529531
UpdateResourceDictionary(dict);
530532
}
531533

534+
public void SetResizeBoarderThickness(WindowChrome windowChrome, bool resizeWindow)
535+
{
536+
if (resizeWindow)
537+
{
538+
windowChrome.ResizeBorderThickness = _themeResizeBorderThickness;
539+
}
540+
else
541+
{
542+
windowChrome.ResizeBorderThickness = new Thickness(0);
543+
}
544+
}
545+
532546
// because adding drop shadow effect will change the margin of the window,
533547
// we need to update the window chrome thickness to correct set the resize border
534-
private static void SetResizeBoarderThickness(Thickness? effectMargin)
548+
private void SetResizeBoarderThickness(Thickness? effectMargin)
535549
{
536550
var window = Application.Current.MainWindow;
537551
if (WindowChrome.GetWindowChrome(window) is WindowChrome windowChrome)
538552
{
539-
Thickness thickness;
553+
// Save the theme resize border thickness so that we can restore it if we change ResizeWindow setting
540554
if (effectMargin == null)
541555
{
542-
thickness = SystemParameters.WindowResizeBorderThickness;
556+
_themeResizeBorderThickness = SystemParameters.WindowResizeBorderThickness;
543557
}
544558
else
545559
{
546-
thickness = new Thickness(
560+
_themeResizeBorderThickness = new Thickness(
547561
effectMargin.Value.Left + SystemParameters.WindowResizeBorderThickness.Left,
548562
effectMargin.Value.Top + SystemParameters.WindowResizeBorderThickness.Top,
549563
effectMargin.Value.Right + SystemParameters.WindowResizeBorderThickness.Right,
550564
effectMargin.Value.Bottom + SystemParameters.WindowResizeBorderThickness.Bottom);
551565
}
552566

553-
windowChrome.ResizeBorderThickness = thickness;
567+
// Apply the resize border thickness to the window chrome
568+
SetResizeBoarderThickness(windowChrome, _settings.ResizeWindow);
554569
}
555570
}
556571

@@ -582,7 +597,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
582597
{
583598
AutoDropShadow(useDropShadowEffect);
584599
}
585-
}, DispatcherPriority.Normal);
600+
}, DispatcherPriority.Render);
586601
}
587602

588603
/// <summary>
@@ -596,7 +611,7 @@ await Application.Current.Dispatcher.InvokeAsync(() =>
596611
var (backdropType, _) = GetActualValue();
597612

598613
SetBlurForWindow(GetCurrentTheme(), backdropType);
599-
}, DispatcherPriority.Normal);
614+
}, DispatcherPriority.Render);
600615
}
601616

602617
/// <summary>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Windows.Media;
1212
using System.Windows.Media.Animation;
1313
using System.Windows.Shapes;
14+
using System.Windows.Shell;
1415
using System.Windows.Threading;
1516
using CommunityToolkit.Mvvm.DependencyInjection;
1617
using Flow.Launcher.Core.Plugin;
@@ -115,9 +116,6 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
115116
welcomeWindow.Show();
116117
}
117118

118-
// Initialize resize mode
119-
SetupResizeMode();
120-
121119
// Initialize place holder
122120
SetupPlaceholderText();
123121

@@ -152,13 +150,17 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
152150
UpdatePosition();
153151

154152
// Refresh frame
155-
await Ioc.Default.GetRequiredService<Theme>().RefreshFrameAsync();
153+
await _theme.RefreshFrameAsync();
154+
155+
// Initialize resize mode after refreshing frame
156+
SetupResizeMode();
156157

157158
// Reset preview
158159
_viewModel.ResetPreview();
159160

160161
// Since the default main window visibility is visible, so we need set focus during startup
161162
QueryTextBox.Focus();
163+
162164
// Set the initial state of the QueryTextBoxCursorMovedToEnd property
163165
// Without this part, when shown for the first time, switching the context menu does not move the cursor to the end.
164166
_viewModel.QueryTextCursorMovedToEnd = false;
@@ -1082,6 +1084,10 @@ private void SetPlaceholderText()
10821084
private void SetupResizeMode()
10831085
{
10841086
ResizeMode = _settings.ResizeWindow ? ResizeMode.CanResize : ResizeMode.NoResize;
1087+
if (WindowChrome.GetWindowChrome(this) is WindowChrome windowChrome)
1088+
{
1089+
_theme.SetResizeBoarderThickness(windowChrome, _settings.ResizeWindow);
1090+
}
10851091
}
10861092

10871093
#endregion

0 commit comments

Comments
 (0)