@@ -97,6 +97,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
97
97
InitializeColorScheme ( ) ;
98
98
WindowsInteropHelper . DisableControlBox ( this ) ;
99
99
InitProgressbarAnimation ( ) ;
100
+ InitializePosition ( ) ;
100
101
// since the default main window visibility is visible
101
102
// so we need set focus during startup
102
103
QueryTextBox . Focus ( ) ;
@@ -114,7 +115,6 @@ private void OnLoaded(object sender, RoutedEventArgs _)
114
115
animationSound . Position = TimeSpan . Zero ;
115
116
animationSound . Play ( ) ;
116
117
}
117
-
118
118
UpdatePosition ( ) ;
119
119
Activate ( ) ;
120
120
QueryTextBox . Focus ( ) ;
@@ -167,6 +167,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
167
167
_viewModel . QueryTextCursorMovedToEnd = false ;
168
168
}
169
169
break ;
170
+
170
171
}
171
172
} ;
172
173
_settings . PropertyChanged += ( o , e ) =>
@@ -182,21 +183,40 @@ private void OnLoaded(object sender, RoutedEventArgs _)
182
183
case nameof ( Settings . Hotkey ) :
183
184
UpdateNotifyIconText ( ) ;
184
185
break ;
186
+ case nameof ( Settings . WindowLeft ) :
187
+ Left = _settings . WindowLeft ;
188
+ break ;
189
+ case nameof ( Settings . WindowTop ) :
190
+ Top = _settings . WindowTop ;
191
+ break ;
185
192
}
186
193
} ;
187
194
}
188
195
189
196
private void InitializePosition ( )
190
197
{
191
- if ( _settings . RememberLastLaunchLocation )
192
- {
193
- Top = _settings . WindowTop ;
194
- Left = _settings . WindowLeft ;
195
- }
196
- else
198
+ switch ( _settings . SearchWindowPosition )
197
199
{
198
- Left = WindowLeft ( ) ;
199
- Top = WindowTop ( ) ;
200
+ case SearchWindowPositions . RememberLastLaunchLocation :
201
+ Top = _settings . WindowTop ;
202
+ Left = _settings . WindowLeft ;
203
+ break ;
204
+ case SearchWindowPositions . MouseScreenCenter :
205
+ Left = HorizonCenter ( ) ;
206
+ Top = VerticalCenter ( ) ;
207
+ break ;
208
+ case SearchWindowPositions . MouseScreenCenterTop :
209
+ Left = HorizonCenter ( ) ;
210
+ Top = 10 ;
211
+ break ;
212
+ case SearchWindowPositions . MouseScreenLeftTop :
213
+ Left = 10 ;
214
+ Top = 10 ;
215
+ break ;
216
+ case SearchWindowPositions . MouseScreenRightTop :
217
+ Left = HorizonRight ( ) ;
218
+ Top = 10 ;
219
+ break ;
200
220
}
201
221
}
202
222
@@ -205,8 +225,9 @@ private void UpdateNotifyIconText()
205
225
var menu = contextMenu ;
206
226
( ( MenuItem ) menu . Items [ 1 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayOpen" ) + " (" + _settings . Hotkey + ")" ;
207
227
( ( MenuItem ) menu . Items [ 2 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) ;
208
- ( ( MenuItem ) menu . Items [ 3 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" ) ;
209
- ( ( MenuItem ) menu . Items [ 4 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) ;
228
+ ( ( MenuItem ) menu . Items [ 3 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "PositionReset" ) ;
229
+ ( ( MenuItem ) menu . Items [ 4 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" ) ;
230
+ ( ( MenuItem ) menu . Items [ 5 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) ;
210
231
}
211
232
212
233
private void InitializeNotifyIcon ( )
@@ -232,6 +253,10 @@ private void InitializeNotifyIcon()
232
253
{
233
254
Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" )
234
255
} ;
256
+ var positionreset = new MenuItem
257
+ {
258
+ Header = InternationalizationManager . Instance . GetTranslation ( "PositionReset" )
259
+ } ;
235
260
var settings = new MenuItem
236
261
{
237
262
Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" )
@@ -243,12 +268,15 @@ private void InitializeNotifyIcon()
243
268
244
269
open . Click += ( o , e ) => _viewModel . ToggleFlowLauncher ( ) ;
245
270
gamemode . Click += ( o , e ) => ToggleGameMode ( ) ;
271
+ positionreset . Click += ( o , e ) => PositionReset ( ) ;
246
272
settings . Click += ( o , e ) => App . API . OpenSettingDialog ( ) ;
247
273
exit . Click += ( o , e ) => Close ( ) ;
248
274
contextMenu . Items . Add ( header ) ;
249
275
contextMenu . Items . Add ( open ) ;
250
276
gamemode . ToolTip = InternationalizationManager . Instance . GetTranslation ( "GameModeToolTip" ) ;
277
+ positionreset . ToolTip = InternationalizationManager . Instance . GetTranslation ( "PositionResetToolTip" ) ;
251
278
contextMenu . Items . Add ( gamemode ) ;
279
+ contextMenu . Items . Add ( positionreset ) ;
252
280
contextMenu . Items . Add ( settings ) ;
253
281
contextMenu . Items . Add ( exit ) ;
254
282
@@ -295,10 +323,17 @@ private void ToggleGameMode()
295
323
_viewModel . GameModeStatus = true ;
296
324
}
297
325
}
326
+ private async void PositionReset ( )
327
+ {
328
+ _viewModel . Show ( ) ;
329
+ await Task . Delay ( 300 ) ; // If don't give a time, Positioning will be weird.
330
+ Left = HorizonCenter ( ) ;
331
+ Top = VerticalCenter ( ) ;
332
+ }
298
333
private void InitProgressbarAnimation ( )
299
334
{
300
335
var da = new DoubleAnimation ( ProgressBar . X2 , ActualWidth + 150 ,
301
- new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
336
+ new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
302
337
var da1 = new DoubleAnimation ( ProgressBar . X1 , ActualWidth + 50 , new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
303
338
Storyboard . SetTargetProperty ( da , new PropertyPath ( "(Line.X2)" ) ) ;
304
339
Storyboard . SetTargetProperty ( da1 , new PropertyPath ( "(Line.X1)" ) ) ;
@@ -402,6 +437,8 @@ private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs
402
437
403
438
private async void OnDeactivated ( object sender , EventArgs e )
404
439
{
440
+ _settings . WindowLeft = Left ;
441
+ _settings . WindowTop = Top ;
405
442
//This condition stops extra hide call when animator is on,
406
443
// which causes the toggling to occasional hide instead of show.
407
444
if ( _viewModel . MainWindowVisibilityStatus )
@@ -423,24 +460,14 @@ private void UpdatePosition()
423
460
{
424
461
if ( _animating )
425
462
return ;
426
-
427
- if ( _settings . RememberLastLaunchLocation )
428
- {
429
- Left = _settings . WindowLeft ;
430
- Top = _settings . WindowTop ;
431
- }
432
- else
433
- {
434
- Left = WindowLeft ( ) ;
435
- Top = WindowTop ( ) ;
436
- }
463
+ InitializePosition ( ) ;
437
464
}
438
465
439
466
private void OnLocationChanged ( object sender , EventArgs e )
440
467
{
441
468
if ( _animating )
442
469
return ;
443
- if ( _settings . RememberLastLaunchLocation )
470
+ if ( _settings . SearchWindowPosition == SearchWindowPositions . RememberLastLaunchLocation )
444
471
{
445
472
_settings . WindowLeft = Left ;
446
473
_settings . WindowTop = Top ;
@@ -459,8 +486,8 @@ public void HideStartup()
459
486
_viewModel . Show ( ) ;
460
487
}
461
488
}
462
-
463
- public double WindowLeft ( )
489
+
490
+ public double HorizonCenter ( )
464
491
{
465
492
var screen = Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
466
493
var dip1 = WindowsInteropHelper . TransformPixelsToDIP ( this , screen . WorkingArea . X , 0 ) ;
@@ -469,7 +496,7 @@ public double WindowLeft()
469
496
return left ;
470
497
}
471
498
472
- public double WindowTop ( )
499
+ public double VerticalCenter ( )
473
500
{
474
501
var screen = Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
475
502
var dip1 = WindowsInteropHelper . TransformPixelsToDIP ( this , 0 , screen . WorkingArea . Y ) ;
@@ -478,12 +505,22 @@ public double WindowTop()
478
505
return top ;
479
506
}
480
507
508
+ public double HorizonRight ( )
509
+ {
510
+ var screen = Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
511
+ var dip1 = WindowsInteropHelper . TransformPixelsToDIP ( this , screen . WorkingArea . X , 0 ) ;
512
+ var dip2 = WindowsInteropHelper . TransformPixelsToDIP ( this , screen . WorkingArea . Width , 0 ) ;
513
+ var left = ( dip2 . X - ActualWidth ) - 10 ;
514
+ return left ;
515
+ }
516
+
481
517
/// <summary>
482
518
/// Register up and down key
483
519
/// todo: any way to put this in xaml ?
484
520
/// </summary>
485
521
private void OnKeyDown ( object sender , KeyEventArgs e )
486
522
{
523
+ var specialKeyState = GlobalHotkey . CheckModifiers ( ) ;
487
524
switch ( e . Key )
488
525
{
489
526
case Key . Down :
@@ -518,8 +555,13 @@ private void OnKeyDown(object sender, KeyEventArgs e)
518
555
e . Handled = true ;
519
556
}
520
557
break ;
558
+ case Key . F12 :
559
+ if ( specialKeyState . CtrlPressed )
560
+ {
561
+ ToggleGameMode ( ) ;
562
+ }
563
+ break ;
521
564
case Key . Back :
522
- var specialKeyState = GlobalHotkey . CheckModifiers ( ) ;
523
565
if ( specialKeyState . CtrlPressed )
524
566
{
525
567
if ( _viewModel . SelectedIsFromQueryResults ( )
0 commit comments