Browse Source

fix acrylic backdrop on win11

pull/7775/head
Trym Lund Flogard 4 years ago
parent
commit
64ae7efe20
  1. 11
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
  2. 15
      src/Windows/Avalonia.Win32/WindowImpl.cs

11
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@ -765,6 +765,14 @@ namespace Avalonia.Win32.Interop
DWMWA_CLOAK,
DWMWA_CLOAKED,
DWMWA_FREEZE_REPRESENTATION,
DWMWA_PASSIVE_UPDATE_MODE,
DWMWA_USE_HOSTBACKDROPBRUSH,
DWMWA_USE_IMMERSIVE_DARK_MODE = 20,
DWMWA_WINDOW_CORNER_PREFERENCE = 33,
DWMWA_BORDER_COLOR,
DWMWA_CAPTION_COLOR,
DWMWA_TEXT_COLOR,
DWMWA_VISIBLE_FRAME_BORDER_THICKNESS,
DWMWA_LAST
};
@ -1456,6 +1464,9 @@ namespace Avalonia.Win32.Interop
[DllImport("dwmapi.dll")]
public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out RECT pvAttribute, int cbAttribute);
[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int dwAttribute, void* pvAttribute, int cbAttribute);
[DllImport("dwmapi.dll")]
public static extern int DwmIsCompositionEnabled(out bool enabled);

15
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -379,13 +379,24 @@ namespace Avalonia.Win32
{
if (_isUsingComposition)
{
_blurHost?.SetBlur(transparencyLevel switch
var effect = transparencyLevel switch
{
WindowTransparencyLevel.Mica => BlurEffect.Mica,
WindowTransparencyLevel.AcrylicBlur => BlurEffect.Acrylic,
WindowTransparencyLevel.Blur => BlurEffect.Acrylic,
_ => BlurEffect.None
});
};
if (Win32Platform.WindowsVersion >= WinUICompositorConnection.MinHostBackdropVersion)
{
unsafe
{
int pvUseBackdropBrush = effect == BlurEffect.Acrylic ? 1 : 0;
DwmSetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_USE_HOSTBACKDROPBRUSH, &pvUseBackdropBrush, sizeof(int));
}
}
_blurHost?.SetBlur(effect);
return transparencyLevel;
}

Loading…
Cancel
Save