From 29b71e7f44b58a87d6ec4e044c24e18b7f59ee11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9E=AB=E9=9B=A8?= <737345039@qq.com>
Date: Thu, 6 Apr 2023 18:09:18 +0800
Subject: [PATCH] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4=E6=9D=A1=E4=BB=B6?=
=?UTF-8?q?=E6=89=A7=E8=A1=8C=E8=AF=AD=E5=8F=A5=E7=9A=84=E4=BD=9C=E7=94=A8?=
=?UTF-8?q?=E5=9F=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/MaaWpfGui/Helper/WindowManager.cs | 57 ++++++++++++++++-----------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/src/MaaWpfGui/Helper/WindowManager.cs b/src/MaaWpfGui/Helper/WindowManager.cs
index 9243e29491..d754daf7de 100644
--- a/src/MaaWpfGui/Helper/WindowManager.cs
+++ b/src/MaaWpfGui/Helper/WindowManager.cs
@@ -39,8 +39,16 @@ namespace MaaWpfGui.Helper
private readonly double Width = double.Parse(ConfigurationHelper.GetValue(ConfigurationKeys.WindowWidth, DefaultDouble.ToString(CultureInfo.InvariantCulture)), CultureInfo.InvariantCulture);
private readonly double Height = double.Parse(ConfigurationHelper.GetValue(ConfigurationKeys.WindowHeight, DefaultDouble.ToString(CultureInfo.InvariantCulture)), CultureInfo.InvariantCulture);
- public void MoveWindowToDisplay(string displayName, Window window)
+ ///
+ /// Move MaaWpfGui.RootView
+ ///
+ private void MoveWindowToDisplay(string displayName, Window window)
{
+ if (Math.Abs(Left - DefaultDouble) < 0.01f || Math.Abs(Top - DefaultDouble) < 0.01f)
+ {
+ return;
+ }
+
var screen = Screen.AllScreens.FirstOrDefault(x => x.DeviceName == displayName);
if (screen != null)
{
@@ -56,37 +64,40 @@ namespace MaaWpfGui.Helper
}
}
+ ///
+ /// Center other windows in MaaWpfGui.RootView
+ ///
+ private void MoveWindowToDisplay(Window window)
+ {
+ var mainWindow = Application.Current.MainWindow;
+ if (mainWindow.WindowState == WindowState.Normal)
+ {
+ // In Stylet, CreateWindow().WindowStartupLocation is CenterScreen or CenterOwner (if w.WSLoc == Manual && w.Left == NaN && w.Top == NaN && ...)
+ window.WindowStartupLocation = WindowStartupLocation.Manual;
+ window.Left = mainWindow!.Left + ((mainWindow.Width - window.Width) / 2);
+ window.Top = mainWindow.Top + ((mainWindow.Height - window.Height) / 2);
+ }
+ }
+
///
protected override Window CreateWindow(object viewModel, bool isDialog, IViewAware ownerViewModel)
{
Window window = base.CreateWindow(viewModel, isDialog, ownerViewModel);
- if (bool.Parse(ConfigurationHelper.GetValue(ConfigurationKeys.LoadPositionAndSize, bool.TrueString)))
+ if (window is RootView)
{
- if (isDialog || ownerViewModel != null || Math.Abs(Left - DefaultDouble) < 0.01f || Math.Abs(Top - DefaultDouble) < 0.01f)
- {
- return window;
- }
-
- if (window is RootView)
+ bool needMoveRootView = bool.Parse(ConfigurationHelper.GetValue(ConfigurationKeys.LoadPositionAndSize, bool.TrueString));
+ if (needMoveRootView)
{
MoveWindowToDisplay(ScreenName, window);
}
- else
- {
- // Center other windows in MaaWpfGui.RootView
- var mainWindow = Application.Current.MainWindow;
- if (mainWindow.WindowState == WindowState.Normal)
- {
- // In Stylet, CreateWindow().WindowStartupLocation is CenterScreen or CenterOwner (if w.WSLoc == Manual && w.Left == NaN && w.Top == NaN && ...)
- window.WindowStartupLocation = WindowStartupLocation.Manual;
- window.Left = mainWindow!.Left + ((mainWindow.Width - window.Width) / 2);
- window.Top = mainWindow.Top + ((mainWindow.Height - window.Height) / 2);
- }
- }
- }
- var app = Application.Current as App;
- app!.DarkToStart();
+ var app = Application.Current as App;
+ app!.DarkToStart();
+ }
+ else if (!isDialog && ownerViewModel == null)
+ {
+ MoveWindowToDisplay(window);
+ }
return window;
}