@@ -58,6 +58,8 @@ public MainWindow(Settings settings, MainViewModel mainVM)
58
58
_settings = settings ;
59
59
60
60
InitializeComponent ( ) ;
61
+ // Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
62
+ InitializePosition ( ) ;
61
63
InitializePosition ( ) ;
62
64
63
65
InitSoundEffects ( ) ;
@@ -72,11 +74,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
72
74
} ;
73
75
}
74
76
75
- DispatcherTimer timer = new DispatcherTimer
76
- {
77
- Interval = new TimeSpan ( 0 , 0 , 0 , 0 , 500 ) ,
78
- IsEnabled = false
79
- } ;
77
+ DispatcherTimer timer = new DispatcherTimer { Interval = new TimeSpan ( 0 , 0 , 0 , 0 , 500 ) , IsEnabled = false } ;
80
78
81
79
public MainWindow ( )
82
80
{
@@ -87,6 +85,7 @@ public MainWindow()
87
85
private const int WM_EXITSIZEMOVE = 0x0232 ;
88
86
private int _initialWidth ;
89
87
private int _initialHeight ;
88
+
90
89
private IntPtr WndProc ( IntPtr hwnd , int msg , IntPtr wParam , IntPtr lParam , ref bool handled )
91
90
{
92
91
if ( msg == WM_ENTERSIZEMOVE )
@@ -95,18 +94,22 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
95
94
_initialHeight = ( int ) Height ;
96
95
handled = true ;
97
96
}
97
+
98
98
if ( msg == WM_EXITSIZEMOVE )
99
99
{
100
- if ( _initialHeight != ( int ) Height )
100
+ if ( _initialHeight != ( int ) Height )
101
101
{
102
102
OnResizeEnd ( ) ;
103
103
}
104
+
104
105
if ( _initialWidth != ( int ) Width )
105
106
{
106
107
FlowMainWindow . SizeToContent = SizeToContent . Height ;
107
108
}
109
+
108
110
handled = true ;
109
111
}
112
+
110
113
return IntPtr . Zero ;
111
114
}
112
115
@@ -131,6 +134,7 @@ private void OnResizeEnd()
131
134
_settings . MaxResultsToShow = Convert . ToInt32 ( Math . Truncate ( itemCount ) ) ;
132
135
}
133
136
}
137
+
134
138
FlowMainWindow . SizeToContent = SizeToContent . Height ;
135
139
_viewModel . MainWindowWidth = Width ;
136
140
}
@@ -175,6 +179,7 @@ private async void OnClosing(object sender, CancelEventArgs e)
175
179
private void OnInitialized ( object sender , EventArgs e )
176
180
{
177
181
}
182
+
178
183
private void OnLoaded ( object sender , RoutedEventArgs _ )
179
184
{
180
185
// MouseEventHandler
@@ -186,6 +191,8 @@ private void OnLoaded(object sender, RoutedEventArgs _)
186
191
InitializeColorScheme ( ) ;
187
192
WindowsInteropHelper . DisableControlBox ( this ) ;
188
193
InitProgressbarAnimation ( ) ;
194
+ // Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
195
+ InitializePosition ( ) ;
189
196
InitializePosition ( ) ;
190
197
PreviewReset ( ) ;
191
198
// since the default main window visibility is visible
@@ -206,6 +213,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
206
213
{
207
214
SoundPlay ( ) ;
208
215
}
216
+
209
217
UpdatePosition ( ) ;
210
218
PreviewReset ( ) ;
211
219
Activate ( ) ;
@@ -217,7 +225,8 @@ private void OnLoaded(object sender, RoutedEventArgs _)
217
225
_viewModel . LastQuerySelected = true ;
218
226
}
219
227
220
- if ( _viewModel . ProgressBarVisibility == Visibility . Visible && isProgressBarStoryboardPaused )
228
+ if ( _viewModel . ProgressBarVisibility == Visibility . Visible &&
229
+ isProgressBarStoryboardPaused )
221
230
{
222
231
_progressBarStoryboard . Begin ( ProgressBar , true ) ;
223
232
isProgressBarStoryboardPaused = false ;
@@ -258,9 +267,12 @@ private void OnLoaded(object sender, RoutedEventArgs _)
258
267
MoveQueryTextToEnd ( ) ;
259
268
_viewModel . QueryTextCursorMovedToEnd = false ;
260
269
}
270
+
261
271
break ;
262
272
case nameof ( MainViewModel . GameModeStatus ) :
263
- _notifyIcon . Icon = _viewModel . GameModeStatus ? Properties . Resources . gamemode : Properties . Resources . app ;
273
+ _notifyIcon . Icon = _viewModel . GameModeStatus
274
+ ? Properties . Resources . gamemode
275
+ : Properties . Resources . app ;
264
276
break ;
265
277
}
266
278
} ;
@@ -290,50 +302,59 @@ private void OnLoaded(object sender, RoutedEventArgs _)
290
302
291
303
private void InitializePosition ( )
292
304
{
293
- if ( _settings . SearchWindowScreen == SearchWindowScreens . RememberLastLaunchLocation )
294
- {
295
- Top = _settings . WindowTop ;
296
- Left = _settings . WindowLeft ;
297
- }
298
- else
305
+ // Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
306
+ InitializePositionInner ( ) ;
307
+ InitializePositionInner ( ) ;
308
+ return ;
309
+
310
+ void InitializePositionInner ( )
299
311
{
300
- var screen = SelectedScreen ( ) ;
301
- switch ( _settings . SearchWindowAlign )
312
+ if ( _settings . SearchWindowScreen == SearchWindowScreens . RememberLastLaunchLocation )
302
313
{
303
- case SearchWindowAligns . Center :
304
- Left = HorizonCenter ( screen ) ;
305
- Top = VerticalCenter ( screen ) ;
306
- break ;
307
- case SearchWindowAligns . CenterTop :
308
- Left = HorizonCenter ( screen ) ;
309
- Top = 10 ;
310
- break ;
311
- case SearchWindowAligns . LeftTop :
312
- Left = HorizonLeft ( screen ) ;
313
- Top = 10 ;
314
- break ;
315
- case SearchWindowAligns . RightTop :
316
- Left = HorizonRight ( screen ) ;
317
- Top = 10 ;
318
- break ;
319
- case SearchWindowAligns . Custom :
320
- Left = WindowsInteropHelper . TransformPixelsToDIP ( this , screen . WorkingArea . X + _settings . CustomWindowLeft , 0 ) . X ;
321
- Top = WindowsInteropHelper . TransformPixelsToDIP ( this , 0 , screen . WorkingArea . Y + _settings . CustomWindowTop ) . Y ;
322
- break ;
314
+ Top = _settings . WindowTop ;
315
+ Left = _settings . WindowLeft ;
316
+ }
317
+ else
318
+ {
319
+ var screen = SelectedScreen ( ) ;
320
+ switch ( _settings . SearchWindowAlign )
321
+ {
322
+ case SearchWindowAligns . Center :
323
+ Left = HorizonCenter ( screen ) ;
324
+ Top = VerticalCenter ( screen ) ;
325
+ break ;
326
+ case SearchWindowAligns . CenterTop :
327
+ Left = HorizonCenter ( screen ) ;
328
+ Top = 10 ;
329
+ break ;
330
+ case SearchWindowAligns . LeftTop :
331
+ Left = HorizonLeft ( screen ) ;
332
+ Top = 10 ;
333
+ break ;
334
+ case SearchWindowAligns . RightTop :
335
+ Left = HorizonRight ( screen ) ;
336
+ Top = 10 ;
337
+ break ;
338
+ case SearchWindowAligns . Custom :
339
+ Left = WindowsInteropHelper . TransformPixelsToDIP ( this ,
340
+ screen . WorkingArea . X + _settings . CustomWindowLeft , 0 ) . X ;
341
+ Top = WindowsInteropHelper . TransformPixelsToDIP ( this , 0 ,
342
+ screen . WorkingArea . Y + _settings . CustomWindowTop ) . Y ;
343
+ break ;
344
+ }
323
345
}
324
346
}
325
-
326
347
}
327
348
328
349
private void UpdateNotifyIconText ( )
329
350
{
330
351
var menu = contextMenu ;
331
- ( ( MenuItem ) menu . Items [ 0 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayOpen" ) + " (" + _settings . Hotkey + ")" ;
352
+ ( ( MenuItem ) menu . Items [ 0 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayOpen" ) +
353
+ " (" + _settings . Hotkey + ")" ;
332
354
( ( MenuItem ) menu . Items [ 1 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) ;
333
355
( ( MenuItem ) menu . Items [ 2 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "PositionReset" ) ;
334
356
( ( MenuItem ) menu . Items [ 3 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" ) ;
335
357
( ( MenuItem ) menu . Items [ 4 ] ) . Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) ;
336
-
337
358
}
338
359
339
360
private void InitializeNotifyIcon ( )
@@ -345,50 +366,34 @@ private void InitializeNotifyIcon()
345
366
Visible = ! _settings . HideNotifyIcon
346
367
} ;
347
368
348
- var openIcon = new FontIcon
349
- {
350
- Glyph = "\ue71e "
351
- } ;
369
+ var openIcon = new FontIcon { Glyph = "\ue71e " } ;
352
370
var open = new MenuItem
353
371
{
354
- Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayOpen" ) + " (" + _settings . Hotkey + ")" ,
372
+ Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayOpen" ) + " (" +
373
+ _settings . Hotkey + ")" ,
355
374
Icon = openIcon
356
375
} ;
357
- var gamemodeIcon = new FontIcon
358
- {
359
- Glyph = "\ue7fc "
360
- } ;
376
+ var gamemodeIcon = new FontIcon { Glyph = "\ue7fc " } ;
361
377
var gamemode = new MenuItem
362
378
{
363
- Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) ,
364
- Icon = gamemodeIcon
365
- } ;
366
- var positionresetIcon = new FontIcon
367
- {
368
- Glyph = "\ue73f "
379
+ Header = InternationalizationManager . Instance . GetTranslation ( "GameMode" ) , Icon = gamemodeIcon
369
380
} ;
381
+ var positionresetIcon = new FontIcon { Glyph = "\ue73f " } ;
370
382
var positionreset = new MenuItem
371
383
{
372
384
Header = InternationalizationManager . Instance . GetTranslation ( "PositionReset" ) ,
373
385
Icon = positionresetIcon
374
386
} ;
375
- var settingsIcon = new FontIcon
376
- {
377
- Glyph = "\ue713 "
378
- } ;
387
+ var settingsIcon = new FontIcon { Glyph = "\ue713 " } ;
379
388
var settings = new MenuItem
380
389
{
381
390
Header = InternationalizationManager . Instance . GetTranslation ( "iconTraySettings" ) ,
382
391
Icon = settingsIcon
383
392
} ;
384
- var exitIcon = new FontIcon
385
- {
386
- Glyph = "\ue7e8 "
387
- } ;
393
+ var exitIcon = new FontIcon { Glyph = "\ue7e8 " } ;
388
394
var exit = new MenuItem
389
395
{
390
- Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) ,
391
- Icon = exitIcon
396
+ Header = InternationalizationManager . Instance . GetTranslation ( "iconTrayExit" ) , Icon = exitIcon
392
397
} ;
393
398
394
399
open . Click += ( o , e ) => _viewModel . ToggleFlowLauncher ( ) ;
@@ -421,6 +426,7 @@ private void InitializeNotifyIcon()
421
426
{
422
427
_ = SetForegroundWindow ( hwndSource . Handle ) ;
423
428
}
429
+
424
430
contextMenu . Focus ( ) ;
425
431
break ;
426
432
}
@@ -454,8 +460,10 @@ private async void PositionReset()
454
460
455
461
private void InitProgressbarAnimation ( )
456
462
{
457
- var da = new DoubleAnimation ( ProgressBar . X2 , ActualWidth + 100 , new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
458
- var da1 = new DoubleAnimation ( ProgressBar . X1 , ActualWidth + 0 , new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
463
+ var da = new DoubleAnimation ( ProgressBar . X2 , ActualWidth + 100 ,
464
+ new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
465
+ var da1 = new DoubleAnimation ( ProgressBar . X1 , ActualWidth + 0 ,
466
+ new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , 1600 ) ) ) ;
459
467
Storyboard . SetTargetProperty ( da , new PropertyPath ( "(Line.X2)" ) ) ;
460
468
Storyboard . SetTargetProperty ( da1 , new PropertyPath ( "(Line.X1)" ) ) ;
461
469
_progressBarStoryboard . Children . Add ( da ) ;
@@ -565,6 +573,7 @@ public void WindowAnimator()
565
573
{
566
574
clocksb . Begin ( ClockPanel ) ;
567
575
}
576
+
568
577
iconsb . Begin ( SearchIcon ) ;
569
578
windowsb . Begin ( FlowMainWindow ) ;
570
579
}
@@ -641,6 +650,9 @@ private void UpdatePosition()
641
650
{
642
651
if ( _animating )
643
652
return ;
653
+
654
+ // Initialize call twice to work around multi-display alignment issue- https://github.com/Flow-Launcher/Flow.Launcher/issues/2910
655
+ InitializePosition ( ) ;
644
656
InitializePosition ( ) ;
645
657
}
646
658
@@ -671,7 +683,7 @@ public void HideStartup()
671
683
public Screen SelectedScreen ( )
672
684
{
673
685
Screen screen = null ;
674
- switch ( _settings . SearchWindowScreen )
686
+ switch ( _settings . SearchWindowScreen )
675
687
{
676
688
case SearchWindowScreens . Cursor :
677
689
screen = Screen . FromPoint ( System . Windows . Forms . Cursor . Position ) ;
@@ -693,6 +705,7 @@ public Screen SelectedScreen()
693
705
screen = Screen . AllScreens [ 0 ] ;
694
706
break ;
695
707
}
708
+
696
709
return screen ?? Screen . AllScreens [ 0 ] ;
697
710
}
698
711
@@ -762,13 +775,15 @@ private void OnKeyDown(object sender, KeyEventArgs e)
762
775
_viewModel . LoadContextMenuCommand . Execute ( null ) ;
763
776
e . Handled = true ;
764
777
}
778
+
765
779
break ;
766
780
case Key . Left :
767
781
if ( ! _viewModel . SelectedIsFromQueryResults ( ) && QueryTextBox . CaretIndex == 0 )
768
782
{
769
783
_viewModel . EscCommand . Execute ( null ) ;
770
784
e . Handled = true ;
771
785
}
786
+
772
787
break ;
773
788
case Key . Back :
774
789
if ( specialKeyState . CtrlPressed )
@@ -787,12 +802,13 @@ private void OnKeyDown(object sender, KeyEventArgs e)
787
802
}
788
803
}
789
804
}
805
+
790
806
break ;
791
807
default :
792
808
break ;
793
-
794
809
}
795
810
}
811
+
796
812
private void OnKeyUp ( object sender , KeyEventArgs e )
797
813
{
798
814
if ( e . Key == Key . Up || e . Key == Key . Down )
@@ -808,6 +824,7 @@ private void MainPreviewMouseMove(object sender, System.Windows.Input.MouseEvent
808
824
e . Handled = true ; // Ignore Mouse Hover when press Arrowkeys
809
825
}
810
826
}
827
+
811
828
public void PreviewReset ( )
812
829
{
813
830
_viewModel . ResetPreview ( ) ;
0 commit comments