auto disable shadow when blur is enabled

This commit is contained in:
Jeremy 2021-06-27 21:42:37 +10:00
parent 4e28b52e05
commit 6a6d6b22ee
4 changed files with 37 additions and 23 deletions

View file

@ -28,6 +28,8 @@ namespace Flow.Launcher.Core.Resource
private string DirectoryPath => Path.Combine(Constant.ProgramDirectory, Folder); private string DirectoryPath => Path.Combine(Constant.ProgramDirectory, Folder);
private string UserDirectoryPath => Path.Combine(DataLocation.DataDirectory(), Folder); private string UserDirectoryPath => Path.Combine(DataLocation.DataDirectory(), Folder);
public bool BlurEnabled { get; set; }
public Theme() public Theme()
{ {
_themeDirectories.Add(DirectoryPath); _themeDirectories.Add(DirectoryPath);
@ -88,7 +90,9 @@ namespace Flow.Launcher.Core.Resource
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath); _oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
} }
if (Settings.UseDropShadowEffect) BlurEnabled = IsBlurTheme();
if (Settings.UseDropShadowEffect && !BlurEnabled)
AddDropShadowEffectToCurrentTheme(); AddDropShadowEffectToCurrentTheme();
} }
catch (DirectoryNotFoundException e) catch (DirectoryNotFoundException e)
@ -252,7 +256,7 @@ namespace Flow.Launcher.Core.Resource
UpdateResourceDictionary(dict); UpdateResourceDictionary(dict);
} }
public void RemoveDropShadowEffectToCurrentTheme() public void RemoveDropShadowEffectFromCurrentTheme()
{ {
var dict = CurrentThemeResourceDictionary(); var dict = CurrentThemeResourceDictionary();
var windowBorderStyle = dict["WindowBorderStyle"] as Style; var windowBorderStyle = dict["WindowBorderStyle"] as Style;
@ -320,30 +324,29 @@ namespace Flow.Launcher.Core.Resource
/// </summary> /// </summary>
public void SetBlurForWindow() public void SetBlurForWindow()
{ {
if (BlurEnabled)
{
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND);
}
else
{
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED);
}
}
// Exception of FindResource can't be cathed if global exception handle is set private bool IsBlurTheme()
{
if (Environment.OSVersion.Version >= new Version(6, 2)) if (Environment.OSVersion.Version >= new Version(6, 2))
{ {
var resource = Application.Current.TryFindResource("ThemeBlurEnabled"); var resource = Application.Current.TryFindResource("ThemeBlurEnabled");
bool blur;
if (resource is bool)
{
blur = (bool)resource;
}
else
{
blur = false;
}
if (blur) if (resource is bool)
{ return (bool)resource;
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND);
} return false;
else
{
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED);
}
} }
return false;
} }
private void SetWindowAccent(Window w, AccentState state) private void SetWindowAccent(Window w, AccentState state)

View file

@ -61,7 +61,8 @@ namespace Flow.Launcher
// show notify icon when flowlauncher is hidden // show notify icon when flowlauncher is hidden
InitializeNotifyIcon(); InitializeNotifyIcon();
// todo is there a way to set blur only once? // currently blur can only be called when loading main window.
// is there a way to set blur only once?
ThemeManager.Instance.SetBlurForWindow(); ThemeManager.Instance.SetBlurForWindow();
WindowsInteropHelper.DisableControlBox(this); WindowsInteropHelper.DisableControlBox(this);
InitProgressbarAnimation(); InitProgressbarAnimation();

View file

@ -242,7 +242,7 @@
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{DynamicResource queryWindowShadowEffect}" Margin="0 30 0 0" FontSize="14" /> <TextBlock Grid.Row="0" Text="{DynamicResource queryWindowShadowEffect}" Margin="0 30 0 0" FontSize="14" />
<ui:ToggleSwitch Grid.Row="0" IsOn="{Binding DropShadowEffect}" Margin="210 23 0 0" Width="80"/> <ui:ToggleSwitch Grid.Row="0" IsOn="{Binding DropShadowEffect, Mode=TwoWay}" Margin="210 23 0 0" Width="80"/>
<TextBlock Grid.Row="1" Text="{DynamicResource shadowEffectCPUUsage}" <TextBlock Grid.Row="1" Text="{DynamicResource shadowEffectCPUUsage}"
Width="280" Width="280"
FontSize="10" HorizontalAlignment="Left"/> FontSize="10" HorizontalAlignment="Left"/>

View file

@ -271,6 +271,10 @@ namespace Flow.Launcher.ViewModel
{ {
Settings.Theme = value; Settings.Theme = value;
ThemeManager.Instance.ChangeTheme(value); ThemeManager.Instance.ChangeTheme(value);
if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect)
DropShadowEffect = false;
} }
} }
@ -282,13 +286,19 @@ namespace Flow.Launcher.ViewModel
get { return Settings.UseDropShadowEffect; } get { return Settings.UseDropShadowEffect; }
set set
{ {
if (ThemeManager.Instance.BlurEnabled && value)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
return;
}
if (value) if (value)
{ {
ThemeManager.Instance.AddDropShadowEffectToCurrentTheme(); ThemeManager.Instance.AddDropShadowEffectToCurrentTheme();
} }
else else
{ {
ThemeManager.Instance.RemoveDropShadowEffectToCurrentTheme(); ThemeManager.Instance.RemoveDropShadowEffectFromCurrentTheme();
} }
Settings.UseDropShadowEffect = value; Settings.UseDropShadowEffect = value;