@@ -42,13 +42,6 @@ public bool HasRightCaptionButton
4242
4343 public Launcher ( )
4444 {
45- var layout = ViewModels . Preferences . Instance . Layout ;
46- if ( layout . LauncherWindowState != WindowState . Maximized )
47- {
48- Width = layout . LauncherWidth ;
49- Height = layout . LauncherHeight ;
50- }
51-
5245 if ( OperatingSystem . IsMacOS ( ) )
5346 {
5447 HasLeftCaptionButton = true ;
@@ -65,6 +58,31 @@ public Launcher()
6558 }
6659
6760 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 ;
6886 }
6987
7088 public void BringToTop ( )
@@ -113,6 +131,18 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
113131 }
114132 }
115133
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+
116146 protected override void OnKeyDown ( KeyEventArgs e )
117147 {
118148 var vm = DataContext as ViewModels . Launcher ;
@@ -311,7 +341,20 @@ protected override void OnClosing(WindowClosingEventArgs e)
311341 base . OnClosing ( e ) ;
312342
313343 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+ }
315358 }
316359
317360 private void OnOpenWorkspaceMenu ( object sender , RoutedEventArgs e )
0 commit comments