mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[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:
2
.github/actions/spell-check/expect.txt
vendored
2
.github/actions/spell-check/expect.txt
vendored
@@ -1157,6 +1157,7 @@ Marquesas
|
|||||||
martinchrzan
|
martinchrzan
|
||||||
martinmoene
|
martinmoene
|
||||||
Mato
|
Mato
|
||||||
|
Maximizable
|
||||||
MAXIMIZEBOX
|
MAXIMIZEBOX
|
||||||
MAXSHORTCUTSIZE
|
MAXSHORTCUTSIZE
|
||||||
maxversiontested
|
maxversiontested
|
||||||
@@ -1203,6 +1204,7 @@ millis
|
|||||||
mimetype
|
mimetype
|
||||||
mindaro
|
mindaro
|
||||||
Minimatch
|
Minimatch
|
||||||
|
Minimizable
|
||||||
MINIMIZEBOX
|
MINIMIZEBOX
|
||||||
MINIMIZEEND
|
MINIMIZEEND
|
||||||
MINIMIZESTART
|
MINIMIZESTART
|
||||||
|
|||||||
49
src/settings-ui/Settings.UI/Helpers/Utils.cs
Normal file
49
src/settings-ui/Settings.UI/Helpers/Utils.cs
Normal 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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,9 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
using Microsoft.PowerLauncher.Telemetry;
|
using Microsoft.PowerLauncher.Telemetry;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
using Microsoft.PowerToys.Telemetry;
|
using Microsoft.PowerToys.Telemetry;
|
||||||
@@ -34,6 +36,9 @@ namespace Microsoft.PowerToys.Settings.UI
|
|||||||
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
|
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
|
||||||
appWindow.SetIcon("icon.ico");
|
appWindow.SetIcon("icon.ico");
|
||||||
|
|
||||||
|
var placement = Utils.DeserializePlacementOrDefault(hWnd);
|
||||||
|
NativeMethods.SetWindowPlacement(hWnd, ref placement);
|
||||||
|
|
||||||
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
||||||
Title = loader.GetString("SettingsWindow_Title");
|
Title = loader.GetString("SettingsWindow_Title");
|
||||||
|
|
||||||
@@ -103,6 +108,9 @@ namespace Microsoft.PowerToys.Settings.UI
|
|||||||
private void Window_Closed(object sender, WindowEventArgs args)
|
private void Window_Closed(object sender, WindowEventArgs args)
|
||||||
{
|
{
|
||||||
App.ClearSettingsWindow();
|
App.ClearSettingsWindow();
|
||||||
|
|
||||||
|
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||||
|
Utils.SerializePlacement(hWnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using Microsoft.UI;
|
|||||||
using Microsoft.UI.Windowing;
|
using Microsoft.UI.Windowing;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Windows.ApplicationModel.Resources;
|
using Windows.ApplicationModel.Resources;
|
||||||
|
using Windows.Graphics;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI
|
namespace Microsoft.PowerToys.Settings.UI
|
||||||
{
|
{
|
||||||
@@ -30,6 +31,16 @@ namespace Microsoft.PowerToys.Settings.UI
|
|||||||
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
|
AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
|
||||||
appWindow.SetIcon("icon.ico");
|
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;
|
this.initialModule = initialModule;
|
||||||
|
|
||||||
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
||||||
|
|||||||
Reference in New Issue
Block a user