diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index de4fd1f9129..4cc125fa4af 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -110,19 +110,37 @@ private void Window_StateChanged(object sender, EventArgs e) public void InitializePosition() { - if (_settings.SettingWindowTop == null || _settings.SettingWindowLeft == null) + var previousTop = _settings.SettingWindowTop; + var previousLeft = _settings.SettingWindowLeft; + + if (previousTop == null || previousLeft == null || !IsPositionValid(previousTop.Value, previousLeft.Value)) { Top = WindowTop(); Left = WindowLeft(); } else { - Top = _settings.SettingWindowTop.Value; - Left = _settings.SettingWindowLeft.Value; + Top = previousTop.Value; + Left = previousLeft.Value; } WindowState = _settings.SettingWindowState; } + private bool IsPositionValid(double top, double left) + { + foreach (var screen in Screen.AllScreens) + { + var workingArea = screen.WorkingArea; + + if (left >= workingArea.Left && left < workingArea.Right && + top >= workingArea.Top && top < workingArea.Bottom) + { + return true; + } + } + return false; + } + private double WindowLeft() { var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);