优化交互显示界面

This commit is contained in:
liufei
2021-07-29 17:04:36 +08:00
parent 3c78b058cf
commit 0a89255ad2
5 changed files with 116 additions and 52 deletions

View File

@@ -18,6 +18,7 @@ using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using static GeekDesk.Util.ShowWindowFollowMouse;
namespace GeekDesk
{
@@ -260,7 +261,7 @@ namespace GeekDesk
{
if (appData.AppConfig.FollowMouse)
{
ShowAppAndFollowMouse();
ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0);
} else
{
mainWindow.Visibility = Visibility.Visible;
@@ -268,54 +269,7 @@ namespace GeekDesk
Keyboard.Focus(mainWindow);
}
/// <summary>
/// 随鼠标位置显示面板 (鼠标始终在中间)
/// </summary>
private static void ShowAppAndFollowMouse()
{
//获取鼠标位置
System.Windows.Point p = MouseUtil.GetMousePosition();
double left = SystemParameters.VirtualScreenLeft;
double top = SystemParameters.VirtualScreenTop;
double width = SystemParameters.VirtualScreenWidth;
double height = SystemParameters.VirtualScreenHeight;
double right = width - Math.Abs(left);
double bottom = height - Math.Abs(top);
if (p.X - mainWindow.Width / 2 < left)
{
//判断是否在最左边缘
mainWindow.Left = left;
}
else if (p.X + mainWindow.Width / 2 > right)
{
//判断是否在最右边缘
mainWindow.Left = right - mainWindow.Width;
}
else
{
mainWindow.Left = p.X - mainWindow.Width / 2;
}
if (p.Y - mainWindow.Height / 2 < top)
{
//判断是否在最上边缘
mainWindow.Top = top;
}
else if (p.Y + mainWindow.Height / 2 > bottom)
{
//判断是否在最下边缘
mainWindow.Top = bottom - mainWindow.Height;
}
else
{
mainWindow.Top = p.Y - mainWindow.Height / 2;
}
mainWindow.Visibility = Visibility.Visible;
}
/// <summary>