mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #2848 from z1nc0r3/window-position-validate
Add function to validate previous Window position
This commit is contained in:
commit
d0a8f51114
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