mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
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.
This commit is contained in:
parent
08af45fd3c
commit
bebff8321f
1 changed files with 21 additions and 3 deletions
|
|
@ -110,19 +110,37 @@ public partial class SettingWindow
|
|||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue