From 319dfec92f6154a0e6104c370ec6c7579a4e3d5a Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Mon, 7 Apr 2025 14:59:46 +0200 Subject: [PATCH 1/8] MinWidth/Height and DPI-aware launch dimensions --- .../Microsoft.CmdPal.UI.csproj | 2 +- .../Settings/SettingsWindow.xaml | 13 +++++++++---- .../Settings/SettingsWindow.xaml.cs | 18 +++--------------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj index 9a4061f6bc78..af4c808b3f54 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj @@ -65,7 +65,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml index d9a81dc2ef5b..05afedc5e354 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml @@ -1,5 +1,5 @@  - - + - + @@ -100,4 +105,4 @@ - + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs index f4294983d538..3b35f38a2917 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs @@ -11,11 +11,12 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Windows.Graphics; +using WinUIEx; using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance; namespace Microsoft.CmdPal.UI.Settings; -public sealed partial class SettingsWindow : Window, +public sealed partial class SettingsWindow : WindowEx, IRecipient, IRecipient { @@ -28,7 +29,7 @@ public SettingsWindow() this.SetIcon(); this.AppWindow.Title = RS_.GetString("SettingsWindowTitle"); this.AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall; - PositionCentered(); + this.CenterOnScreen(); WeakReferenceMessenger.Default.Register(this); WeakReferenceMessenger.Default.Register(this); @@ -68,19 +69,6 @@ private void Navigate(ProviderSettingsViewModel extension) BreadCrumbs.Add(new(extension.DisplayName, string.Empty)); } - private void PositionCentered() - { - AppWindow.Resize(new SizeInt32 { Width = 1280, Height = 720 }); - var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest); - if (displayArea is not null) - { - var centeredPosition = AppWindow.Position; - centeredPosition.X = (displayArea.WorkArea.Width - AppWindow.Size.Width) / 2; - centeredPosition.Y = (displayArea.WorkArea.Height - AppWindow.Size.Height) / 2; - AppWindow.Move(centeredPosition); - } - } - public void Receive(NavigateToExtensionSettingsMessage message) => Navigate(message.ProviderSettingsVM); private void NavigationBreadcrumbBar_ItemClicked(BreadcrumbBar sender, BreadcrumbBarItemClickedEventArgs args) From c4da159c6a3beb2fd42aa30b8270d48e12d6f23e Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Mon, 7 Apr 2025 15:16:40 +0200 Subject: [PATCH 2/8] Making MainWindow DPI aware too --- .../Microsoft.CmdPal.UI/MainWindow.xaml | 8 ++++-- .../Microsoft.CmdPal.UI/MainWindow.xaml.cs | 28 +++---------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml index 4e5e8259a3b0..7bf7c035d3c1 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml @@ -1,4 +1,4 @@ - + - + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs index ac1b0e086056..fa20ef60cbac 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs @@ -28,11 +28,12 @@ using Windows.Win32.UI.Shell; using Windows.Win32.UI.WindowsAndMessaging; using WinRT; +using WinUIEx; using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance; namespace Microsoft.CmdPal.UI; -public sealed partial class MainWindow : Window, +public sealed partial class MainWindow : WindowEx, IRecipient, IRecipient, IRecipient, @@ -74,8 +75,7 @@ public MainWindow() this.SetIcon(); AppWindow.Title = RS_.GetString("AppName"); - AppWindow.Resize(new SizeInt32 { Width = 1000, Height = 620 }); - PositionCentered(); + this.CenterOnScreen(800, Height = 480); SetAcrylic(); WeakReferenceMessenger.Default.Register(this); @@ -124,26 +124,6 @@ private void RootShellPage_Loaded(object sender, RoutedEventArgs e) => private void WindowSizeChanged(object sender, WindowSizeChangedEventArgs args) => UpdateRegionsForCustomTitleBar(); - private void PositionCentered() - { - var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest); - PositionCentered(displayArea); - } - - private void PositionCentered(DisplayArea displayArea) - { - if (displayArea is not null) - { - var centeredPosition = AppWindow.Position; - centeredPosition.X = (displayArea.WorkArea.Width - AppWindow.Size.Width) / 2; - centeredPosition.Y = (displayArea.WorkArea.Height - AppWindow.Size.Height) / 2; - - centeredPosition.X += displayArea.WorkArea.X; - centeredPosition.Y += displayArea.WorkArea.Y; - AppWindow.Move(centeredPosition); - } - } - private void HotReloadSettings() { var settings = App.Current.Services.GetService()!; @@ -219,7 +199,7 @@ private void ShowHwnd(IntPtr hwndValue, MonitorBehavior target) } var display = GetScreen(hwnd, target); - PositionCentered(display); + this.CenterOnScreen(); PInvoke.ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_SHOW); PInvoke.SetForegroundWindow(hwnd); From 602666d215bf1e4f9ccbf24e34212433431fe247 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Mon, 7 Apr 2025 15:58:54 +0200 Subject: [PATCH 3/8] Moving toastwindow to WinUIEx too --- .../cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml | 11 ++++++----- .../cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml.cs | 12 ++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml index 06bcdd66fc7d..c52755dec91e 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml @@ -1,5 +1,5 @@  - - + - + - + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml.cs index e21c8dd55d0d..a848099335b1 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml.cs @@ -14,11 +14,12 @@ using Windows.Win32; using Windows.Win32.Foundation; using Windows.Win32.UI.WindowsAndMessaging; +using WinUIEx; using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance; namespace Microsoft.CmdPal.UI; -public sealed partial class ToastWindow : Window, +public sealed partial class ToastWindow : WindowEx, IRecipient { private readonly HWND _hwnd; @@ -46,12 +47,7 @@ public ToastWindow() private void PositionCentered() { - var intSize = new SizeInt32 - { - Width = Convert.ToInt32(ToastText.ActualWidth), - Height = Convert.ToInt32(ToastText.ActualHeight), - }; - AppWindow.Resize(intSize); + this.SetWindowSize(ToastText.ActualWidth, ToastText.ActualHeight); var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest); if (displayArea is not null) @@ -61,7 +57,7 @@ private void PositionCentered() var monitorHeight = displayArea.WorkArea.Height; var windowHeight = AppWindow.Size.Height; - centeredPosition.Y = monitorHeight - (windowHeight * 2); + centeredPosition.Y = monitorHeight - (windowHeight + 8); // Align with other shell toasts, like the volume indicator. AppWindow.Move(centeredPosition); } } From 429f6360aed900e5b1f3e0a0cad64921c8e4d7ac Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Mon, 14 Apr 2025 13:00:13 +0200 Subject: [PATCH 4/8] Update MainWindow.xaml.cs --- src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs index fa20ef60cbac..240c3296e5d6 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs @@ -75,7 +75,7 @@ public MainWindow() this.SetIcon(); AppWindow.Title = RS_.GetString("AppName"); - this.CenterOnScreen(800, Height = 480); + this.CenterOnScreen(800, 480); SetAcrylic(); WeakReferenceMessenger.Default.Register(this); From 1ab500d7d00ffd9be8e2cc8b65f7558643b50bd5 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 23 Apr 2025 16:45:15 +0200 Subject: [PATCH 5/8] Reverting back to the working logic --- .../Microsoft.CmdPal.UI/MainWindow.xaml | 2 ++ .../Microsoft.CmdPal.UI/MainWindow.xaml.cs | 24 +++++++++++++++++-- .../Settings/SettingsWindow.xaml.cs | 15 +++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml index 7bf7c035d3c1..e7acbdf76671 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml @@ -7,6 +7,8 @@ xmlns:pages="using:Microsoft.CmdPal.UI.Pages" xmlns:viewmodels="using:Microsoft.CmdPal.UI.ViewModels" xmlns:winuiex="using:WinUIEx" + Width="800" + Height="480" MinWidth="320" MinHeight="240" Activated="MainWindow_Activated" diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs index 240c3296e5d6..1ea0ad37371c 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs @@ -75,7 +75,7 @@ public MainWindow() this.SetIcon(); AppWindow.Title = RS_.GetString("AppName"); - this.CenterOnScreen(800, 480); + PositionCentered(); SetAcrylic(); WeakReferenceMessenger.Default.Register(this); @@ -124,6 +124,26 @@ private void RootShellPage_Loaded(object sender, RoutedEventArgs e) => private void WindowSizeChanged(object sender, WindowSizeChangedEventArgs args) => UpdateRegionsForCustomTitleBar(); + private void PositionCentered() + { + var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest); + PositionCentered(displayArea); + } + + private void PositionCentered(DisplayArea displayArea) + { + if (displayArea is not null) + { + var centeredPosition = AppWindow.Position; + centeredPosition.X = (displayArea.WorkArea.Width - AppWindow.Size.Width) / 2; + centeredPosition.Y = (displayArea.WorkArea.Height - AppWindow.Size.Height) / 2; + + centeredPosition.X += displayArea.WorkArea.X; + centeredPosition.Y += displayArea.WorkArea.Y; + AppWindow.Move(centeredPosition); + } + } + private void HotReloadSettings() { var settings = App.Current.Services.GetService()!; @@ -199,7 +219,7 @@ private void ShowHwnd(IntPtr hwndValue, MonitorBehavior target) } var display = GetScreen(hwnd, target); - this.CenterOnScreen(); + PositionCentered(display); PInvoke.ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_SHOW); PInvoke.SetForegroundWindow(hwnd); diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs index 3b35f38a2917..ce63a2764a3f 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs @@ -29,7 +29,7 @@ public SettingsWindow() this.SetIcon(); this.AppWindow.Title = RS_.GetString("SettingsWindowTitle"); this.AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall; - this.CenterOnScreen(); + PositionCentered(); WeakReferenceMessenger.Default.Register(this); WeakReferenceMessenger.Default.Register(this); @@ -69,6 +69,19 @@ private void Navigate(ProviderSettingsViewModel extension) BreadCrumbs.Add(new(extension.DisplayName, string.Empty)); } + private void PositionCentered() + { + AppWindow.Resize(new SizeInt32 { Width = 1280, Height = 720 }); + var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest); + if (displayArea is not null) + { + var centeredPosition = AppWindow.Position; + centeredPosition.X = (displayArea.WorkArea.Width - AppWindow.Size.Width) / 2; + centeredPosition.Y = (displayArea.WorkArea.Height - AppWindow.Size.Height) / 2; + AppWindow.Move(centeredPosition); + } + } + public void Receive(NavigateToExtensionSettingsMessage message) => Navigate(message.ProviderSettingsVM); private void NavigationBreadcrumbBar_ItemClicked(BreadcrumbBar sender, BreadcrumbBarItemClickedEventArgs args) From 8fc2d058501ad92ca0ec4b3b52823854c1c07541 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 23 Apr 2025 16:45:29 +0200 Subject: [PATCH 6/8] Localizing settings window title --- .../cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml index 05afedc5e354..38e88d269815 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml @@ -45,7 +45,7 @@ Margin="12,0,0,0" VerticalAlignment="Center" Style="{StaticResource CaptionTextBlockStyle}" - Text="Command Palette Settings" /> + x:Uid="CmdPalSettingsHeader" /> Date: Wed, 23 Apr 2025 17:54:59 +0200 Subject: [PATCH 7/8] Xaml formatting --- src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml | 1 - .../cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml | 4 ++-- src/modules/cmdpal/Microsoft.CmdPal.UI/ToastWindow.xaml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml index e7acbdf76671..450625cfb5a6 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml @@ -14,6 +14,5 @@ Activated="MainWindow_Activated" Closed="MainWindow_Closed" mc:Ignorable="d"> - diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml index 38e88d269815..ca82533e3f46 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml @@ -42,10 +42,10 @@ Height="16" Source="ms-appx:///Assets/icon.svg" /> + Style="{StaticResource CaptionTextBlockStyle}" /> - + \ No newline at end of file From de19be5a32bfbcba8265ba8c063d35fd91ddd10d Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Wed, 30 Apr 2025 20:42:59 +0200 Subject: [PATCH 8/8] Update SettingsWindow.xaml.cs --- .../cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs index ce63a2764a3f..770f3b536762 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Settings/SettingsWindow.xaml.cs @@ -71,7 +71,6 @@ private void Navigate(ProviderSettingsViewModel extension) private void PositionCentered() { - AppWindow.Resize(new SizeInt32 { Width = 1280, Height = 720 }); var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest); if (displayArea is not null) {