From de852409d1a2d3e2b06ce7a40bbea50920c3046d Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Tue, 25 Jun 2024 14:53:37 +0100 Subject: [PATCH 1/2] [PTRun]Disable titlebar accent workaround on Windows 10 --- .../PowerLauncher/ViewModel/MainViewModel.cs | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs index 06e80a2a010..a23cf56c096 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs @@ -1016,27 +1016,30 @@ public void ToggleWox() 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) + if (OSVersionHelper.IsWindows11()) { - return; - } + // 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); + 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))); + // 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 86ff236eee908dd7b2d595a8cbaf4957d2f583ed Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Tue, 25 Jun 2024 16:44:43 +0100 Subject: [PATCH 2/2] Add comment about Windows 11 --- src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs index a23cf56c096..c717d16bc2f 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs @@ -1036,7 +1036,7 @@ public void ToggleWox() uint titlebarPvAttribute = 0xFFFFFFFE; _ = Wox.Plugin.Common.Win32.NativeMethods.DwmSetWindowAttribute( windowSource.Handle, - (int)Wox.Plugin.Common.Win32.DwmWindowAttributes.CaptionColor, + (int)Wox.Plugin.Common.Win32.DwmWindowAttributes.CaptionColor, // CaptionColor attribute is only available on Windows 11. ref titlebarPvAttribute, Marshal.SizeOf(typeof(uint))); }