mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
[Launcher]Port from WPF-UI to .NET 9 WPF (#36215)
* Initial implementation * Fix fluent style * Fix no endline * Update expect.txt * Fix formatting * Fix light theme looking bad on Windows 10 * fix formatting * test change * Now really fixed W10 * Add a comment * Fix typos * Fix spellcheck errors * Fix spellcheck pattern for websites * Change patterns for spellcheck in the right file * Fix XAML styling * Fix contrast colors on W11 * Fix formatting * Removed emty line * Fix formatting * Added comment to fluentHC file * fix comment * Fix Windows10 again. Adress feedback. * W11 fix chaning from high contrast to normal not having correct background * W10 Fix high contrast not working after switching from light/dark moed * Address feedback * Fix formatting * Second W11 fix chaning from high contrast to normal not having correct background
This commit is contained in:
@@ -25,7 +25,6 @@ using PowerToys.Interop;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Interfaces;
|
||||
using Wpf.Ui.Appearance;
|
||||
|
||||
using CancellationToken = System.Threading.CancellationToken;
|
||||
using Image = Wox.Infrastructure.Image;
|
||||
@@ -50,6 +49,31 @@ namespace PowerLauncher
|
||||
private Point _mouseDownPosition;
|
||||
private ResultViewModel _mouseDownResultViewModel;
|
||||
|
||||
// The enum flag for DwmSetWindowAttribute's second parameter, which tells the function what attribute to set.
|
||||
public enum DWMWINDOWATTRIBUTE
|
||||
{
|
||||
DWMWA_WINDOW_CORNER_PREFERENCE = 33,
|
||||
}
|
||||
|
||||
// The DWM_WINDOW_CORNER_PREFERENCE enum for DwmSetWindowAttribute's third parameter, which tells the function
|
||||
// what value of the enum to set.
|
||||
// Copied from dwmapi.h
|
||||
public enum DWM_WINDOW_CORNER_PREFERENCE
|
||||
{
|
||||
DWMWCP_DEFAULT = 0,
|
||||
DWMWCP_DONOTROUND = 1,
|
||||
DWMWCP_ROUND = 2,
|
||||
DWMWCP_ROUNDSMALL = 3,
|
||||
}
|
||||
|
||||
// Import dwmapi.dll and define DwmSetWindowAttribute in C# corresponding to the native function.
|
||||
[DllImport("dwmapi.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
|
||||
internal static extern void DwmSetWindowAttribute(
|
||||
IntPtr hwnd,
|
||||
DWMWINDOWATTRIBUTE attribute,
|
||||
ref DWM_WINDOW_CORNER_PREFERENCE pvAttribute,
|
||||
uint cbAttribute);
|
||||
|
||||
public MainWindow(PowerToysRunSettings settings, MainViewModel mainVM, CancellationToken nativeWaiterCancelToken)
|
||||
: this()
|
||||
{
|
||||
@@ -63,17 +87,6 @@ namespace PowerLauncher
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
if (OSVersionHelper.IsWindows11())
|
||||
{
|
||||
WindowBackdropType = Wpf.Ui.Controls.WindowBackdropType.Acrylic;
|
||||
}
|
||||
else
|
||||
{
|
||||
WindowBackdropType = Wpf.Ui.Controls.WindowBackdropType.None;
|
||||
}
|
||||
|
||||
SystemThemeWatcher.Watch(this, WindowBackdropType);
|
||||
|
||||
_firstDeleteTimer.Elapsed += CheckForFirstDelete;
|
||||
_firstDeleteTimer.Interval = 1000;
|
||||
NativeEventWaiter.WaitForEventLoop(
|
||||
@@ -179,6 +192,14 @@ namespace PowerLauncher
|
||||
|
||||
// Call RegisterHotKey only after a window handle can be used, so that a global hotkey can be registered.
|
||||
_viewModel.RegisterHotkey(_hwndSource.Handle);
|
||||
if (OSVersionHelper.IsWindows11())
|
||||
{
|
||||
// ResizeMode="NoResize" removes rounded corners. So force them to rounded.
|
||||
IntPtr hWnd = new WindowInteropHelper(GetWindow(this)).EnsureHandle();
|
||||
DWMWINDOWATTRIBUTE attribute = DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE;
|
||||
DWM_WINDOW_CORNER_PREFERENCE preference = DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUND;
|
||||
DwmSetWindowAttribute(hWnd, attribute, ref preference, sizeof(uint));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
@@ -471,7 +492,7 @@ namespace PowerLauncher
|
||||
|
||||
private void OnLocationChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (_settings.RememberLastLaunchLocation)
|
||||
if (_settings != null && _settings.RememberLastLaunchLocation)
|
||||
{
|
||||
_settings.WindowLeft = Left;
|
||||
_settings.WindowTop = Top;
|
||||
|
||||
Reference in New Issue
Block a user