Skip to content

Commit d0a8f51

Browse files
authored
Merge pull request #2848 from z1nc0r3/window-position-validate
Add function to validate previous Window position
2 parents 5e59892 + bebff83 commit d0a8f51

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,37 @@ private void Window_StateChanged(object sender, EventArgs e)
110110

111111
public void InitializePosition()
112112
{
113-
if (_settings.SettingWindowTop == null || _settings.SettingWindowLeft == null)
113+
var previousTop = _settings.SettingWindowTop;
114+
var previousLeft = _settings.SettingWindowLeft;
115+
116+
if (previousTop == null || previousLeft == null || !IsPositionValid(previousTop.Value, previousLeft.Value))
114117
{
115118
Top = WindowTop();
116119
Left = WindowLeft();
117120
}
118121
else
119122
{
120-
Top = _settings.SettingWindowTop.Value;
121-
Left = _settings.SettingWindowLeft.Value;
123+
Top = previousTop.Value;
124+
Left = previousLeft.Value;
122125
}
123126
WindowState = _settings.SettingWindowState;
124127
}
125128

129+
private bool IsPositionValid(double top, double left)
130+
{
131+
foreach (var screen in Screen.AllScreens)
132+
{
133+
var workingArea = screen.WorkingArea;
134+
135+
if (left >= workingArea.Left && left < workingArea.Right &&
136+
top >= workingArea.Top && top < workingArea.Bottom)
137+
{
138+
return true;
139+
}
140+
}
141+
return false;
142+
}
143+
126144
private double WindowLeft()
127145
{
128146
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);

0 commit comments

Comments
 (0)