Skip to content

Commit bebff83

Browse files
committed
Add function to validate window position
A new function was added to check whether the previously saved Window position is still valid or not. If not it resets the Window position to default.
1 parent 08af45f commit bebff83

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)