Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying WPF-UI #2502

Closed
wants to merge 13 commits into from
3 changes: 3 additions & 0 deletions Flow.Launcher/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:ux="http://schemas.lepo.co/wpfui/2022/xaml"
ShutdownMode="OnMainWindowClose"
Startup="OnStartupAsync">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ux:ThemesDictionary Theme="Light" />
<ux:ControlsDictionary />
<ui:ThemeResources>
<ui:ThemeResources.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
Expand Down
1 change: 1 addition & 0 deletions Flow.Launcher/Flow.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
<PackageReference Include="SharpVectors" Version="1.8.2" />
<PackageReference Include="VirtualizingWrapPanel" Version="1.5.8" />
<PackageReference Include="WPF-UI" Version="3.0.0-preview.7" />
</ItemGroup>

<ItemGroup>
Expand Down
29 changes: 16 additions & 13 deletions Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window
<ui:FluentWindow
x:Class="Flow.Launcher.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -7,15 +7,17 @@
xmlns:flowlauncher="clr-namespace:Flow.Launcher"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:ux="http://schemas.modernwpf.com/2019"
xmlns:vm="clr-namespace:Flow.Launcher.ViewModel"
Name="FlowMainWindow"
Title="Flow Launcher"
MinWidth="{Binding MainWindowWidth, Mode=OneWay}"
MaxWidth="{Binding MainWindowWidth, Mode=OneWay}"
d:DataContext="{d:DesignInstance Type=vm:MainViewModel}"
ui:ExtendsContentIntoTitleBar="True"
ui:SizeToContent="Height"
AllowDrop="True"
AllowsTransparency="True"
Background="Transparent"
Closing="OnClosing"
Deactivated="OnDeactivated"
Expand All @@ -27,23 +29,21 @@
PreviewKeyDown="OnKeyDown"
ResizeMode="NoResize"
ShowInTaskbar="False"
SizeToContent="Height"
Style="{DynamicResource WindowStyle}"
Topmost="True"
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
WindowBackdropType="Acrylic"
WindowStartupLocation="Manual"
WindowStyle="None"
mc:Ignorable="d">
<Window.Resources>
<ui:FluentWindow.Resources>
<converters:QuerySuggestionBoxConverter x:Key="QuerySuggestionBoxConverter" />
<converters:BorderClipConverter x:Key="BorderClipConverter" />
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converters:SplitterConverter x:Key="SplitterConverter" />
<converters:BoolToIMEConversionModeConverter x:Key="BoolToIMEConversionModeConverter" />
<converters:BoolToIMEStateConverter x:Key="BoolToIMEStateConverter" />
<converters:StringToKeyBindingConverter x:Key="StringToKeyBindingConverter" />
</Window.Resources>
<Window.InputBindings>
</ui:FluentWindow.Resources>
<ui:FluentWindow.InputBindings>
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
<KeyBinding Key="F5" Command="{Binding ReloadPluginDataCommand}" />
<KeyBinding Key="Tab" Command="{Binding AutocompleteQueryCommand}" />
Expand Down Expand Up @@ -190,9 +190,12 @@
Key="{Binding PreviewHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='key'}"
Command="{Binding TogglePreviewCommand}"
Modifiers="{Binding PreviewHotkey, Converter={StaticResource StringToKeyBindingConverter}, ConverterParameter='modifiers'}" />
</Window.InputBindings>
</ui:FluentWindow.InputBindings>
<Grid>
<Border MouseDown="OnMouseDown" Style="{DynamicResource WindowBorderStyle}">
<Grid MouseDown="OnMouseDown">
<Grid.Background>
<SolidColorBrush Opacity="0.8" Color="{DynamicResource ApplicationBackgroundColor}" />
</Grid.Background>
<StackPanel Orientation="Vertical">
<Grid>
<Border Style="{DynamicResource QueryBoxBgStyle}">
Expand Down Expand Up @@ -496,6 +499,6 @@
</Grid>
</Grid>
</StackPanel>
</Border>
</Grid>
</Grid>
</Window>
</ui:FluentWindow>
35 changes: 15 additions & 20 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
using Key = System.Windows.Input.Key;
using System.Media;
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Threading;


namespace Flow.Launcher
{
Expand All @@ -43,8 +47,14 @@ public partial class MainWindow

#endregion

// Remove OS minimizing/maximizing animation
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
private const int DWMWA_TRANSITIONS_FORCEDISABLED = 3;

public MainWindow(Settings settings, MainViewModel mainVM)
{

DataContext = mainVM;
_viewModel = mainVM;
_settings = settings;
Expand Down Expand Up @@ -97,6 +107,11 @@ private void OnInitialized(object sender, EventArgs e)

private void OnLoaded(object sender, RoutedEventArgs _)
{
// Remove OS minimizing/maximizing animation
IntPtr WinHandle = new WindowInteropHelper(this).Handle;
int BOOL_TRUE = 1;
DwmSetWindowAttribute(WinHandle, DWMWA_TRANSITIONS_FORCEDISABLED, ref BOOL_TRUE, Marshal.SizeOf(BOOL_TRUE));

CheckFirstLaunch();
HideStartup();
// show notify icon when flowlauncher is hidden
Expand Down Expand Up @@ -397,21 +412,6 @@ public void WindowAnimator()
_ => _settings.CustomAnimationLength
};

var WindowOpacity = new DoubleAnimation
{
From = 0,
To = 1,
Duration = TimeSpan.FromMilliseconds(animationLength * 2 / 3),
FillBehavior = FillBehavior.Stop
};

var WindowMotion = new DoubleAnimation
{
From = Top + 10,
To = Top,
Duration = TimeSpan.FromMilliseconds(animationLength * 2 / 3),
FillBehavior = FillBehavior.Stop
};
var IconMotion = new DoubleAnimation
{
From = 12,
Expand Down Expand Up @@ -452,16 +452,11 @@ public void WindowAnimator()
Storyboard.SetTargetProperty(ClockOpacity, new PropertyPath(OpacityProperty));
Storyboard.SetTargetName(thicknessAnimation, "ClockPanel");
Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath(MarginProperty));
Storyboard.SetTarget(WindowOpacity, this);
Storyboard.SetTargetProperty(WindowOpacity, new PropertyPath(Window.OpacityProperty));
Storyboard.SetTargetProperty(WindowMotion, new PropertyPath(Window.TopProperty));
Storyboard.SetTargetProperty(IconMotion, new PropertyPath(TopProperty));
Storyboard.SetTargetProperty(IconOpacity, new PropertyPath(OpacityProperty));

clocksb.Children.Add(thicknessAnimation);
clocksb.Children.Add(ClockOpacity);
windowsb.Children.Add(WindowOpacity);
windowsb.Children.Add(WindowMotion);
iconsb.Children.Add(IconMotion);
iconsb.Children.Add(IconOpacity);

Expand Down
37 changes: 37 additions & 0 deletions Flow.Launcher/Themes/Base.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:userSettings="clr-namespace:Flow.Launcher.Infrastructure.UserSettings;assembly=Flow.Launcher.Infrastructure">
<CornerRadius x:Key="ItemRadius">0</CornerRadius>
<Thickness x:Key="ItemMargin">0</Thickness>
Expand Down Expand Up @@ -565,4 +566,40 @@
TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="#8f8f8f" />
</Style>


<Style
x:Key="DefaultFluentWindowStyle"
BasedOn="{StaticResource {x:Type Window}}"
TargetType="{x:Type ui:FluentWindow}">
<Setter Property="Background" Value="{DynamicResource ApplicationBackgroundColor}" />
<Setter Property="Foreground" Value="{DynamicResource WindowForeground}" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Width" Value="1100" />
<Setter Property="MinWidth" Value="460" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<AdornerDecorator>
<ui:ClientAreaBorder
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter x:Name="ContentPresenter" />
</ui:ClientAreaBorder>
</AdornerDecorator>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style BasedOn="{StaticResource DefaultFluentWindowStyle}" TargetType="{x:Type ui:FluentWindow}" />
</ResourceDictionary>
4 changes: 2 additions & 2 deletions Flow.Launcher/Themes/Win11Dark.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml" />
</ResourceDictionary.MergedDictionaries>
<Thickness x:Key="ResultMargin">0 0 0 8</Thickness>
<Color x:Key="ApplicationBackgroundColor">#FF202020</Color>
<SolidColorBrush x:Key="ApplicationBackgroundBrush" Color="{StaticResource ApplicationBackgroundColor}" />
<Style
x:Key="ItemGlyph"
BasedOn="{StaticResource BaseGlyphStyle}"
Expand All @@ -28,7 +30,6 @@
x:Key="QuerySuggestionBoxStyle"
BasedOn="{StaticResource BaseQuerySuggestionBoxStyle}"
TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="#202020" />
<Setter Property="Foreground" Value="#7b7b7b" />
<Setter Property="FontSize" Value="26" />
<Setter Property="Padding" Value="0,4,66,0" />
Expand All @@ -41,7 +42,6 @@
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="#3f3f3f" />
<Setter Property="CornerRadius" Value="5" />
<Setter Property="Background" Value="#202020" />
</Style>
<Style
x:Key="WindowStyle"
Expand Down
2 changes: 2 additions & 0 deletions Flow.Launcher/Themes/Win11Light.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml" />
</ResourceDictionary.MergedDictionaries>
<Thickness x:Key="ResultMargin">0 0 0 8</Thickness>
<Color x:Key="ApplicationBackgroundColor">#FFFAFAFA</Color>
<SolidColorBrush x:Key="ApplicationBackgroundBrush" Color="{StaticResource ApplicationBackgroundColor}" />
<Style
x:Key="ItemGlyph"
BasedOn="{StaticResource BaseGlyphStyle}"
Expand Down
1 change: 0 additions & 1 deletion Flow.Launcher/Themes/Win11System.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
x:Key="QuerySuggestionBoxStyle"
BasedOn="{StaticResource BaseQuerySuggestionBoxStyle}"
TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="{DynamicResource Color01B}" />
<Setter Property="Foreground" Value="{DynamicResource QuerySuggestionBoxForeground}" />
<Setter Property="FontSize" Value="26" />
<Setter Property="Padding" Value="0,4,66,0" />
Expand Down
4 changes: 2 additions & 2 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ public void Show()
{
MainWindowVisibility = Visibility.Visible;

MainWindowOpacity = 1;
//MainWindowOpacity = 1;

MainWindowVisibilityStatus = true;
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
Expand All @@ -1024,7 +1024,7 @@ public void Show()
public async void Hide()
{
// Trick for no delay
MainWindowOpacity = 0;
//MainWindowOpacity = 0;

if (!SelectedIsFromQueryResults())
{
Expand Down