Skip to content

Commit 3bbffe8

Browse files
authored
Merge pull request #498 from Flow-Launcher/auto_disable_shadow
auto disable shadow when blur is enabled
2 parents b75618c + b5272dd commit 3bbffe8

File tree

10 files changed

+61
-27
lines changed

10 files changed

+61
-27
lines changed

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public class Theme
2828
private string DirectoryPath => Path.Combine(Constant.ProgramDirectory, Folder);
2929
private string UserDirectoryPath => Path.Combine(DataLocation.DataDirectory(), Folder);
3030

31+
public bool BlurEnabled { get; set; }
32+
33+
private double mainWindowWidth;
34+
3135
public Theme()
3236
{
3337
_themeDirectories.Add(DirectoryPath);
@@ -88,8 +92,12 @@ public bool ChangeTheme(string theme)
8892
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
8993
}
9094

91-
if (Settings.UseDropShadowEffect)
95+
BlurEnabled = IsBlurTheme();
96+
97+
if (Settings.UseDropShadowEffect && !BlurEnabled)
9298
AddDropShadowEffectToCurrentTheme();
99+
100+
SetBlurForWindow();
93101
}
94102
catch (DirectoryNotFoundException e)
95103
{
@@ -181,6 +189,21 @@ public ResourceDictionary GetResourceDictionary()
181189
Array.ForEach(new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
182190
}
183191

192+
var windowStyle = dict["WindowStyle"] as Style;
193+
194+
var width = windowStyle?.Setters.OfType<Setter>().Where(x => x.Property.Name == "Width")
195+
.Select(x => x.Value).FirstOrDefault();
196+
197+
if (width == null)
198+
{
199+
windowStyle = dict["BaseWindowStyle"] as Style;
200+
201+
width = windowStyle?.Setters.OfType<Setter>().Where(x => x.Property.Name == "Width")
202+
.Select(x => x.Value).FirstOrDefault();
203+
}
204+
205+
mainWindowWidth = (double)width;
206+
184207
return dict;
185208
}
186209

@@ -252,7 +275,7 @@ public void AddDropShadowEffectToCurrentTheme()
252275
UpdateResourceDictionary(dict);
253276
}
254277

255-
public void RemoveDropShadowEffectToCurrentTheme()
278+
public void RemoveDropShadowEffectFromCurrentTheme()
256279
{
257280
var dict = CurrentThemeResourceDictionary();
258281
var windowBorderStyle = dict["WindowBorderStyle"] as Style;
@@ -320,35 +343,39 @@ private enum WindowCompositionAttribute
320343
/// </summary>
321344
public void SetBlurForWindow()
322345
{
346+
if (BlurEnabled)
347+
{
348+
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND);
349+
}
350+
else
351+
{
352+
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED);
353+
}
354+
}
323355

324-
// Exception of FindResource can't be cathed if global exception handle is set
356+
private bool IsBlurTheme()
357+
{
325358
if (Environment.OSVersion.Version >= new Version(6, 2))
326359
{
327360
var resource = Application.Current.TryFindResource("ThemeBlurEnabled");
328-
bool blur;
361+
329362
if (resource is bool)
330-
{
331-
blur = (bool)resource;
332-
}
333-
else
334-
{
335-
blur = false;
336-
}
363+
return (bool)resource;
337364

338-
if (blur)
339-
{
340-
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND);
341-
}
342-
else
343-
{
344-
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED);
345-
}
365+
return false;
346366
}
367+
368+
return false;
347369
}
348370

349371
private void SetWindowAccent(Window w, AccentState state)
350372
{
351373
var windowHelper = new WindowInteropHelper(w);
374+
375+
// this determines the width of the main query window
376+
w.Width = mainWindowWidth;
377+
windowHelper.EnsureHandle();
378+
352379
var accent = new AccentPolicy { AccentState = state };
353380
var accentStructSize = Marshal.SizeOf(accent);
354381

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<system:String x:Key="querySearchPrecision">Query Search Precision</system:String>
4040
<system:String x:Key="ShouldUsePinyin">Should Use Pinyin</system:String>
4141
<system:String x:Key="ShouldUsePinyinToolTip">Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for transliterating Chinese</system:String>
42+
<system:String x:Key="shadowEffectNotAllowed">Shadow effect is not allowed while current theme has blur effect enabled</system:String>
4243

4344
<!--Setting Plugin-->
4445
<system:String x:Key="plugin">Plugin</system:String>

Flow.Launcher/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<KeyBinding Key="D8" Modifiers="{Binding OpenResultCommandModifiers}" Command="{Binding OpenResultCommand}" CommandParameter="7"></KeyBinding>
6161
<KeyBinding Key="D9" Modifiers="{Binding OpenResultCommandModifiers}" Command="{Binding OpenResultCommand}" CommandParameter="8"></KeyBinding>
6262
</Window.InputBindings>
63-
<Grid Width="750">
63+
<Grid>
6464
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown" CornerRadius="5" >
6565
<StackPanel Orientation="Vertical">
6666
<Grid>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ private void OnLoaded(object sender, RoutedEventArgs _)
6161
// show notify icon when flowlauncher is hidden
6262
InitializeNotifyIcon();
6363

64-
// todo is there a way to set blur only once?
65-
ThemeManager.Instance.SetBlurForWindow();
6664
WindowsInteropHelper.DisableControlBox(this);
6765
InitProgressbarAnimation();
6866
InitializePosition();

Flow.Launcher/SettingWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
<RowDefinition Height="30"/>
243243
</Grid.RowDefinitions>
244244
<TextBlock Grid.Row="0" Text="{DynamicResource queryWindowShadowEffect}" Margin="0 30 0 0" FontSize="14" />
245-
<ui:ToggleSwitch Grid.Row="0" IsOn="{Binding DropShadowEffect}" Margin="210 23 0 0" Width="80"/>
245+
<ui:ToggleSwitch Grid.Row="0" IsOn="{Binding DropShadowEffect, Mode=TwoWay}" Margin="210 23 0 0" Width="80"/>
246246
<TextBlock Grid.Row="1" Text="{DynamicResource shadowEffectCPUUsage}"
247247
Width="280"
248248
FontSize="10" HorizontalAlignment="Left"/>

Flow.Launcher/Themes/Base.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
<Setter Property="Padding" Value="8 10 8 8" />
4747
</Style>
4848
<Style x:Key="BaseWindowStyle" TargetType="{x:Type Window}">
49+
<Setter Property="Width" Value="750" />
50+
<Setter Property="RenderOptions.ClearTypeHint" Value="Enabled"/>
4951
</Style>
5052

5153
<Style x:Key="BasePendingLineStyle" TargetType="{x:Type Line}">

Flow.Launcher/Themes/BlurBlack Darker.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
</Style>
2626

2727
<Style x:Key="WindowStyle" BasedOn="{StaticResource BaseWindowStyle}" TargetType="{x:Type Window}">
28-
<Setter Property="Width" Value="750" /> <!-- This is used to set the blur width only -->
2928
<Setter Property="Background">
3029
<Setter.Value>
3130
<SolidColorBrush Color="Black" Opacity="0.6"/>

Flow.Launcher/Themes/BlurBlack.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
</Style>
2626

2727
<Style x:Key="WindowStyle" BasedOn="{StaticResource BaseWindowStyle}" TargetType="{x:Type Window}">
28-
<Setter Property="Width" Value="750" /> <!-- This is used to set the blur width only -->
2928
<Setter Property="Background">
3029
<Setter.Value>
3130
<SolidColorBrush Color="Black" Opacity="0.3"/>

Flow.Launcher/Themes/BlurWhite.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
</Style>
2424

2525
<Style x:Key="WindowStyle" BasedOn="{StaticResource BaseWindowStyle}" TargetType="{x:Type Window}">
26-
<Setter Property="Width" Value="750" /> <!-- This is used to set the blur width only -->
2726
<Setter Property="Background">
2827
<Setter.Value>
2928
<SolidColorBrush Color="White" Opacity="0.5"/>

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ public string SelectedTheme
271271
{
272272
Settings.Theme = value;
273273
ThemeManager.Instance.ChangeTheme(value);
274+
275+
if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect)
276+
DropShadowEffect = false;
274277
}
275278
}
276279

@@ -282,13 +285,19 @@ public bool DropShadowEffect
282285
get { return Settings.UseDropShadowEffect; }
283286
set
284287
{
288+
if (ThemeManager.Instance.BlurEnabled && value)
289+
{
290+
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("shadowEffectNotAllowed"));
291+
return;
292+
}
293+
285294
if (value)
286295
{
287296
ThemeManager.Instance.AddDropShadowEffectToCurrentTheme();
288297
}
289298
else
290299
{
291-
ThemeManager.Instance.RemoveDropShadowEffectToCurrentTheme();
300+
ThemeManager.Instance.RemoveDropShadowEffectFromCurrentTheme();
292301
}
293302

294303
Settings.UseDropShadowEffect = value;

0 commit comments

Comments
 (0)