[Workspaces] fixing bug: editor starts outside of visible desktop area (#36769)

* [Workspaces] fixing bug: editor starts outside of visible desktop area

* Update src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml.cs

Co-authored-by: Seraphima Zykova <zykovas91@gmail.com>

---------

Co-authored-by: Seraphima Zykova <zykovas91@gmail.com>
This commit is contained in:
Laszlo Nemeth 2025-01-16 10:56:11 +01:00 коммит произвёл GitHub
Родитель 315059fc3b
Коммит 603379a1ad
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 18 добавлений и 3 удалений

Просмотреть файл

@ -3,10 +3,11 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Interop;
using ManagedCommon;
using Microsoft.PowerToys.Telemetry;
using WorkspacesEditor.Utils;
@ -30,9 +31,9 @@ namespace WorkspacesEditor
MainViewModel = mainViewModel;
mainViewModel.SetMainWindow(this);
if (Properties.Settings.Default.Height == -1)
if (Properties.Settings.Default.Height == -1 || !IsEditorInsideVisibleArea())
{
// This is the very first time the window is created. Place it on the screen center
// This is the very first time the window is created or it would be placed outside the visible area (monitor rearrangement). Place it on the screen center
WindowInteropHelper windowInteropHelper = new WindowInteropHelper(this);
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle);
double dpi = MonitorHelper.GetScreenDpiFromScreen(screen);
@ -88,6 +89,20 @@ namespace WorkspacesEditor
cancellationToken.Token);
}
private bool IsEditorInsideVisibleArea()
{
System.Windows.Forms.Screen[] allScreens = MonitorHelper.GetDpiUnawareScreens();
Rectangle commonBounds = allScreens[0].Bounds;
for (int screenIndex = 1; screenIndex < allScreens.Length; screenIndex++)
{
Rectangle rectangle = allScreens[screenIndex].Bounds;
commonBounds = Rectangle.Union(rectangle, commonBounds);
}
Rectangle editorBounds = new Rectangle((int)Properties.Settings.Default.Left, (int)Properties.Settings.Default.Top, (int)Properties.Settings.Default.Width, (int)Properties.Settings.Default.Height);
return editorBounds.IntersectsWith(commonBounds);
}
private void SavePosition()
{
if (WindowState == WindowState.Maximized)