mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
[CmdPal] MinWidth/Height and DPI-aware launch dimensions (#38637)
* MinWidth/Height and DPI-aware launch dimensions * Making MainWindow DPI aware too * Moving toastwindow to WinUIEx too * Update MainWindow.xaml.cs * Reverting back to the working logic * Localizing settings window title * Xaml formatting * Update SettingsWindow.xaml.cs
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<Window
|
<winuiex:WindowEx
|
||||||
x:Class="Microsoft.CmdPal.UI.MainWindow"
|
x:Class="Microsoft.CmdPal.UI.MainWindow"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
@@ -6,8 +6,13 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:pages="using:Microsoft.CmdPal.UI.Pages"
|
xmlns:pages="using:Microsoft.CmdPal.UI.Pages"
|
||||||
xmlns:viewmodels="using:Microsoft.CmdPal.UI.ViewModels"
|
xmlns:viewmodels="using:Microsoft.CmdPal.UI.ViewModels"
|
||||||
|
xmlns:winuiex="using:WinUIEx"
|
||||||
|
Width="800"
|
||||||
|
Height="480"
|
||||||
|
MinWidth="320"
|
||||||
|
MinHeight="240"
|
||||||
Activated="MainWindow_Activated"
|
Activated="MainWindow_Activated"
|
||||||
Closed="MainWindow_Closed"
|
Closed="MainWindow_Closed"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<pages:ShellPage x:Name="RootShellPage" />
|
<pages:ShellPage x:Name="RootShellPage" />
|
||||||
</Window>
|
</winuiex:WindowEx>
|
||||||
|
|||||||
@@ -29,11 +29,12 @@ using Windows.Win32.UI.Input.KeyboardAndMouse;
|
|||||||
using Windows.Win32.UI.Shell;
|
using Windows.Win32.UI.Shell;
|
||||||
using Windows.Win32.UI.WindowsAndMessaging;
|
using Windows.Win32.UI.WindowsAndMessaging;
|
||||||
using WinRT;
|
using WinRT;
|
||||||
|
using WinUIEx;
|
||||||
using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance;
|
using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance;
|
||||||
|
|
||||||
namespace Microsoft.CmdPal.UI;
|
namespace Microsoft.CmdPal.UI;
|
||||||
|
|
||||||
public sealed partial class MainWindow : Window,
|
public sealed partial class MainWindow : WindowEx,
|
||||||
IRecipient<DismissMessage>,
|
IRecipient<DismissMessage>,
|
||||||
IRecipient<ShowWindowMessage>,
|
IRecipient<ShowWindowMessage>,
|
||||||
IRecipient<HideWindowMessage>,
|
IRecipient<HideWindowMessage>,
|
||||||
@@ -82,7 +83,6 @@ public sealed partial class MainWindow : Window,
|
|||||||
|
|
||||||
this.SetIcon();
|
this.SetIcon();
|
||||||
AppWindow.Title = RS_.GetString("AppName");
|
AppWindow.Title = RS_.GetString("AppName");
|
||||||
AppWindow.Resize(new SizeInt32 { Width = 1000, Height = 620 });
|
|
||||||
PositionCentered();
|
PositionCentered();
|
||||||
SetAcrylic();
|
SetAcrylic();
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
||||||
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
||||||
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" />
|
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" />
|
||||||
|
<PackageReference Include="WinUIEx" />
|
||||||
<PackageReference Include="Microsoft.Windows.CsWin32">
|
<PackageReference Include="Microsoft.Windows.CsWin32">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<Window
|
<winuiex:WindowEx
|
||||||
x:Class="Microsoft.CmdPal.UI.Settings.SettingsWindow"
|
x:Class="Microsoft.CmdPal.UI.Settings.SettingsWindow"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
@@ -7,13 +7,18 @@
|
|||||||
xmlns:local="using:Microsoft.CmdPal.UI.Settings"
|
xmlns:local="using:Microsoft.CmdPal.UI.Settings"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:ui="using:CommunityToolkit.WinUI"
|
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||||
|
xmlns:winuiex="using:WinUIEx"
|
||||||
Title="SettingsWindow"
|
Title="SettingsWindow"
|
||||||
|
Width="1280"
|
||||||
|
Height="720"
|
||||||
|
MinWidth="480"
|
||||||
|
MinHeight="480"
|
||||||
Activated="Window_Activated"
|
Activated="Window_Activated"
|
||||||
Closed="Window_Closed"
|
Closed="Window_Closed"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Window.SystemBackdrop>
|
<winuiex:WindowEx.SystemBackdrop>
|
||||||
<MicaBackdrop />
|
<MicaBackdrop />
|
||||||
</Window.SystemBackdrop>
|
</winuiex:WindowEx.SystemBackdrop>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
@@ -37,10 +42,10 @@
|
|||||||
Height="16"
|
Height="16"
|
||||||
Source="ms-appx:///Assets/icon.svg" />
|
Source="ms-appx:///Assets/icon.svg" />
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
x:Uid="CmdPalSettingsHeader"
|
||||||
Margin="12,0,0,0"
|
Margin="12,0,0,0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Style="{StaticResource CaptionTextBlockStyle}"
|
Style="{StaticResource CaptionTextBlockStyle}" />
|
||||||
Text="Command Palette Settings" />
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<NavigationView
|
<NavigationView
|
||||||
x:Name="NavView"
|
x:Name="NavView"
|
||||||
@@ -100,4 +105,4 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</NavigationView>
|
</NavigationView>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</winuiex:WindowEx>
|
||||||
|
|||||||
@@ -11,11 +11,12 @@ using Microsoft.UI.Windowing;
|
|||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Windows.Graphics;
|
using Windows.Graphics;
|
||||||
|
using WinUIEx;
|
||||||
using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance;
|
using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance;
|
||||||
|
|
||||||
namespace Microsoft.CmdPal.UI.Settings;
|
namespace Microsoft.CmdPal.UI.Settings;
|
||||||
|
|
||||||
public sealed partial class SettingsWindow : Window,
|
public sealed partial class SettingsWindow : WindowEx,
|
||||||
IRecipient<NavigateToExtensionSettingsMessage>,
|
IRecipient<NavigateToExtensionSettingsMessage>,
|
||||||
IRecipient<QuitMessage>
|
IRecipient<QuitMessage>
|
||||||
{
|
{
|
||||||
@@ -70,7 +71,6 @@ public sealed partial class SettingsWindow : Window,
|
|||||||
|
|
||||||
private void PositionCentered()
|
private void PositionCentered()
|
||||||
{
|
{
|
||||||
AppWindow.Resize(new SizeInt32 { Width = 1280, Height = 720 });
|
|
||||||
var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest);
|
var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest);
|
||||||
if (displayArea is not null)
|
if (displayArea is not null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<Window
|
<winuiex:WindowEx
|
||||||
x:Class="Microsoft.CmdPal.UI.ToastWindow"
|
x:Class="Microsoft.CmdPal.UI.ToastWindow"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
@@ -7,17 +7,18 @@
|
|||||||
xmlns:local="using:Microsoft.CmdPal.UI"
|
xmlns:local="using:Microsoft.CmdPal.UI"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:ui="using:CommunityToolkit.WinUI"
|
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||||
|
xmlns:winuiex="using:WinUIEx"
|
||||||
Title="Command Palette Toast"
|
Title="Command Palette Toast"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Window.SystemBackdrop>
|
<winuiex:WindowEx.SystemBackdrop>
|
||||||
<DesktopAcrylicBackdrop />
|
<DesktopAcrylicBackdrop />
|
||||||
</Window.SystemBackdrop>
|
</winuiex:WindowEx.SystemBackdrop>
|
||||||
<Grid x:Name="ToastGrid">
|
<Grid x:Name="ToastGrid">
|
||||||
<!-- This padding is used to calculate the dimensions of the ToastWindow -->
|
<!-- This padding is used to calculate the dimensions of the ToastWindow -->
|
||||||
<TextBlock
|
<TextBlock
|
||||||
x:Name="ToastText"
|
x:Name="ToastText"
|
||||||
Padding="16,16,36,24"
|
Padding="12,12,24,20"
|
||||||
Text="{x:Bind ViewModel.ToastMessage, Mode=OneWay}"
|
Text="{x:Bind ViewModel.ToastMessage, Mode=OneWay}"
|
||||||
TextAlignment="Center" />
|
TextAlignment="Center" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</winuiex:WindowEx>
|
||||||
@@ -17,11 +17,12 @@ using Windows.Win32.Foundation;
|
|||||||
using Windows.Win32.Graphics.Gdi;
|
using Windows.Win32.Graphics.Gdi;
|
||||||
using Windows.Win32.UI.HiDpi;
|
using Windows.Win32.UI.HiDpi;
|
||||||
using Windows.Win32.UI.WindowsAndMessaging;
|
using Windows.Win32.UI.WindowsAndMessaging;
|
||||||
|
using WinUIEx;
|
||||||
using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance;
|
using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance;
|
||||||
|
|
||||||
namespace Microsoft.CmdPal.UI;
|
namespace Microsoft.CmdPal.UI;
|
||||||
|
|
||||||
public sealed partial class ToastWindow : Window,
|
public sealed partial class ToastWindow : WindowEx,
|
||||||
IRecipient<QuitMessage>
|
IRecipient<QuitMessage>
|
||||||
{
|
{
|
||||||
private readonly HWND _hwnd;
|
private readonly HWND _hwnd;
|
||||||
@@ -64,19 +65,7 @@ public sealed partial class ToastWindow : Window,
|
|||||||
|
|
||||||
private void PositionCentered()
|
private void PositionCentered()
|
||||||
{
|
{
|
||||||
var intSize = new SizeInt32
|
this.SetWindowSize(ToastText.ActualWidth, ToastText.ActualHeight);
|
||||||
{
|
|
||||||
Width = Convert.ToInt32(ToastText.ActualWidth),
|
|
||||||
Height = Convert.ToInt32(ToastText.ActualHeight),
|
|
||||||
};
|
|
||||||
|
|
||||||
var scaleAdjustment = GetScaleFactor(_hwnd);
|
|
||||||
var scaled = new SizeInt32
|
|
||||||
{
|
|
||||||
Width = (int)Math.Round(intSize.Width * scaleAdjustment),
|
|
||||||
Height = (int)Math.Round(intSize.Height * scaleAdjustment),
|
|
||||||
};
|
|
||||||
AppWindow.Resize(scaled);
|
|
||||||
|
|
||||||
var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest);
|
var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest);
|
||||||
if (displayArea is not null)
|
if (displayArea is not null)
|
||||||
@@ -86,7 +75,7 @@ public sealed partial class ToastWindow : Window,
|
|||||||
|
|
||||||
var monitorHeight = displayArea.WorkArea.Height;
|
var monitorHeight = displayArea.WorkArea.Height;
|
||||||
var windowHeight = AppWindow.Size.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);
|
AppWindow.Move(centeredPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user