@@ -31,8 +31,8 @@ public class AppControllerCore
3131 public ObservableCollection < MonitorViewModel > Monitors { get ; }
3232 protected readonly object _monitorsLock = new ( ) ;
3333
34- public NotifyIconContainer NotifyIconContainer { get ; }
3534 public WindowPainter WindowPainter { get ; }
35+ public NotifyIconContainer NotifyIconContainer { get ; }
3636
3737 private readonly SessionWatcher _sessionWatcher ;
3838 private readonly PowerWatcher _powerWatcher ;
@@ -51,8 +51,8 @@ public AppControllerCore(AppKeeper keeper, SettingsCore settings)
5151 Monitors = new ObservableCollection < MonitorViewModel > ( ) ;
5252 BindingOperations . EnableCollectionSynchronization ( Monitors , _monitorsLock ) ;
5353
54- NotifyIconContainer = new NotifyIconContainer ( ) ;
5554 WindowPainter = new WindowPainter ( ) ;
55+ NotifyIconContainer = new NotifyIconContainer ( ) ;
5656
5757 _sessionWatcher = new SessionWatcher ( ) ;
5858 _powerWatcher = new PowerWatcher ( ) ;
@@ -71,16 +71,21 @@ public virtual async Task InitiateAsync()
7171 OnSettingsInitiated ( ) ;
7272 await OperationRecorder . RecordAsync ( $ "Connectable by named pipes: { _keeper . StartupAgent . IsConnectable } ") ;
7373
74+ WindowPainter . ApplyInitialTheme ( ) ;
7475 NotifyIconContainer . ShowIcon ( WindowPainter . GetIconPath ( ) , ProductInfo . Title ) ;
7576 WindowPainter . ThemeChanged += ( _ , _ ) =>
7677 {
7778 NotifyIconContainer . ShowIcon ( WindowPainter . GetIconPath ( ) ) ;
7879 } ;
7980
80- _current . MainWindow = new MainWindow ( this ) ;
81+ var mainWindow = new MainWindow ( this ) ;
82+ _current . MainWindow = mainWindow ;
8183
8284 if ( StartupAgent . IsWindowShowExpected ( ) )
83- _current . MainWindow . Show ( ) ;
85+ {
86+ mainWindow . CursorLocation = CursorHelper . GetCursorLocation ( ) ;
87+ mainWindow . Show ( ) ;
88+ }
8489
8590 await ScanAsync ( ) ;
8691
@@ -167,7 +172,7 @@ protected async void OnMainWindowShowRequestedBySelf(object sender, EventArgs e)
167172
168173 protected async void OnMainWindowShowRequestedByOther ( object sender , EventArgs e )
169174 {
170- _current . Dispatcher . Invoke ( ( ) => ShowMainWindow ( ) ) ;
175+ _current . Dispatcher . Invoke ( ( ) => ShowMainWindow ( true ) ) ;
171176 await CheckUpdateAsync ( ) ;
172177
173178 if ( _brightnessConnector . IsEnabled )
@@ -179,12 +184,13 @@ protected void OnMenuWindowShowRequested(object sender, Point e)
179184 ShowMenuWindow ( e ) ;
180185 }
181186
182- protected virtual void ShowMainWindow ( )
187+ protected virtual void ShowMainWindow ( bool useCursorLocation = false )
183188 {
184189 var window = ( MainWindow ) _current . MainWindow ;
185190 if ( window is { CanBeShown : false } or { Visibility : Visibility . Visible , IsForeground : true } )
186191 return ;
187192
193+ window . CursorLocation = useCursorLocation ? CursorHelper . GetCursorLocation ( ) : null ;
188194 window . ShowForeground ( ) ;
189195 window . Activate ( ) ;
190196 }
@@ -497,8 +503,9 @@ protected virtual async Task UpdateMessageAsync(string deviceInstanceId, string
497503
498504 private void ReflectMouseWheel ( int delta )
499505 {
500- var monitor = Monitors . Prepend ( SelectedMonitor )
501- . FirstOrDefault ( x => x . IsTarget && x . IsControllable ) ;
506+ var monitors = Monitors . Where ( x => x . IsTarget && x . IsControllable ) . ToArray ( ) ;
507+ var monitor = monitors . FirstOrDefault ( x => ReferenceEquals ( x , SelectedMonitor ) )
508+ ?? monitors . FirstOrDefault ( ) ; // Fallback
502509 if ( monitor is null )
503510 return ;
504511
0 commit comments