Skip to content

Commit 8b8c75b

Browse files
[PTRun]Disable titlebar accent workaround on Windows 10 (#33505)
After #33458 , that fix crashes on Windows 10, where the caption color attribute is not supported. This PR disables the fix on Windows 10, since it's not even needed there actually.
1 parent 5c257fb commit 8b8c75b

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs

+21-18
Original file line numberDiff line numberDiff line change
@@ -1016,27 +1016,30 @@ public void ToggleWox()
10161016
var window = Application.Current.MainWindow;
10171017
Wpf.Ui.Controls.WindowBackdrop.RemoveBackground(window);
10181018

1019-
// Taken from WPFUI's fix for the title bar issue. We should be able to remove this fix when WPF UI 4 is integrated.
1020-
// https://github.com/lepoco/wpfui/pull/1122/files#diff-196b404f4db09632665ef546da6c8e57302b2f3e3d082eb4b5c295ae3482d94a
1021-
IntPtr windowHandle = new WindowInteropHelper(window).Handle;
1022-
if (windowHandle == IntPtr.Zero)
1019+
if (OSVersionHelper.IsWindows11())
10231020
{
1024-
return;
1025-
}
1021+
// Taken from WPFUI's fix for the title bar issue. We should be able to remove this fix when WPF UI 4 is integrated.
1022+
// https://github.com/lepoco/wpfui/pull/1122/files#diff-196b404f4db09632665ef546da6c8e57302b2f3e3d082eb4b5c295ae3482d94a
1023+
IntPtr windowHandle = new WindowInteropHelper(window).Handle;
1024+
if (windowHandle == IntPtr.Zero)
1025+
{
1026+
return;
1027+
}
10261028

1027-
HwndSource windowSource = HwndSource.FromHwnd(windowHandle);
1029+
HwndSource windowSource = HwndSource.FromHwnd(windowHandle);
10281030

1029-
// Remove background from client area
1030-
if (windowSource != null && windowSource.Handle != IntPtr.Zero && windowSource?.CompositionTarget != null)
1031-
{
1032-
// NOTE: https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
1033-
// 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.
1034-
uint titlebarPvAttribute = 0xFFFFFFFE;
1035-
_ = Wox.Plugin.Common.Win32.NativeMethods.DwmSetWindowAttribute(
1036-
windowSource.Handle,
1037-
(int)Wox.Plugin.Common.Win32.DwmWindowAttributes.CaptionColor,
1038-
ref titlebarPvAttribute,
1039-
Marshal.SizeOf(typeof(uint)));
1031+
// Remove background from client area
1032+
if (windowSource != null && windowSource.Handle != IntPtr.Zero && windowSource?.CompositionTarget != null)
1033+
{
1034+
// NOTE: https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
1035+
// 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.
1036+
uint titlebarPvAttribute = 0xFFFFFFFE;
1037+
_ = Wox.Plugin.Common.Win32.NativeMethods.DwmSetWindowAttribute(
1038+
windowSource.Handle,
1039+
(int)Wox.Plugin.Common.Win32.DwmWindowAttributes.CaptionColor, // CaptionColor attribute is only available on Windows 11.
1040+
ref titlebarPvAttribute,
1041+
Marshal.SizeOf(typeof(uint)));
1042+
}
10401043
}
10411044
}
10421045
else

0 commit comments

Comments
 (0)