[Settings]Remember maximized state (#31424)

* restore settings in maximized state

* fix using
This commit is contained in:
Davide Giacometti
2024-02-20 11:40:53 +01:00
committed by GitHub
parent 0afec7293b
commit e607b26df6
2 changed files with 16 additions and 3 deletions

View File

@@ -82,7 +82,7 @@ namespace Microsoft.PowerToys.Settings.UI
{
if (settingsWindow == null)
{
settingsWindow = new MainWindow(IsDarkTheme());
settingsWindow = new MainWindow();
}
settingsWindow.Activate();
@@ -92,7 +92,7 @@ namespace Microsoft.PowerToys.Settings.UI
settingsWindow.NavigateToSection(type);
WindowHelpers.BringToForeground(settingsWindow.GetWindowHandle());
}
}
if (ensurePageIsSelected)
{

View File

@@ -7,7 +7,6 @@ using ManagedCommon;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.OOBE.Views;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.PowerToys.Telemetry;
using Microsoft.UI;
@@ -41,6 +40,9 @@ namespace Microsoft.PowerToys.Settings.UI
if (createHidden)
{
placement.ShowCmd = NativeMethods.SW_HIDE;
// Restore the last known placement on the first activation
this.Activated += Window_Activated;
}
NativeMethods.SetWindowPlacement(hWnd, ref placement);
@@ -213,6 +215,17 @@ namespace Microsoft.PowerToys.Settings.UI
}
}
private void Window_Activated(object sender, WindowActivatedEventArgs args)
{
if (args.WindowActivationState != WindowActivationState.Deactivated)
{
this.Activated -= Window_Activated;
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
var placement = Utils.DeserializePlacementOrDefault(hWnd);
NativeMethods.SetWindowPlacement(hWnd, ref placement);
}
}
internal void EnsurePageIsSelected()
{
ShellPage.EnsurePageIsSelected();