mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #498 from Flow-Launcher/auto_disable_shadow
auto disable shadow when blur is enabled
This commit is contained in:
commit
3bbffe8ed1
10 changed files with 62 additions and 28 deletions
|
|
@ -28,6 +28,10 @@ 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; }
|
||||
|
||||
private double mainWindowWidth;
|
||||
|
||||
public Theme()
|
||||
{
|
||||
_themeDirectories.Add(DirectoryPath);
|
||||
|
|
@ -88,8 +92,12 @@ namespace Flow.Launcher.Core.Resource
|
|||
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
|
||||
}
|
||||
|
||||
if (Settings.UseDropShadowEffect)
|
||||
BlurEnabled = IsBlurTheme();
|
||||
|
||||
if (Settings.UseDropShadowEffect && !BlurEnabled)
|
||||
AddDropShadowEffectToCurrentTheme();
|
||||
|
||||
SetBlurForWindow();
|
||||
}
|
||||
catch (DirectoryNotFoundException e)
|
||||
{
|
||||
|
|
@ -181,6 +189,21 @@ namespace Flow.Launcher.Core.Resource
|
|||
Array.ForEach(new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
|
||||
}
|
||||
|
||||
var windowStyle = dict["WindowStyle"] as Style;
|
||||
|
||||
var width = windowStyle?.Setters.OfType<Setter>().Where(x => x.Property.Name == "Width")
|
||||
.Select(x => x.Value).FirstOrDefault();
|
||||
|
||||
if (width == null)
|
||||
{
|
||||
windowStyle = dict["BaseWindowStyle"] as Style;
|
||||
|
||||
width = windowStyle?.Setters.OfType<Setter>().Where(x => x.Property.Name == "Width")
|
||||
.Select(x => x.Value).FirstOrDefault();
|
||||
}
|
||||
|
||||
mainWindowWidth = (double)width;
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +275,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
UpdateResourceDictionary(dict);
|
||||
}
|
||||
|
||||
public void RemoveDropShadowEffectToCurrentTheme()
|
||||
public void RemoveDropShadowEffectFromCurrentTheme()
|
||||
{
|
||||
var dict = CurrentThemeResourceDictionary();
|
||||
var windowBorderStyle = dict["WindowBorderStyle"] as Style;
|
||||
|
|
@ -320,35 +343,39 @@ 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)
|
||||
{
|
||||
var windowHelper = new WindowInteropHelper(w);
|
||||
|
||||
// this determines the width of the main query window
|
||||
w.Width = mainWindowWidth;
|
||||
windowHelper.EnsureHandle();
|
||||
|
||||
var accent = new AccentPolicy { AccentState = state };
|
||||
var accentStructSize = Marshal.SizeOf(accent);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
<system:String x:Key="querySearchPrecision">Query Search Precision</system:String>
|
||||
<system:String x:Key="ShouldUsePinyin">Should Use Pinyin</system:String>
|
||||
<system:String x:Key="ShouldUsePinyinToolTip">Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for transliterating Chinese</system:String>
|
||||
<system:String x:Key="shadowEffectNotAllowed">Shadow effect is not allowed while current theme has blur effect enabled</system:String>
|
||||
|
||||
<!--Setting Plugin-->
|
||||
<system:String x:Key="plugin">Plugin</system:String>
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@
|
|||
<KeyBinding Key="D8" Modifiers="{Binding OpenResultCommandModifiers}" Command="{Binding OpenResultCommand}" CommandParameter="7"></KeyBinding>
|
||||
<KeyBinding Key="D9" Modifiers="{Binding OpenResultCommandModifiers}" Command="{Binding OpenResultCommand}" CommandParameter="8"></KeyBinding>
|
||||
</Window.InputBindings>
|
||||
<Grid Width="750">
|
||||
<Grid>
|
||||
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown" CornerRadius="5" >
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Grid>
|
||||
|
|
|
|||
|
|
@ -61,8 +61,6 @@ namespace Flow.Launcher
|
|||
// show notify icon when flowlauncher is hidden
|
||||
InitializeNotifyIcon();
|
||||
|
||||
// todo is there a way to set blur only once?
|
||||
ThemeManager.Instance.SetBlurForWindow();
|
||||
WindowsInteropHelper.DisableControlBox(this);
|
||||
InitProgressbarAnimation();
|
||||
InitializePosition();
|
||||
|
|
|
|||
|
|
@ -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"/>
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@
|
|||
<Setter Property="Padding" Value="8 10 8 8" />
|
||||
</Style>
|
||||
<Style x:Key="BaseWindowStyle" TargetType="{x:Type Window}">
|
||||
<Setter Property="Width" Value="750" />
|
||||
<Setter Property="RenderOptions.ClearTypeHint" Value="Enabled"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="BasePendingLineStyle" TargetType="{x:Type Line}">
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
</Style>
|
||||
|
||||
<Style x:Key="WindowStyle" BasedOn="{StaticResource BaseWindowStyle}" TargetType="{x:Type Window}">
|
||||
<Setter Property="Width" Value="750" /> <!-- This is used to set the blur width only -->
|
||||
<Setter Property="Background">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Color="Black" Opacity="0.6"/>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
</Style>
|
||||
|
||||
<Style x:Key="WindowStyle" BasedOn="{StaticResource BaseWindowStyle}" TargetType="{x:Type Window}">
|
||||
<Setter Property="Width" Value="750" /> <!-- This is used to set the blur width only -->
|
||||
<Setter Property="Background">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Color="Black" Opacity="0.3"/>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
</Style>
|
||||
|
||||
<Style x:Key="WindowStyle" BasedOn="{StaticResource BaseWindowStyle}" TargetType="{x:Type Window}">
|
||||
<Setter Property="Width" Value="750" /> <!-- This is used to set the blur width only -->
|
||||
<Setter Property="Background">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Color="White" Opacity="0.5"/>
|
||||
|
|
|
|||
|
|
@ -271,6 +271,9 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
Settings.Theme = value;
|
||||
ThemeManager.Instance.ChangeTheme(value);
|
||||
|
||||
if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect)
|
||||
DropShadowEffect = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -282,13 +285,19 @@ namespace Flow.Launcher.ViewModel
|
|||
get { return Settings.UseDropShadowEffect; }
|
||||
set
|
||||
{
|
||||
if (ThemeManager.Instance.BlurEnabled && value)
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("shadowEffectNotAllowed"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (value)
|
||||
{
|
||||
ThemeManager.Instance.AddDropShadowEffectToCurrentTheme();
|
||||
}
|
||||
else
|
||||
{
|
||||
ThemeManager.Instance.RemoveDropShadowEffectToCurrentTheme();
|
||||
ThemeManager.Instance.RemoveDropShadowEffectFromCurrentTheme();
|
||||
}
|
||||
|
||||
Settings.UseDropShadowEffect = value;
|
||||
|
|
|
|||
Loading…
Reference in a new issue