Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 46 additions & 19 deletions Flow.Launcher.Core/Resource/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class Theme
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);
Expand Down Expand Up @@ -88,8 +92,12 @@ public bool ChangeTheme(string theme)
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
}

if (Settings.UseDropShadowEffect)
BlurEnabled = IsBlurTheme();

if (Settings.UseDropShadowEffect && !BlurEnabled)
AddDropShadowEffectToCurrentTheme();

SetBlurForWindow();
}
catch (DirectoryNotFoundException e)
{
Expand Down Expand Up @@ -181,6 +189,21 @@ public ResourceDictionary GetResourceDictionary()
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;
}

Expand Down Expand Up @@ -252,7 +275,7 @@ public void AddDropShadowEffectToCurrentTheme()
UpdateResourceDictionary(dict);
}

public void RemoveDropShadowEffectToCurrentTheme()
public void RemoveDropShadowEffectFromCurrentTheme()
{
var dict = CurrentThemeResourceDictionary();
var windowBorderStyle = dict["WindowBorderStyle"] as Style;
Expand Down Expand Up @@ -320,35 +343,39 @@ private enum WindowCompositionAttribute
/// </summary>
public void SetBlurForWindow()
{
if (BlurEnabled)
{
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND);
}
else
{
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED);
}
Comment on lines +346 to +353
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe only change this if blur state is changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the original code this state is always set though via on_loaded everytime when flow is started, not sure if we really need to manage this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taooceros did you want to show me what you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I forget to reply. I mean only call this method when we switch from Blur to non-blur or non-blur to Blur. Also maybe remove the call of this method in MainWindow.OnLoaded and move that to ChangeTheme

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this method when we switch from Blur to non-blur or non-blur to Blur

there's not really a good way to tell what state blur was previously. is this just so the call is not done multiple times when user cycles through themes? i tested current way there hasnt been any issues.

remove the call of this method in MainWindow.OnLoaded and move that to ChangeTheme

this is already removed.

}

// 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;
}
return (bool)resource;

if (blur)
{
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND);
}
else
{
SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED);
}
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);

Expand Down
1 change: 1 addition & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 0 additions & 2 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ private void OnLoaded(object sender, RoutedEventArgs _)
// 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();
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
2 changes: 2 additions & 0 deletions Flow.Launcher/Themes/Base.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/Themes/BlurBlack Darker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/Themes/BlurBlack.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/Themes/BlurWhite.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
11 changes: 10 additions & 1 deletion Flow.Launcher/ViewModel/SettingWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ public string SelectedTheme
{
Settings.Theme = value;
ThemeManager.Instance.ChangeTheme(value);

if (ThemeManager.Instance.BlurEnabled && Settings.UseDropShadowEffect)
DropShadowEffect = false;
}
}

Expand All @@ -282,13 +285,19 @@ public bool DropShadowEffect
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;
Expand Down