[settings] Fix OOBE size and make it non-resizable & Bring back Settings window placement preserve logic (#17822)

* Fix OOBE size and make it non-resizable
Bring back Settings window placement preserve logic

* Disable OOBE maximize&minimize

* expect.txt

* Remove uneeded line

* Remove uneeded check

* Add brackets
This commit is contained in:
Stefan Markovic 2022-04-20 17:08:25 +02:00 committed by GitHub
parent 40300c1e4f
commit b3c520ed54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 0 deletions

View File

@ -1157,6 +1157,7 @@ Marquesas
martinchrzan
martinmoene
Mato
Maximizable
MAXIMIZEBOX
MAXSHORTCUTSIZE
maxversiontested
@ -1203,6 +1204,7 @@ millis
mimetype
mindaro
Minimatch
Minimizable
MINIMIZEBOX
MINIMIZEEND
MINIMIZESTART

View File

@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Helpers
{
internal class Utils
{
private static string _placementPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\PowerToys\settings-placement.json");
public static WINDOWPLACEMENT DeserializePlacementOrDefault(IntPtr handle)
{
try
{
var json = File.ReadAllText(_placementPath);
var placement = JsonSerializer.Deserialize<WINDOWPLACEMENT>(json);
placement.Length = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
placement.Flags = 0;
placement.ShowCmd = (placement.ShowCmd == NativeMethods.SW_SHOWMAXIMIZED) ? NativeMethods.SW_SHOWMAXIMIZED : NativeMethods.SW_SHOWNORMAL;
return placement;
}
catch (Exception)
{
}
_ = NativeMethods.GetWindowPlacement(handle, out var defaultPlacement);
return defaultPlacement;
}
public static void SerializePlacement(IntPtr handle)
{
_ = NativeMethods.GetWindowPlacement(handle, out var placement);
try
{
var json = JsonSerializer.Serialize(placement);
File.WriteAllText(_placementPath, json);
}
catch (Exception)
{
}
}
}
}

View File

@ -3,7 +3,9 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Drawing;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.PowerToys.Telemetry;
@ -34,6 +36,9 @@ namespace Microsoft.PowerToys.Settings.UI
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
appWindow.SetIcon("icon.ico");
var placement = Utils.DeserializePlacementOrDefault(hWnd);
NativeMethods.SetWindowPlacement(hWnd, ref placement);
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
Title = loader.GetString("SettingsWindow_Title");
@ -103,6 +108,9 @@ namespace Microsoft.PowerToys.Settings.UI
private void Window_Closed(object sender, WindowEventArgs args)
{
App.ClearSettingsWindow();
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
Utils.SerializePlacement(hWnd);
}
}
}

View File

@ -10,6 +10,7 @@ using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Windows.ApplicationModel.Resources;
using Windows.Graphics;
namespace Microsoft.PowerToys.Settings.UI
{
@ -30,6 +31,16 @@ namespace Microsoft.PowerToys.Settings.UI
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
appWindow.SetIcon("icon.ico");
OverlappedPresenter presenter = appWindow.Presenter as OverlappedPresenter;
presenter.IsResizable = false;
presenter.IsMinimizable = false;
presenter.IsMaximizable = false;
SizeInt32 size;
size.Width = 1650;
size.Height = 1050;
appWindow.Resize(size);
this.initialModule = initialModule;
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();