diff --git a/src/settings-ui/PowerToys.Settings/App.xaml.cs b/src/settings-ui/PowerToys.Settings/App.xaml.cs index 56b244638f..f4a958d3fe 100644 --- a/src/settings-ui/PowerToys.Settings/App.xaml.cs +++ b/src/settings-ui/PowerToys.Settings/App.xaml.cs @@ -33,20 +33,8 @@ namespace PowerToys.Settings { settingsWindow = new MainWindow(); - // To avoid visual flickering, show the window with a size of 0,0 - // and don't show it in the taskbar - var originalHight = settingsWindow.Height; - var originalWidth = settingsWindow.Width; - settingsWindow.Height = 0; - settingsWindow.Width = 0; - settingsWindow.ShowInTaskbar = false; - - settingsWindow.Show(); - settingsWindow.Hide(); - - settingsWindow.Height = originalHight; - settingsWindow.Width = originalWidth; - settingsWindow.ShowInTaskbar = true; + Utils.ShowHide(settingsWindow); + Utils.CenterToScreen(settingsWindow); } private void Application_Startup(object sender, StartupEventArgs e) diff --git a/src/settings-ui/PowerToys.Settings/MainWindow.xaml b/src/settings-ui/PowerToys.Settings/MainWindow.xaml index 0899c7ece7..6735a3e2d5 100644 --- a/src/settings-ui/PowerToys.Settings/MainWindow.xaml +++ b/src/settings-ui/PowerToys.Settings/MainWindow.xaml @@ -7,7 +7,15 @@ xmlns:Controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls" xmlns:xaml="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost" mc:Ignorable="d" - Title="PowerToys Settings" MinWidth="480" Height="800" Width="1100" Closing="MainWindow_Closing" Loaded="MainWindow_Loaded" Activated="MainWindow_Activated"> + Title="PowerToys Settings" + Height="860" + MinHeight="400" + Width="1180" + MinWidth="480" + WindowStartupLocation="CenterScreen" + Closing="MainWindow_Closing" + Loaded="MainWindow_Loaded" + Activated="MainWindow_Activated"> diff --git a/src/settings-ui/PowerToys.Settings/MainWindow.xaml.cs b/src/settings-ui/PowerToys.Settings/MainWindow.xaml.cs index 7a4848da90..c8b253a837 100644 --- a/src/settings-ui/PowerToys.Settings/MainWindow.xaml.cs +++ b/src/settings-ui/PowerToys.Settings/MainWindow.xaml.cs @@ -26,6 +26,9 @@ namespace PowerToys.Settings bootTime.Start(); this.InitializeComponent(); + + Utils.FitToScreen(this); + bootTime.Stop(); PowerToysTelemetry.Log.WriteEvent(new SettingsBootEvent() { BootTimeMs = bootTime.ElapsedMilliseconds }); diff --git a/src/settings-ui/PowerToys.Settings/OobeWindow.xaml.cs b/src/settings-ui/PowerToys.Settings/OobeWindow.xaml.cs index dec8fe81f7..7be7a88075 100644 --- a/src/settings-ui/PowerToys.Settings/OobeWindow.xaml.cs +++ b/src/settings-ui/PowerToys.Settings/OobeWindow.xaml.cs @@ -30,6 +30,7 @@ namespace PowerToys.Settings public OobeWindow() { InitializeComponent(); + Utils.FitToScreen(this); } private void Window_Closed(object sender, EventArgs e) diff --git a/src/settings-ui/PowerToys.Settings/Utils.cs b/src/settings-ui/PowerToys.Settings/Utils.cs new file mode 100644 index 0000000000..de5e329d55 --- /dev/null +++ b/src/settings-ui/PowerToys.Settings/Utils.cs @@ -0,0 +1,70 @@ +// 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.Windows; + +namespace PowerToys.Settings +{ + internal class Utils + { + public static void FitToScreen(Window window) + { + if (SystemParameters.WorkArea.Width < window.Width) + { + window.Width = SystemParameters.WorkArea.Width; + } + + if (SystemParameters.WorkArea.Height < window.Height) + { + window.Height = SystemParameters.WorkArea.Height; + } + } + + public static void CenterToScreen(Window window) + { + if (SystemParameters.WorkArea.Height <= window.Height) + { + window.Top = 0; + } + else + { + window.Top = (SystemParameters.WorkArea.Height - window.Height) / 2; + } + + if (SystemParameters.WorkArea.Width <= window.Width) + { + window.Left = 0; + } + else + { + window.Left = (SystemParameters.WorkArea.Width - window.Width) / 2; + } + } + + public static void ShowHide(Window window) + { + // To limit the visual flickering, show the window with a size of 0,0 + // and don't show it in the taskbar + var originalHeight = window.Height; + var originalWidth = window.Width; + var originalMinHeight = window.MinHeight; + var originalMinWidth = window.MinWidth; + + window.MinHeight = 0; + window.MinWidth = 0; + window.Height = 0; + window.Width = 0; + window.ShowInTaskbar = false; + + window.Show(); + window.Hide(); + + window.Height = originalHeight; + window.Width = originalWidth; + window.MinHeight = originalMinHeight; + window.MinWidth = originalMinWidth; + window.ShowInTaskbar = true; + } + } +}