@@ -42,13 +42,6 @@ public bool HasRightCaptionButton
42
42
43
43
public Launcher ( )
44
44
{
45
- var layout = ViewModels . Preferences . Instance . Layout ;
46
- if ( layout . LauncherWindowState != WindowState . Maximized )
47
- {
48
- Width = layout . LauncherWidth ;
49
- Height = layout . LauncherHeight ;
50
- }
51
-
52
45
if ( OperatingSystem . IsMacOS ( ) )
53
46
{
54
47
HasLeftCaptionButton = true ;
@@ -65,6 +58,31 @@ public Launcher()
65
58
}
66
59
67
60
InitializeComponent ( ) ;
61
+ PositionChanged += OnPositionChanged ;
62
+
63
+ var layout = ViewModels . Preferences . Instance . Layout ;
64
+ Width = layout . LauncherWidth ;
65
+ Height = layout . LauncherHeight ;
66
+
67
+ var x = layout . LauncherPositionX ;
68
+ var y = layout . LauncherPositionY ;
69
+ if ( x != int . MinValue && y != int . MinValue && Screens is { } screens )
70
+ {
71
+ var position = new PixelPoint ( x , y ) ;
72
+ var size = new PixelSize ( ( int ) layout . LauncherWidth , ( int ) layout . LauncherHeight ) ;
73
+ var desiredRect = new PixelRect ( position , size ) ;
74
+ for ( var i = 0 ; i < screens . ScreenCount ; i ++ )
75
+ {
76
+ var screen = screens . All [ i ] ;
77
+ if ( screen . WorkingArea . Contains ( desiredRect ) )
78
+ {
79
+ Position = position ;
80
+ return ;
81
+ }
82
+ }
83
+ }
84
+
85
+ WindowStartupLocation = WindowStartupLocation . CenterScreen ;
68
86
}
69
87
70
88
public void BringToTop ( )
@@ -113,6 +131,18 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
113
131
}
114
132
}
115
133
134
+ protected override void OnSizeChanged ( SizeChangedEventArgs e )
135
+ {
136
+ base . OnSizeChanged ( e ) ;
137
+
138
+ if ( WindowState == WindowState . Normal )
139
+ {
140
+ var layout = ViewModels . Preferences . Instance . Layout ;
141
+ layout . LauncherWidth = Width ;
142
+ layout . LauncherHeight = Height ;
143
+ }
144
+ }
145
+
116
146
protected override void OnKeyDown ( KeyEventArgs e )
117
147
{
118
148
var vm = DataContext as ViewModels . Launcher ;
@@ -311,7 +341,20 @@ protected override void OnClosing(WindowClosingEventArgs e)
311
341
base . OnClosing ( e ) ;
312
342
313
343
if ( ! Design . IsDesignMode && DataContext is ViewModels . Launcher launcher )
314
- launcher . Quit ( Width , Height ) ;
344
+ {
345
+ ViewModels . Preferences . Instance . Save ( ) ;
346
+ launcher . Quit ( ) ;
347
+ }
348
+ }
349
+
350
+ private void OnPositionChanged ( object sender , PixelPointEventArgs e )
351
+ {
352
+ if ( WindowState == WindowState . Normal )
353
+ {
354
+ var layout = ViewModels . Preferences . Instance . Layout ;
355
+ layout . LauncherPositionX = Position . X ;
356
+ layout . LauncherPositionY = Position . Y ;
357
+ }
315
358
}
316
359
317
360
private void OnOpenWorkspaceMenu ( object sender , RoutedEventArgs e )
0 commit comments