|
24 | 24 | using System.Windows.Data;
|
25 | 25 | using ModernWpf.Controls;
|
26 | 26 | using Key = System.Windows.Input.Key;
|
27 |
| -using System.Threading; |
28 | 27 | using System.Media;
|
29 |
| - |
| 28 | +using System.Linq; |
30 | 29 |
|
31 | 30 | namespace Flow.Launcher
|
32 | 31 | {
|
@@ -207,31 +206,31 @@ private void InitializePosition()
|
207 | 206 | Top = _settings.WindowTop;
|
208 | 207 | Left = _settings.WindowLeft;
|
209 | 208 | }
|
210 |
| - else if (_settings.SearchWindowScreen == SearchWindowScreens.CustomPosition) |
211 |
| - { |
212 |
| - Top = _settings.CustomWindowTop; |
213 |
| - Left = _settings.CustomWindowLeft; |
214 |
| - } |
215 | 209 | else
|
216 | 210 | {
|
| 211 | + var screen = SelectedScreen(); |
217 | 212 | switch (_settings.SearchWindowAlign)
|
218 | 213 | {
|
219 | 214 | case SearchWindowAligns.Center:
|
220 |
| - Left = HorizonCenter(); |
221 |
| - Top = VerticalCenter(); |
| 215 | + Left = HorizonCenter(screen); |
| 216 | + Top = VerticalCenter(screen); |
222 | 217 | break;
|
223 | 218 | case SearchWindowAligns.CenterTop:
|
224 |
| - Left = HorizonCenter(); |
| 219 | + Left = HorizonCenter(screen); |
225 | 220 | Top = 10;
|
226 | 221 | break;
|
227 | 222 | case SearchWindowAligns.LeftTop:
|
228 |
| - Left = HorizonLeft(); |
| 223 | + Left = HorizonLeft(screen); |
229 | 224 | Top = 10;
|
230 | 225 | break;
|
231 | 226 | case SearchWindowAligns.RightTop:
|
232 |
| - Left = HorizonRight(); |
| 227 | + Left = HorizonRight(screen); |
233 | 228 | Top = 10;
|
234 | 229 | break;
|
| 230 | + case SearchWindowAligns.Custom: |
| 231 | + Left = screen.WorkingArea.Left + _settings.CustomWindowLeft; |
| 232 | + Top = screen.WorkingArea.Top + _settings.CustomWindowTop; |
| 233 | + break; |
235 | 234 | }
|
236 | 235 | }
|
237 | 236 |
|
@@ -351,8 +350,9 @@ private async void PositionReset()
|
351 | 350 | {
|
352 | 351 | _viewModel.Show();
|
353 | 352 | await Task.Delay(300); // If don't give a time, Positioning will be weird.
|
354 |
| - Left = HorizonCenter(); |
355 |
| - Top = VerticalCenter(); |
| 353 | + var screen = SelectedScreen(); |
| 354 | + Left = HorizonCenter(screen); |
| 355 | + Top = VerticalCenter(screen); |
356 | 356 | }
|
357 | 357 |
|
358 | 358 | private void InitProgressbarAnimation()
|
@@ -536,59 +536,56 @@ public void HideStartup()
|
536 | 536 |
|
537 | 537 | public Screen SelectedScreen()
|
538 | 538 | {
|
539 |
| - if (_settings.SearchWindowScreen == SearchWindowScreens.MouseScreen) |
540 |
| - { |
541 |
| - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); |
542 |
| - return screen; |
543 |
| - } |
544 |
| - else if (_settings.SearchWindowScreen == SearchWindowScreens.PrimaryScreen) |
545 |
| - { |
546 |
| - var screen = Screen.PrimaryScreen; |
547 |
| - return screen; |
548 |
| - } |
549 |
| - else if (_settings.SearchWindowScreen == SearchWindowScreens.SecondaryScreen) |
550 |
| - { |
551 |
| - var screen = Screen.AllScreens[1]; |
552 |
| - return screen; |
553 |
| - } |
554 |
| - else |
| 539 | + Screen screen = null; |
| 540 | + switch(_settings.SearchWindowScreen) |
555 | 541 | {
|
556 |
| - var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); |
557 |
| - return screen; |
| 542 | + case SearchWindowScreens.Cursor: |
| 543 | + screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); |
| 544 | + break; |
| 545 | + case SearchWindowScreens.Primary: |
| 546 | + screen = Screen.PrimaryScreen; |
| 547 | + break; |
| 548 | + case SearchWindowScreens.Focus: |
| 549 | + IntPtr foregroundWindowHandle = WindowsInteropHelper.GetForegroundWindow(); |
| 550 | + screen = Screen.FromHandle(foregroundWindowHandle); |
| 551 | + break; |
| 552 | + case SearchWindowScreens.Custom: |
| 553 | + screen = Screen.AllScreens.FirstOrDefault(s => s.DeviceName == _settings.CustomScreenDeviceName); |
| 554 | + break; |
| 555 | + default: |
| 556 | + screen = Screen.AllScreens[0]; |
| 557 | + break; |
558 | 558 | }
|
| 559 | + return screen ?? Screen.AllScreens[0]; |
559 | 560 | }
|
560 |
| - public double HorizonCenter() |
| 561 | + |
| 562 | + public double HorizonCenter(Screen screen) |
561 | 563 | {
|
562 |
| - var screen = SelectedScreen(); |
563 | 564 | var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
|
564 | 565 | var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
|
565 | 566 | var left = (dip2.X - ActualWidth) / 2 + dip1.X;
|
566 | 567 | return left;
|
567 | 568 | }
|
568 | 569 |
|
569 |
| - public double VerticalCenter() |
| 570 | + public double VerticalCenter(Screen screen) |
570 | 571 | {
|
571 |
| - var screen = SelectedScreen(); |
572 | 572 | var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
|
573 | 573 | var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
|
574 | 574 | var top = (dip2.Y - QueryTextBox.ActualHeight) / 4 + dip1.Y;
|
575 | 575 | return top;
|
576 | 576 | }
|
577 | 577 |
|
578 |
| - public double HorizonRight() |
| 578 | + public double HorizonRight(Screen screen) |
579 | 579 | {
|
580 |
| - var screen = SelectedScreen(); |
581 | 580 | var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
|
582 | 581 | var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
|
583 | 582 | var left = (dip1.X + dip2.X - ActualWidth) - 10;
|
584 | 583 | return left;
|
585 | 584 | }
|
586 | 585 |
|
587 |
| - public double HorizonLeft() |
| 586 | + public double HorizonLeft(Screen screen) |
588 | 587 | {
|
589 |
| - var screen = SelectedScreen(); |
590 | 588 | var dip1 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
|
591 |
| - var dip2 = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0); |
592 | 589 | var left = dip1.X + 10;
|
593 | 590 | return left;
|
594 | 591 | }
|
|
0 commit comments