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 UserDirectoryPath => Path.Combine(DataLocation.DataDirectory(), Folder);
public bool BlurEnabled { get; set; }
public Theme()
{
_themeDirectories.Add(DirectoryPath);
@ -88,7 +90,9 @@ namespace Flow.Launcher.Core.Resource
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
}
if (Settings.UseDropShadowEffect)
BlurEnabled = IsBlurTheme();
if (Settings.UseDropShadowEffect && !BlurEnabled)
AddDropShadowEffectToCurrentTheme();
}
catch (DirectoryNotFoundException e)
@ -252,7 +256,7 @@ namespace Flow.Launcher.Core.Resource
UpdateResourceDictionary(dict);
}
public void RemoveDropShadowEffectToCurrentTheme()
public void RemoveDropShadowEffectFromCurrentTheme()
{
var dict = CurrentThemeResourceDictionary();
var windowBorderStyle = dict["WindowBorderStyle"] as Style;
@ -320,30 +324,29 @@ namespace Flow.Launcher.Core.Resource
/// </summary>
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))
{
var resource = Application.Current.TryFindResource("ThemeBlurEnabled");
bool blur;
if (resource is bool)
{
blur = (bool)resource;
}
else
{
blur = false;
}
if (blur)
{
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND);
}
else
{
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED);
}
if (resource is bool)
return (bool)resource;
return false;
}
return false;
}
private void SetWindowAccent(Window w, AccentState state)

View file

@ -61,7 +61,8 @@ namespace Flow.Launcher
// show notify icon when flowlauncher is hidden
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();
WindowsInteropHelper.DisableControlBox(this);
InitProgressbarAnimation();

View file

@ -242,7 +242,7 @@
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<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}"
Width="280"
FontSize="10" HorizontalAlignment="Left"/>

View file

@ -271,6 +271,10 @@ namespace Flow.Launcher.ViewModel
{
Settings.Theme = 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; }
set
{
if (ThemeManager.Instance.BlurEnabled && value)
{
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
return;
}
if (value)
{
ThemeManager.Instance.AddDropShadowEffectToCurrentTheme();
}
else
{
ThemeManager.Instance.RemoveDropShadowEffectToCurrentTheme();
ThemeManager.Instance.RemoveDropShadowEffectFromCurrentTheme();
}
Settings.UseDropShadowEffect = value;