diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 8ecd6dc4b..1b15a31f6 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; @@ -43,6 +43,11 @@ namespace Flow.Launcher.Infrastructure.UserSettings public bool UseSound { get; set; } = true; public bool FirstLaunch { get; set; } = true; + public double SettingWindowWidth { get; set; } = 1000; + public double SettingWindowHeight { get; set; } = 700; + public double SettingWindowTop { get; set; } = 0; + public double SettingWindowLeft { get; set; } = 0; + public int CustomExplorerIndex { get; set; } = 0; [JsonIgnore] @@ -220,4 +225,4 @@ namespace Flow.Launcher.Infrastructure.UserSettings Light, Dark } -} \ No newline at end of file +} diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index ba6569771..3c2d1834d 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -13,17 +13,19 @@ xmlns:userSettings="clr-namespace:Flow.Launcher.Infrastructure.UserSettings;assembly=Flow.Launcher.Infrastructure" xmlns:vm="clr-namespace:Flow.Launcher.ViewModel" Title="{DynamicResource flowlauncher_settings}" - Width="1000" - Height="700" + Width="{Binding SettingWindowWidth, Mode=TwoWay}" + Height="{Binding SettingWindowHeight, Mode=TwoWay}" MinWidth="900" MinHeight="600" d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}" Closed="OnClosed" Icon="Images\app.ico" + Left="{Binding SettingWindowLeft, Mode=TwoWay}" Loaded="OnLoaded" MouseDown="window_MouseDown" ResizeMode="CanResize" StateChanged="Window_StateChanged" + Top="{Binding SettingWindowTop, Mode=TwoWay}" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 10c9aeffe..b1e18192c 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -12,6 +12,7 @@ using Flow.Launcher.ViewModel; using Microsoft.Win32; using ModernWpf; using System; +using System.Diagnostics; using System.IO; using System.Windows; using System.Windows.Controls; @@ -48,6 +49,7 @@ namespace Flow.Launcher private void OnLoaded(object sender, RoutedEventArgs e) { + InitializePosition(); RefreshMaximizeRestoreButton(); // Fix (workaround) for the window freezes after lock screen (Win+L) // https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf @@ -242,6 +244,8 @@ namespace Flow.Launcher private void OnClosed(object sender, EventArgs e) { + settings.SettingWindowTop = Top; + settings.SettingWindowLeft = Left; viewModel.Save(); } @@ -319,6 +323,7 @@ namespace Flow.Launcher private void OnCloseButtonClick(object sender, RoutedEventArgs e) { + Close(); } @@ -348,5 +353,36 @@ namespace Flow.Launcher { Plugins.ScrollIntoView(Plugins.SelectedItem); } + + public void InitializePosition() + { + if (settings.SettingWindowTop == 0 && settings.SettingWindowLeft == 0) + { + Top = WindowTop(); + Left = WindowLeft(); + } + else + { + Top = settings.SettingWindowTop; + Left = settings.SettingWindowLeft; + } + } + public double WindowLeft() + { + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0); + var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); + var left = (dip2.X - this.ActualWidth) / 2 + dip1.X; + return left; + } + + public double WindowTop() + { + var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); + var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y); + var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height); + var top = (dip2.Y - this.ActualHeight) / 2 + dip1.Y - 20; + return top; + } } } diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index a63e54f3b..fc6e3a16d 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -51,7 +51,7 @@ namespace Flow.Launcher.ViewModel { await _updater.UpdateAppAsync(App.API, false); } - + public bool AutoUpdates { get => Settings.AutoUpdates; @@ -385,6 +385,30 @@ namespace Flow.Launcher.ViewModel set => Settings.UseSound = value; } + public double SettingWindowWidth + { + get => Settings.SettingWindowWidth; + set => Settings.SettingWindowWidth = value; + } + + public double SettingWindowHeight + { + get => Settings.SettingWindowHeight; + set => Settings.SettingWindowHeight = value; + } + + public double SettingWindowTop + { + get => Settings.SettingWindowTop; + set => Settings.SettingWindowTop = value; + } + + public double SettingWindowLeft + { + get => Settings.SettingWindowLeft; + set => Settings.SettingWindowLeft = value; + } + public Brush PreviewBackground { get