Skip to content

Commit 6a6d6b2

Browse files
committed
auto disable shadow when blur is enabled
1 parent 4e28b52 commit 6a6d6b2

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ 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+
3133
public Theme()
3234
{
3335
_themeDirectories.Add(DirectoryPath);
@@ -88,7 +90,9 @@ public bool ChangeTheme(string theme)
8890
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
8991
}
9092

91-
if (Settings.UseDropShadowEffect)
93+
BlurEnabled = IsBlurTheme();
94+
95+
if (Settings.UseDropShadowEffect && !BlurEnabled)
9296
AddDropShadowEffectToCurrentTheme();
9397
}
9498
catch (DirectoryNotFoundException e)
@@ -252,7 +256,7 @@ public void AddDropShadowEffectToCurrentTheme()
252256
UpdateResourceDictionary(dict);
253257
}
254258

255-
public void RemoveDropShadowEffectToCurrentTheme()
259+
public void RemoveDropShadowEffectFromCurrentTheme()
256260
{
257261
var dict = CurrentThemeResourceDictionary();
258262
var windowBorderStyle = dict["WindowBorderStyle"] as Style;
@@ -320,30 +324,29 @@ private enum WindowCompositionAttribute
320324
/// </summary>
321325
public void SetBlurForWindow()
322326
{
327+
if (BlurEnabled)
328+
{
329+
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND);
330+
}
331+
else
332+
{
333+
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED);
334+
}
335+
}
323336

324-
// Exception of FindResource can't be cathed if global exception handle is set
337+
private bool IsBlurTheme()
338+
{
325339
if (Environment.OSVersion.Version >= new Version(6, 2))
326340
{
327341
var resource = Application.Current.TryFindResource("ThemeBlurEnabled");
328-
bool blur;
342+
329343
if (resource is bool)
330-
{
331-
blur = (bool)resource;
332-
}
333-
else
334-
{
335-
blur = false;
336-
}
344+
return (bool)resource;
337345

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-
}
346+
return false;
346347
}
348+
349+
return false;
347350
}
348351

349352
private void SetWindowAccent(Window w, AccentState state)

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ 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?
64+
// currently blur can only be called when loading main window.
65+
// is there a way to set blur only once?
6566
ThemeManager.Instance.SetBlurForWindow();
6667
WindowsInteropHelper.DisableControlBox(this);
6768
InitProgressbarAnimation();

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/ViewModel/SettingWindowViewModel.cs

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

@@ -282,13 +286,19 @@ public bool DropShadowEffect
282286
get { return Settings.UseDropShadowEffect; }
283287
set
284288
{
289+
if (ThemeManager.Instance.BlurEnabled && value)
290+
{
291+
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
292+
return;
293+
}
294+
285295
if (value)
286296
{
287297
ThemeManager.Instance.AddDropShadowEffectToCurrentTheme();
288298
}
289299
else
290300
{
291-
ThemeManager.Instance.RemoveDropShadowEffectToCurrentTheme();
301+
ThemeManager.Instance.RemoveDropShadowEffectFromCurrentTheme();
292302
}
293303

294304
Settings.UseDropShadowEffect = value;

0 commit comments

Comments
 (0)