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

WPFUI / Fluent Window / Theme system / Resizable Window #2635

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion Flow.Launcher.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public class Settings : BaseModel
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
public string ColorScheme { get; set; } = "System";
public string ThemeMode { get; set; } = "Modern";
public bool ShowOpenResultHotkey { get; set; } = true;
public double WindowSize { get; set; } = 580;
public WindowStyle WindowStyle { get; set; } = WindowStyle.None;
public string PreviewHotkey { get; set; } = $"F1";

public string Language
Expand All @@ -43,6 +45,13 @@ public string Theme
}
}
public bool UseDropShadowEffect { get; set; } = false;

/* Appearance Settings. It should be separated from the setting later.*/
public double WindowHeightSize { get; set; } = 40;
public double ItemHeightSize { get; set; } = 58;
public double QueryBoxFontSize { get; set; } = 18;
public double ResultItemFontSize { get; set; } = 16;
public double ResultSubItemFontSize { get; set; } = 13;
public string QueryBoxFont { get; set; } = FontFamily.GenericSansSerif.Name;
public string QueryBoxFontStyle { get; set; }
public string QueryBoxFontWeight { get; set; }
Expand All @@ -51,6 +60,7 @@ public string Theme
public string ResultFontStyle { get; set; }
public string ResultFontWeight { get; set; }
public string ResultFontStretch { get; set; }

public bool UseGlyphIcons { get; set; } = true;
public bool UseAnimation { get; set; } = true;
public bool UseSound { get; set; } = true;
Expand Down Expand Up @@ -278,7 +288,13 @@ public enum ColorSchemes
Light,
Dark
}


public enum ThemeModes
{
Modern,
Legacy
}

public enum SearchWindowScreens
{
RememberLastLaunchLocation,
Expand Down
6 changes: 6 additions & 0 deletions Flow.Launcher/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
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:uix="http://schemas.lepo.co/wpfui/2022/xaml"
ShutdownMode="OnMainWindowClose"
Startup="OnStartupAsync">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- WPF UI -->
<uix:ThemesDictionary Theme="Dark" />
<uix:ThemesDictionary Theme="Light" />
<uix:ControlsDictionary />
<!-- ModernWPF UI -->
<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.3" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<system:String x:Key="SampleSubTitleProcessKiller">Terminate unwanted processes</system:String>
<system:String x:Key="queryBoxFont">Query Box Font</system:String>
<system:String x:Key="resultItemFont">Result Item Font</system:String>
<system:String x:Key="resultSubItemFont">Item Subtitle Font</system:String>
<system:String x:Key="windowMode">Window Mode</system:String>
<system:String x:Key="opacity">Opacity</system:String>
<system:String x:Key="theme_load_failure_path_not_exists">Theme {0} not exists, fallback to default theme</system:String>
Expand All @@ -168,6 +169,10 @@
<system:String x:Key="AnimationSpeedCustom">Custom</system:String>
<system:String x:Key="Clock">Clock</system:String>
<system:String x:Key="Date">Date</system:String>
<system:String x:Key="ThemeModeTitle">Theme Mode (Beta)</system:String>
<system:String x:Key="ThemeModeTip">Select the window rendering method. Modern mode is available in Windows 10 and later versions. There are differences in some features.</system:String>
<system:String x:Key="ThemeModeModern">Modern</system:String>
<system:String x:Key="ThemeModeLegacy">Legacy</system:String>

<!-- Setting Hotkey -->
<system:String x:Key="hotkey">Hotkey</system:String>
Expand Down
628 changes: 320 additions & 308 deletions Flow.Launcher/MainWindow.xaml

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
using DataObject = System.Windows.DataObject;
using System.Windows.Media;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Threading;
using Wpf.Ui.Appearance;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Window = System.Windows.Window;
using Windows.UI.Composition;
using Wpf.Ui.Controls;
using MenuItem = System.Windows.Controls.MenuItem;
using FontIcon = ModernWpf.Controls.FontIcon;
using System.Diagnostics;

namespace Flow.Launcher
{
Expand All @@ -45,6 +56,10 @@ 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;
Expand All @@ -57,8 +72,19 @@ public MainWindow(Settings settings, MainViewModel mainVM)
animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));

DataObject.AddPastingHandler(QueryTextBox, OnPaste);
this.Loaded += (obj, args) =>
{
var handle = new WindowInteropHelper(this).Handle;
var win = HwndSource.FromHwnd(handle);
win.AddHook(new HwndSourceHook(WndProc));
};
}

DispatcherTimer timer = new DispatcherTimer
{
Interval = new TimeSpan(0, 0, 0, 0, 500),
IsEnabled = false
};
public MainWindow()
{
InitializeComponent();
Expand Down Expand Up @@ -107,6 +133,12 @@ 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 @@ -717,5 +749,62 @@ private void QueryTextBox_KeyUp(object sender, KeyEventArgs e)
be.UpdateSource();
}
}

private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
/*_settings.WindowSize = Width;*/
/*_settings.MaxResultsToShow = System.Convert.ToInt32(Height / _settings.ItemHeightSize);*/

/*FlowMainWindow.SizeToContent = SizeToContent.Height;*/
/*IntPtr WinHandle = new WindowInteropHelper(this).Handle;*/
/*
var backgroundBrush = FlowMainWindow.Resources["ApplicationBackgroundBrush"];
backgroundBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x20, 0x20, 0x20));
HwndSource.FromHwnd(WinHandle).CompositionTarget.BackgroundColor = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
WindowBackdrop.RemoveBackdrop(FlowMainWindow);
FlowMainWindow.Resources["ApplicationBackgroundColor"] = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);*/
}

private const int WM_ENTERSIZEMOVE = 0x0231;
private const int WM_EXITSIZEMOVE = 0x0232;
public event EventHandler ResizeBegin;
public event EventHandler ResizeEnd;
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_ENTERSIZEMOVE)
{
OnResizeBegin();
handled = true;
}
if (msg == WM_EXITSIZEMOVE)
{
OnResizeEnd();
handled = true;
}
return IntPtr.Zero;
}
private void OnResizeBegin()
{
Debug.WriteLine("------------------RESIZE BEGIN-----------------------");
//Any custom logic for resize begin
}
private void OnResizeEnd()
{
Debug.WriteLine("------------------END-----------------------");
Debug.WriteLine(System.Convert.ToInt32((Height - (_settings.WindowHeightSize + 14)) / _settings.ItemHeightSize));
Debug.WriteLine("----------------------------------------------------");
//_settings.MaxResultsToShow = System.Convert.ToInt32((Height - (_settings.WindowHeightSize + 14)) / _settings.ItemHeightSize);
if (System.Convert.ToInt32((Height - (_settings.WindowHeightSize + 14)) / _settings.ItemHeightSize) == 0)
{
_settings.MaxResultsToShow = 1;
}
else
{
_settings.MaxResultsToShow = System.Convert.ToInt32((Height - (_settings.WindowHeightSize + 14)) / _settings.ItemHeightSize);
}
_settings.WindowSize = Width;
FlowMainWindow.SizeToContent = SizeToContent.Height;
//Any custom logic for resize begin
}
}
}
4 changes: 3 additions & 1 deletion Flow.Launcher/ResultListBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
Grid.Row="0"
VerticalAlignment="Center"
DockPanel.Dock="Left"
FontSize="{Binding ResultItemFontSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="False"
Style="{DynamicResource ItemTitleStyle}"
Text="{Binding Result.Title}"
Expand All @@ -191,6 +192,7 @@
<TextBlock
x:Name="SubTitle"
Grid.Row="1"
FontSize="{Binding ResultSubItemFontSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="False"
Style="{DynamicResource ItemSubTitleStyle}"
Text="{Binding Result.SubTitle}"
Expand Down Expand Up @@ -219,7 +221,7 @@
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="MouseEnter" Handler="OnMouseEnter" />
<EventSetter Event="MouseMove" Handler="OnMouseMove" />
<Setter Property="Height" Value="{DynamicResource ResultItemHeight}" />
<Setter Property="Height" Value="{Binding ItemHeightSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="BorderThickness" Value="0" />
Expand Down