From 09f909d80941a0208d21f10eb082c98defd6e8fd Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Thu, 20 Jun 2024 15:26:14 +0100 Subject: [PATCH 1/5] Revert "[PTRun]Fix accent on title bar bleed into UI (#33046)" This reverts commit 8bb5a33572cdfeb03752c9ed88e98a192fc9572b. --- src/modules/launcher/PowerLauncher/MainWindow.xaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml b/src/modules/launcher/PowerLauncher/MainWindow.xaml index 9ae9a70cf317..384560c7c9b0 100644 --- a/src/modules/launcher/PowerLauncher/MainWindow.xaml +++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml @@ -45,11 +45,6 @@ Grid.Row="0" Padding="12,4,12,3"> - - - - - From 1262596fabe8ac415ac4fb020e08cc4b4ed8b0b2 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Thu, 20 Jun 2024 15:26:54 +0100 Subject: [PATCH 2/5] Revert "[PTRun]Use Mica backdrop to fix crashes with WPFUI (#32118)" This reverts commit b9da1e6abff4e4dd343f23ffbfa0acb46bacb2fd. --- src/modules/launcher/PowerLauncher/MainWindow.xaml | 4 ++-- src/modules/launcher/PowerLauncher/MainWindow.xaml.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml b/src/modules/launcher/PowerLauncher/MainWindow.xaml index 384560c7c9b0..764dee2bbacf 100644 --- a/src/modules/launcher/PowerLauncher/MainWindow.xaml +++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml @@ -32,9 +32,9 @@ - + diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs index 69c4d7108fd6..2fa2699953d8 100644 --- a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs +++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs @@ -63,7 +63,7 @@ public MainWindow(PowerToysRunSettings settings, MainViewModel mainVM, Cancellat if (OSVersionHelper.IsWindows11()) { - WindowBackdropType = Wpf.Ui.Controls.WindowBackdropType.Mica; + WindowBackdropType = Wpf.Ui.Controls.WindowBackdropType.Acrylic; } else { From b24ded4a89a045e6ec92a851e0e0d10d73aa714c Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Thu, 20 Jun 2024 16:23:47 +0100 Subject: [PATCH 3/5] Fix DWMAttributes in Wox Plugin Native Methods --- .../Wox.Plugin/Common/Win32/NativeMethods.cs | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs b/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs index 0c2c76e8f0b5..d213dd93a731 100644 --- a/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs +++ b/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs @@ -66,7 +66,7 @@ public static class NativeMethods public static extern int DwmpActivateLivePreview([MarshalAs(UnmanagedType.Bool)] bool fActivate, IntPtr hWndExclude, IntPtr hWndInsertBefore, LivePreviewTrigger lpt, IntPtr prcFinalRect); [DllImport("dwmapi.dll", PreserveSig = false)] - public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize); + public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref uint attrValue, int attrSize); [DllImport("dwmapi.dll", PreserveSig = false)] public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out int pvAttribute, int cbAttribute); @@ -493,29 +493,29 @@ public enum DwmNCRenderingPolicies public enum DwmWindowAttributes { NCRenderingEnabled = 1, - NCRenderingPolicy, - TransitionsForceDisabled, - AllowNCPaint, - CaptionButtonBounds, - NonClientRtlLayout, - ForceIconicRepresentation, - Flip3DPolicy, - ExtendedFrameBounds, - HasIconicBitmap, - DisallowPeek, - ExcludedFromPeek, - Cloak, - Cloaked, - FreezeRepresentation, - PassiveUpdateMode, - UseHostbackdropbrush, - UseImmersiveDarkMode, - WindowCornerPreference, - BorderColor, - CaptionColor, - TextColor, + NCRenderingPolicy = 2, + TransitionsForceDisabled = 3, + AllowNCPaint = 4, + CaptionButtonBounds = 5, + NonClientRtlLayout = 6, + ForceIconicRepresentation = 7, + Flip3DPolicy = 8, + ExtendedFrameBounds = 9, + HasIconicBitmap = 10, + DisallowPeek = 11, + ExcludedFromPeek = 12, + Cloak = 13, + Cloaked = 14, + FreezeRepresentation = 15, + PassiveUpdateMode = 16, + UseHostbackdropbrush = 17, + UseImmersiveDarkMode = 20, + WindowCornerPreference = 33, + BorderColor = 34, + CaptionColor = 35, + TextColor = 36, VisibleFrameBorderThickness, - Last, + Last = 37, } /// From 661be8d986f6f3b3db58a54e3b232becd2595051 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Thu, 20 Jun 2024 16:24:24 +0100 Subject: [PATCH 4/5] Fix titlebar accent showing --- .../Components/LivePreview.cs | 4 +-- .../PowerLauncher/ViewModel/MainViewModel.cs | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/LivePreview.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/LivePreview.cs index 4dd834f6af8e..4ae0d0c42f9a 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/LivePreview.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/LivePreview.cs @@ -19,13 +19,13 @@ internal class LivePreview /// handle to the window to exclude public static void SetWindowExclusionFromLivePreview(IntPtr hwnd) { - int renderPolicy = (int)DwmNCRenderingPolicies.Enabled; + uint renderPolicy = (uint)DwmNCRenderingPolicies.Enabled; _ = NativeMethods.DwmSetWindowAttribute( hwnd, 12, ref renderPolicy, - sizeof(int)); + sizeof(uint)); } /// diff --git a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs index 43e642dd0b7f..06e80a2a0106 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs @@ -8,11 +8,13 @@ using System.Globalization; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; +using System.Windows.Interop; using System.Windows.Threading; using Common.UI; using interop; @@ -1006,6 +1008,36 @@ public void ToggleWox() if (MainWindowVisibility != Visibility.Visible) { MainWindowVisibility = Visibility.Visible; + + // HACK: The following code in this if is a fix for https://github.com/microsoft/PowerToys/issues/30206 and https://github.com/microsoft/PowerToys/issues/33135 + // WPF UI theme watcher removes the composition target background color, among other weird stuff. + // https://github.com/lepoco/wpfui/blob/303f0aefcd59a142bc681415dc4360a34a15f33d/src/Wpf.Ui/Controls/Window/WindowBackdrop.cs#L280 + // So we set it back with https://github.com/lepoco/wpfui/blob/303f0aefcd59a142bc681415dc4360a34a15f33d/src/Wpf.Ui/Controls/Window/WindowBackdrop.cs#L191 + var window = Application.Current.MainWindow; + Wpf.Ui.Controls.WindowBackdrop.RemoveBackground(window); + + // Taken from WPFUI's fix for the title bar issue. We should be able to remove this fix when WPF UI 4 is integrated. + // https://github.com/lepoco/wpfui/pull/1122/files#diff-196b404f4db09632665ef546da6c8e57302b2f3e3d082eb4b5c295ae3482d94a + IntPtr windowHandle = new WindowInteropHelper(window).Handle; + if (windowHandle == IntPtr.Zero) + { + return; + } + + HwndSource windowSource = HwndSource.FromHwnd(windowHandle); + + // Remove background from client area + if (windowSource != null && windowSource.Handle != IntPtr.Zero && windowSource?.CompositionTarget != null) + { + // NOTE: https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute + // Specifying DWMWA_COLOR_DEFAULT (value 0xFFFFFFFF) for the color will reset the window back to using the system's default behavior for the caption color. + uint titlebarPvAttribute = 0xFFFFFFFE; + _ = Wox.Plugin.Common.Win32.NativeMethods.DwmSetWindowAttribute( + windowSource.Handle, + (int)Wox.Plugin.Common.Win32.DwmWindowAttributes.CaptionColor, + ref titlebarPvAttribute, + Marshal.SizeOf(typeof(uint))); + } } else { From 36e152d3d861dbc5d0ddfffe16f73347907c2e4b Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Thu, 20 Jun 2024 16:58:01 +0100 Subject: [PATCH 5/5] Fix number on wrong enum --- src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs b/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs index d213dd93a731..0028d9a1a261 100644 --- a/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs +++ b/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs @@ -514,8 +514,8 @@ public enum DwmWindowAttributes BorderColor = 34, CaptionColor = 35, TextColor = 36, - VisibleFrameBorderThickness, - Last = 37, + VisibleFrameBorderThickness = 37, + Last, } ///