Skip to content

Commit e42c2b6

Browse files
committed
Remember Settingwindow Size and Location
1 parent 05044ae commit e42c2b6

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Drawing;
@@ -43,6 +43,11 @@ public string Language
4343
public bool UseSound { get; set; } = true;
4444
public bool FirstLaunch { get; set; } = true;
4545

46+
public double SettingWindowWidth { get; set; } = 1000;
47+
public double SettingWindowHeight { get; set; } = 700;
48+
public double SettingWindowTop { get; set; } = 0;
49+
public double SettingWindowLeft { get; set; } = 0;
50+
4651
public int CustomExplorerIndex { get; set; } = 0;
4752

4853
[JsonIgnore]
@@ -220,4 +225,4 @@ public enum ColorSchemes
220225
Light,
221226
Dark
222227
}
223-
}
228+
}

Flow.Launcher/SettingWindow.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313
xmlns:userSettings="clr-namespace:Flow.Launcher.Infrastructure.UserSettings;assembly=Flow.Launcher.Infrastructure"
1414
xmlns:vm="clr-namespace:Flow.Launcher.ViewModel"
1515
Title="{DynamicResource flowlauncher_settings}"
16-
Width="1000"
17-
Height="700"
16+
Width="{Binding SettingWindowWidth, Mode=TwoWay}"
17+
Height="{Binding SettingWindowHeight, Mode=TwoWay}"
1818
MinWidth="900"
1919
MinHeight="600"
2020
d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}"
2121
Closed="OnClosed"
2222
Icon="Images\app.ico"
23+
Left="{Binding SettingWindowLeft, Mode=TwoWay}"
2324
Loaded="OnLoaded"
2425
MouseDown="window_MouseDown"
2526
ResizeMode="CanResize"
2627
StateChanged="Window_StateChanged"
28+
Top="{Binding SettingWindowTop, Mode=TwoWay}"
2729
WindowStartupLocation="CenterScreen"
2830
mc:Ignorable="d">
2931
<WindowChrome.WindowChrome>

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.Win32;
1313
using ModernWpf;
1414
using System;
15+
using System.Diagnostics;
1516
using System.IO;
1617
using System.Windows;
1718
using System.Windows.Controls;
@@ -48,6 +49,7 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
4849

4950
private void OnLoaded(object sender, RoutedEventArgs e)
5051
{
52+
InitializePosition();
5153
RefreshMaximizeRestoreButton();
5254
// Fix (workaround) for the window freezes after lock screen (Win+L)
5355
// https://stackoverflow.com/questions/4951058/software-rendering-mode-wpf
@@ -242,6 +244,8 @@ private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
242244

243245
private void OnClosed(object sender, EventArgs e)
244246
{
247+
settings.SettingWindowTop = Top;
248+
settings.SettingWindowLeft = Left;
245249
viewModel.Save();
246250
}
247251

@@ -319,6 +323,7 @@ private void OnMaximizeRestoreButtonClick(object sender, RoutedEventArgs e)
319323

320324
private void OnCloseButtonClick(object sender, RoutedEventArgs e)
321325
{
326+
322327
Close();
323328
}
324329

@@ -348,5 +353,36 @@ private void ItemSizeChanged(object sender, SizeChangedEventArgs e)
348353
{
349354
Plugins.ScrollIntoView(Plugins.SelectedItem);
350355
}
356+
357+
public void InitializePosition()
358+
{
359+
if (settings.SettingWindowTop == 0 && settings.SettingWindowLeft == 0)
360+
{
361+
Top = WindowTop();
362+
Left = WindowLeft();
363+
}
364+
else
365+
{
366+
Top = settings.SettingWindowTop;
367+
Left = settings.SettingWindowLeft;
368+
}
369+
}
370+
public double WindowLeft()
371+
{
372+
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
373+
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
374+
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
375+
var left = (dip2.X - this.ActualWidth) / 2 + dip1.X;
376+
return left;
377+
}
378+
379+
public double WindowTop()
380+
{
381+
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
382+
var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
383+
var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
384+
var top = (dip2.Y - this.ActualHeight) / 2 + dip1.Y - 20;
385+
return top;
386+
}
351387
}
352388
}

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public async void UpdateApp()
5151
{
5252
await _updater.UpdateAppAsync(App.API, false);
5353
}
54-
54+
5555
public bool AutoUpdates
5656
{
5757
get => Settings.AutoUpdates;
@@ -385,6 +385,30 @@ public bool UseSound
385385
set => Settings.UseSound = value;
386386
}
387387

388+
public double SettingWindowWidth
389+
{
390+
get => Settings.SettingWindowWidth;
391+
set => Settings.SettingWindowWidth = value;
392+
}
393+
394+
public double SettingWindowHeight
395+
{
396+
get => Settings.SettingWindowHeight;
397+
set => Settings.SettingWindowHeight = value;
398+
}
399+
400+
public double SettingWindowTop
401+
{
402+
get => Settings.SettingWindowTop;
403+
set => Settings.SettingWindowTop = value;
404+
}
405+
406+
public double SettingWindowLeft
407+
{
408+
get => Settings.SettingWindowLeft;
409+
set => Settings.SettingWindowLeft = value;
410+
}
411+
388412
public Brush PreviewBackground
389413
{
390414
get

0 commit comments

Comments
 (0)