@@ -91,6 +91,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
91
91
InitializeColorScheme ( ) ;
92
92
WindowsInteropHelper . DisableControlBox ( this ) ;
93
93
InitProgressbarAnimation ( ) ;
94
+ InitializePosition ( ) ;
94
95
// since the default main window visibility is visible
95
96
// so we need set focus during startup
96
97
QueryTextBox . Focus ( ) ;
@@ -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,21 +177,40 @@ 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
183
190
private void InitializePosition ( )
184
191
{
185
- if ( _settings . RememberLastLaunchLocation )
186
- {
187
- Top = _settings . WindowTop ;
188
- Left = _settings . WindowLeft ;
189
- }
190
- else
192
+ switch ( _settings . SearchWindowPosition )
191
193
{
192
- Left = WindowLeft ( ) ;
193
- Top = WindowTop ( ) ;
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 ;
194
214
}
195
215
}
196
216
@@ -199,8 +219,9 @@ private void UpdateNotifyIconText()
199
219
var menu = contextMenu ;
200
220
( ( MenuItem ) menu . Items [ 1 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayOpen" ) + " (" + _settings . Hotkey + ")" ;
201
221
( ( MenuItem ) menu . Items [ 2 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) ;
202
- ( ( MenuItem ) menu . Items [ 3 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" ) ;
203
- ( ( 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" ) ;
204
225
}
205
226
206
227
private void InitializeNotifyIcon ( )
@@ -226,6 +247,10 @@ private void InitializeNotifyIcon()
226
247
{
227
248
Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" )
228
249
} ;
250
+ var positionreset = new MenuItem
251
+ {
252
+ Header = InternationalizationManager . Instance . GetTranslation ( "PositionReset" )
253
+ } ;
229
254
var settings = new MenuItem
230
255
{
231
256
Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" )
@@ -237,12 +262,15 @@ private void InitializeNotifyIcon()
237
262
238
263
open . Click += ( o , e ) => _viewModel . ToggleFlowLauncher ( ) ;
239
264
gamemode . Click += ( o , e ) => ToggleGameMode ( ) ;
265
+ positionreset . Click += ( o , e ) => PositionReset ( ) ;
240
266
settings . Click += ( o , e ) => App . API . OpenSettingDialog ( ) ;
241
267
exit . Click += ( o , e ) => Close ( ) ;
242
268
contextMenu . Items . Add ( header ) ;
243
269
contextMenu . Items . Add ( open ) ;
244
270
gamemode . ToolTip = InternationalizationManager . Instance . GetTranslation ( "GameModeToolTip" ) ;
271
+ positionreset . ToolTip = InternationalizationManager . Instance . GetTranslation ( "PositionResetToolTip" ) ;
245
272
contextMenu . Items . Add ( gamemode ) ;
273
+ contextMenu . Items . Add ( positionreset ) ;
246
274
contextMenu . Items . Add ( settings ) ;
247
275
contextMenu . Items . Add ( exit ) ;
248
276
@@ -289,10 +317,17 @@ private void ToggleGameMode()
289
317
_viewModel . GameModeStatus = true ;
290
318
}
291
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
+ }
292
327
private void InitProgressbarAnimation ( )
293
328
{
294
329
var da = new DoubleAnimation ( ProgressBar . X2 , ActualWidth + 150 ,
295
- new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
330
+ new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
296
331
var da1 = new DoubleAnimation ( ProgressBar . X1 , ActualWidth + 50 , new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
297
332
Storyboard . SetTargetProperty ( da , new PropertyPath ( "(Line.X2)" ) ) ;
298
333
Storyboard . SetTargetProperty ( da1 , new PropertyPath ( "(Line.X1)" ) ) ;
@@ -396,6 +431,8 @@ private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs
396
431
397
432
private async void OnDeactivated ( object sender , EventArgs e )
398
433
{
434
+ _settings . WindowLeft = Left ;
435
+ _settings . WindowTop = Top ;
399
436
//This condition stops extra hide call when animator is on,
400
437
// which causes the toggling to occasional hide instead of show.
401
438
if ( _viewModel . MainWindowVisibilityStatus )
@@ -417,24 +454,14 @@ private void UpdatePosition()
417
454
{
418
455
if ( _animating )
419
456
return ;
420
-
421
- if ( _settings . RememberLastLaunchLocation )
422
- {
423
- Left = _settings . WindowLeft ;
424
- Top = _settings . WindowTop ;
425
- }
426
- else
427
- {
428
- Left = WindowLeft ( ) ;
429
- Top = WindowTop ( ) ;
430
- }
457
+ InitializePosition ( ) ;
431
458
}
432
459
433
460
private void OnLocationChanged ( object sender , EventArgs e )
434
461
{
435
462
if ( _animating )
436
463
return ;
437
- if ( _settings . RememberLastLaunchLocation )
464
+ if ( _settings . SearchWindowPosition == SearchWindowPositions . RememberLastLaunchLocation )
438
465
{
439
466
_settings . WindowLeft = Left ;
440
467
_settings . WindowTop = Top ;
@@ -453,8 +480,8 @@ public void HideStartup()
453
480
_viewModel . Show ( ) ;
454
481
}
455
482
}
456
-
457
- public double WindowLeft ( )
483
+
484
+ public double HorizonCenter ( )
458
485
{
459
486
var screen = Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
460
487
var dip1 = WindowsInteropHelper . TransformPixelsToDIP ( this , screen . WorkingArea . X , 0 ) ;
@@ -463,7 +490,7 @@ public double WindowLeft()
463
490
return left ;
464
491
}
465
492
466
- public double WindowTop ( )
493
+ public double VerticalCenter ( )
467
494
{
468
495
var screen = Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
469
496
var dip1 = WindowsInteropHelper . TransformPixelsToDIP ( this , 0 , screen . WorkingArea . Y ) ;
@@ -472,12 +499,22 @@ public double WindowTop()
472
499
return top ;
473
500
}
474
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
+
475
511
/// <summary>
476
512
/// Register up and down key
477
513
/// todo: any way to put this in xaml ?
478
514
/// </summary>
479
515
private void OnKeyDown ( object sender , KeyEventArgs e )
480
516
{
517
+ var specialKeyState = GlobalHotkey . CheckModifiers ( ) ;
481
518
switch ( e . Key )
482
519
{
483
520
case Key . Down :
@@ -512,8 +549,13 @@ private void OnKeyDown(object sender, KeyEventArgs e)
512
549
e . Handled = true ;
513
550
}
514
551
break ;
552
+ case Key . F12 :
553
+ if ( specialKeyState . CtrlPressed )
554
+ {
555
+ ToggleGameMode ( ) ;
556
+ }
557
+ break ;
515
558
case Key . Back :
516
- var specialKeyState = GlobalHotkey . CheckModifiers ( ) ;
517
559
if ( specialKeyState . CtrlPressed )
518
560
{
519
561
if ( _viewModel . SelectedIsFromQueryResults ( )
0 commit comments