@@ -46,6 +46,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
46
46
_viewModel = mainVM ;
47
47
_settings = settings ;
48
48
InitializeComponent ( ) ;
49
+ InitializePosition ( ) ;
49
50
animationSound . Open ( new Uri ( AppDomain . CurrentDomain . BaseDirectory + "Resources\\ open.wav" ) ) ;
50
51
}
51
52
@@ -108,7 +109,6 @@ private void OnLoaded(object sender, RoutedEventArgs _)
108
109
animationSound . Position = TimeSpan . Zero ;
109
110
animationSound . Play ( ) ;
110
111
}
111
-
112
112
UpdatePosition ( ) ;
113
113
Activate ( ) ;
114
114
QueryTextBox . Focus ( ) ;
@@ -161,6 +161,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
161
161
_viewModel . QueryTextCursorMovedToEnd = false ;
162
162
}
163
163
break ;
164
+
164
165
}
165
166
} ;
166
167
_settings . PropertyChanged += ( o , e ) =>
@@ -176,17 +177,51 @@ private void OnLoaded(object sender, RoutedEventArgs _)
176
177
case nameof ( Settings . Hotkey ) :
177
178
UpdateNotifyIconText ( ) ;
178
179
break ;
180
+ case nameof ( Settings . WindowLeft ) :
181
+ Left = _settings . WindowLeft ;
182
+ break ;
183
+ case nameof ( Settings . WindowTop ) :
184
+ Top = _settings . WindowTop ;
185
+ break ;
179
186
}
180
187
} ;
181
188
}
182
189
190
+ private void InitializePosition ( )
191
+ {
192
+ switch ( _settings . SearchWindowPosition )
193
+ {
194
+ case SearchWindowPositions . RememberLastLaunchLocation :
195
+ Top = _settings . WindowTop ;
196
+ Left = _settings . WindowLeft ;
197
+ break ;
198
+ case SearchWindowPositions . MouseScreenCenter :
199
+ Left = HorizonCenter ( ) ;
200
+ Top = VerticalCenter ( ) ;
201
+ break ;
202
+ case SearchWindowPositions . MouseScreenCenterTop :
203
+ Left = HorizonCenter ( ) ;
204
+ Top = 10 ;
205
+ break ;
206
+ case SearchWindowPositions . MouseScreenLeftTop :
207
+ Left = 10 ;
208
+ Top = 10 ;
209
+ break ;
210
+ case SearchWindowPositions . MouseScreenRightTop :
211
+ Left = HorizonRight ( ) ;
212
+ Top = 10 ;
213
+ break ;
214
+ }
215
+ }
216
+
183
217
private void UpdateNotifyIconText ( )
184
218
{
185
219
var menu = contextMenu ;
186
220
( ( MenuItem ) menu . Items [ 1 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayOpen" ) + " (" + _settings . Hotkey + ")" ;
187
221
( ( MenuItem ) menu . Items [ 2 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) ;
188
- ( ( MenuItem ) menu . Items [ 3 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" ) ;
189
- ( ( MenuItem ) menu . Items [ 4 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) ;
222
+ ( ( MenuItem ) menu . Items [ 3 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "PositionReset" ) ;
223
+ ( ( MenuItem ) menu . Items [ 4 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" ) ;
224
+ ( ( MenuItem ) menu . Items [ 5 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) ;
190
225
}
191
226
192
227
private void InitializeNotifyIcon ( )
@@ -212,6 +247,10 @@ private void InitializeNotifyIcon()
212
247
{
213
248
Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" )
214
249
} ;
250
+ var positionreset = new MenuItem
251
+ {
252
+ Header = InternationalizationManager . Instance . GetTranslation ( "PositionReset" )
253
+ } ;
215
254
var settings = new MenuItem
216
255
{
217
256
Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" )
@@ -223,12 +262,15 @@ private void InitializeNotifyIcon()
223
262
224
263
open . Click += ( o , e ) => _viewModel . ToggleFlowLauncher ( ) ;
225
264
gamemode . Click += ( o , e ) => ToggleGameMode ( ) ;
265
+ positionreset . Click += ( o , e ) => PositionReset ( ) ;
226
266
settings . Click += ( o , e ) => App . API . OpenSettingDialog ( ) ;
227
267
exit . Click += ( o , e ) => Close ( ) ;
228
268
contextMenu . Items . Add ( header ) ;
229
269
contextMenu . Items . Add ( open ) ;
230
270
gamemode . ToolTip = InternationalizationManager . Instance . GetTranslation ( "GameModeToolTip" ) ;
271
+ positionreset . ToolTip = InternationalizationManager . Instance . GetTranslation ( "PositionResetToolTip" ) ;
231
272
contextMenu . Items . Add ( gamemode ) ;
273
+ contextMenu . Items . Add ( positionreset ) ;
232
274
contextMenu . Items . Add ( settings ) ;
233
275
contextMenu . Items . Add ( exit ) ;
234
276
@@ -275,10 +317,17 @@ private void ToggleGameMode()
275
317
_viewModel . GameModeStatus = true ;
276
318
}
277
319
}
320
+ private async void PositionReset ( )
321
+ {
322
+ _viewModel . Show ( ) ;
323
+ await Task . Delay ( 300 ) ; // If don't give a time, Positioning will be weird.
324
+ Left = HorizonCenter ( ) ;
325
+ Top = VerticalCenter ( ) ;
326
+ }
278
327
private void InitProgressbarAnimation ( )
279
328
{
280
329
var da = new DoubleAnimation ( ProgressBar . X2 , ActualWidth + 150 ,
281
- new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
330
+ new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
282
331
var da1 = new DoubleAnimation ( ProgressBar . X1 , ActualWidth + 50 , new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
283
332
Storyboard . SetTargetProperty ( da , new PropertyPath ( "(Line.X2)" ) ) ;
284
333
Storyboard . SetTargetProperty ( da1 , new PropertyPath ( "(Line.X1)" ) ) ;
@@ -382,6 +431,8 @@ private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs
382
431
383
432
private async void OnDeactivated ( object sender , EventArgs e )
384
433
{
434
+ _settings . WindowLeft = Left ;
435
+ _settings . WindowTop = Top ;
385
436
//This condition stops extra hide call when animator is on,
386
437
// which causes the toggling to occasional hide instead of show.
387
438
if ( _viewModel . MainWindowVisibilityStatus )
@@ -403,24 +454,14 @@ private void UpdatePosition()
403
454
{
404
455
if ( _animating )
405
456
return ;
406
-
407
- if ( _settings . RememberLastLaunchLocation )
408
- {
409
- Left = _settings . WindowLeft ;
410
- Top = _settings . WindowTop ;
411
- }
412
- else
413
- {
414
- Left = WindowLeft ( ) ;
415
- Top = WindowTop ( ) ;
416
- }
457
+ InitializePosition ( ) ;
417
458
}
418
459
419
460
private void OnLocationChanged ( object sender , EventArgs e )
420
461
{
421
462
if ( _animating )
422
463
return ;
423
- if ( _settings . RememberLastLaunchLocation )
464
+ if ( _settings . SearchWindowPosition == SearchWindowPositions . RememberLastLaunchLocation )
424
465
{
425
466
_settings . WindowLeft = Left ;
426
467
_settings . WindowTop = Top ;
@@ -439,17 +480,8 @@ public void HideStartup()
439
480
_viewModel . Show ( ) ;
440
481
}
441
482
}
442
-
443
- private void InitializePosition ( )
444
- {
445
- if ( ! _settings . RememberLastLaunchLocation )
446
- {
447
- Left = WindowLeft ( ) ;
448
- Top = WindowTop ( ) ;
449
- }
450
- }
451
483
452
- public double WindowLeft ( )
484
+ public double HorizonCenter ( )
453
485
{
454
486
var screen = Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
455
487
var dip1 = WindowsInteropHelper . TransformPixelsToDIP ( this , screen . WorkingArea . X , 0 ) ;
@@ -458,7 +490,7 @@ public double WindowLeft()
458
490
return left ;
459
491
}
460
492
461
- public double WindowTop ( )
493
+ public double VerticalCenter ( )
462
494
{
463
495
var screen = Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
464
496
var dip1 = WindowsInteropHelper . TransformPixelsToDIP ( this , 0 , screen . WorkingArea . Y ) ;
@@ -467,6 +499,15 @@ public double WindowTop()
467
499
return top ;
468
500
}
469
501
502
+ public double HorizonRight ( )
503
+ {
504
+ var screen = Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
505
+ var dip1 = WindowsInteropHelper . TransformPixelsToDIP ( this , screen . WorkingArea . X , 0 ) ;
506
+ var dip2 = WindowsInteropHelper . TransformPixelsToDIP ( this , screen . WorkingArea . Width , 0 ) ;
507
+ var left = ( dip2 . X - ActualWidth ) - 10 ;
508
+ return left ;
509
+ }
510
+
470
511
/// <summary>
471
512
/// Register up and down key
472
513
/// todo: any way to put this in xaml ?
0 commit comments