[PTRun]Bring back acrylic and proper fix to title bar accent showing (#33458)

* Revert "[PTRun]Fix accent on title bar bleed into UI (#33046)"

This reverts commit 8bb5a33572.

* Revert "[PTRun]Use Mica backdrop to fix crashes with WPFUI (#32118)"

This reverts commit b9da1e6abf.

* Fix DWMAttributes in Wox Plugin Native Methods

* Fix titlebar accent showing

* Fix number on wrong enum
This commit is contained in:
Jaime Bernardo
2024-06-21 10:30:13 +01:00
committed by GitHub
parent 6043898ee5
commit 9509d7c1cc
5 changed files with 60 additions and 33 deletions

View File

@@ -8,11 +8,13 @@ using System.Collections.ObjectModel;
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 @@ namespace PowerLauncher.ViewModel
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
{