Skip to content

Commit

Permalink
Prevent ServerLogWindow from being out of screens
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed Oct 9, 2019
1 parent b3e1dc2 commit a8768fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion shadowsocks-csharp/Model/WindowStatus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using Shadowsocks.Util;
using System.Windows;

namespace Shadowsocks.Model
{
Expand Down Expand Up @@ -35,6 +36,7 @@ public void SetStatus(Window window)
window.Left = Left;
window.Top = Top;
window.WindowState = State;
window.WindowStartupLocation = ViewUtils.IsOnScreen(window) ? WindowStartupLocation.Manual : WindowStartupLocation.CenterScreen;
}
}
}
15 changes: 15 additions & 0 deletions shadowsocks-csharp/Util/ViewUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,20 @@ public static void SetResource(ResourceDictionary resources, string filename, in
resources.MergedDictionaries.Add(langRd);
}
}

public static bool IsOnScreen(Window window)
{
return IsOnScreen(window.Left, window.Top)
|| IsOnScreen(window.Left + window.Width, window.Top + window.Height);
}

public static bool IsOnScreen(double x, double y)
{
return
SystemParameters.VirtualScreenLeft <= x &&
SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth >= x &&
SystemParameters.VirtualScreenTop <= y &&
SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight >= y;
}
}
}
1 change: 0 additions & 1 deletion shadowsocks-csharp/View/ServerLogWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public ServerLogWindow(ShadowsocksController controller, WindowStatus status)
else
{
SizeToContent = SizeToContent.Manual;
WindowStartupLocation = WindowStartupLocation.Manual;
status.SetStatus(this);
}
}
Expand Down

0 comments on commit a8768fb

Please sign in to comment.